commit bd2c7bc4c3b81b7182a2d8ae43701bb80b274f66 Author: flifloo Date: Sat Aug 24 01:02:56 2019 +0200 Initial commit diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..bfb1a30 --- /dev/null +++ b/src/config.yml @@ -0,0 +1 @@ +language: en \ No newline at end of file diff --git a/src/fr/flifloo/StaffToggle/Commands/Help.java b/src/fr/flifloo/StaffToggle/Commands/Help.java new file mode 100644 index 0000000..0c61dc4 --- /dev/null +++ b/src/fr/flifloo/StaffToggle/Commands/Help.java @@ -0,0 +1,22 @@ +package fr.flifloo.StaffToggle.Commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import fr.flifloo.StaffToggle.Main; + +public class Help implements CommandExecutor { + Main plugin; + + public Help(Main plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender player, Command cmd, String label, String[] args) { + player.sendMessage(ChatColor.AQUA + "StaffToogle help !"); + return true; + } +} diff --git a/src/fr/flifloo/StaffToggle/Commands/Staff.java b/src/fr/flifloo/StaffToggle/Commands/Staff.java new file mode 100644 index 0000000..08b6332 --- /dev/null +++ b/src/fr/flifloo/StaffToggle/Commands/Staff.java @@ -0,0 +1,37 @@ +package fr.flifloo.StaffToggle.Commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import fr.flifloo.StaffToggle.Main; + +public class Staff implements CommandExecutor { + Main plugin; + + public Staff(Main plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender player, Command cmd, String label, String[] args) { + if (!(player instanceof Player)) { + player.sendMessage(ChatColor.RED + "Command only for players !"); + return false; + } + + if (args.length == 0 || args[0].equalsIgnoreCase("help")) { + String message = plugin.language.config.getString("staff.help"); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + } + else if (args[0].equalsIgnoreCase("modo")) { + player.sendMessage(ChatColor.GOLD + "Switch modo !"); + } + else if (args[0].equalsIgnoreCase("admin")) { + player.sendMessage(ChatColor.GOLD + "Switch admin !"); + } + return true; + } +} diff --git a/src/fr/flifloo/StaffToggle/Configuration/Language.java b/src/fr/flifloo/StaffToggle/Configuration/Language.java new file mode 100644 index 0000000..b8d9f52 --- /dev/null +++ b/src/fr/flifloo/StaffToggle/Configuration/Language.java @@ -0,0 +1,42 @@ +package fr.flifloo.StaffToggle.Configuration; + +import fr.flifloo.StaffToggle.Main; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +public class Language{ + public FileConfiguration config; + + public Language (Main main) { + String configLanguage = main.getConfig().getString("language"); + InputStream resourceLanguage = main.getResource("languages/" + configLanguage + ".yml"); + File configFile = new File(main.getDataFolder(), "language.yml"); + + if (!configFile.exists()) { + configFile.getParentFile().mkdirs(); + try { + Files.copy(resourceLanguage, configFile.toPath()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + config = new YamlConfiguration(); + try { + config.load(configFile); + if (!configLanguage.equalsIgnoreCase(config.getString("language"))) { + Files.copy(resourceLanguage, configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + config.load(configFile); + } + } catch (IOException | InvalidConfigurationException e) { + e.printStackTrace(); + } + } +} diff --git a/src/fr/flifloo/StaffToggle/Main.java b/src/fr/flifloo/StaffToggle/Main.java new file mode 100644 index 0000000..9d02dac --- /dev/null +++ b/src/fr/flifloo/StaffToggle/Main.java @@ -0,0 +1,29 @@ +package fr.flifloo.StaffToggle; + +import fr.flifloo.StaffToggle.Commands.*; +import fr.flifloo.StaffToggle.Configuration.*; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.IOException; + +public class Main extends JavaPlugin { + public Language language; + + @Override + public void onEnable() { + saveDefaultConfig(); + getConfig().getString("language"); + language = new Language(this); + registerCommands(); + } + + @Override + public void onDisable() { + + } + + public void registerCommands() { + getCommand("staff").setExecutor(new Staff(this)); + } +} diff --git a/src/languages/en.yml b/src/languages/en.yml new file mode 100644 index 0000000..7446d7b --- /dev/null +++ b/src/languages/en.yml @@ -0,0 +1,6 @@ +language: en +staff: + help: "&3=========={Staff help}==========\n +&e/staff modo&9: Toggle moderation\n +&e/staff admin&9: Toggle administration\n +&3==============================" \ No newline at end of file diff --git a/src/languages/fr.yml b/src/languages/fr.yml new file mode 100644 index 0000000..d232289 --- /dev/null +++ b/src/languages/fr.yml @@ -0,0 +1,6 @@ +language: fr +staff: + help: "&3=========={Staff help}==========\n +&e/staff modo&9: Active la moderation\n +&e/staff admin&9: Active l'administration\n +&3==============================" \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..2844f65 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,22 @@ +main: fr.flifloo.StaffToggle.Main +name: StaffToggle +version: 1.0.0 +description: Toggle staff mod +api-version: "1.14" +author: flifloo +depend: + - LuckPerms + +commands: + staff: + permission: staff.help + permission-message: You don't have the permission to use this command ! + aliases: staff help + +permissions: + staff.help: + description: Show help + staff.modo: + description: Toogle modo + staff.admin: + description: Toogle admin \ No newline at end of file