diff --git a/src/fr/flifloo/StaffToggle/Commands/Staff.java b/src/fr/flifloo/StaffToggle/Commands/Staff.java index dbaa116..9ecc70a 100644 --- a/src/fr/flifloo/StaffToggle/Commands/Staff.java +++ b/src/fr/flifloo/StaffToggle/Commands/Staff.java @@ -8,6 +8,10 @@ import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import fr.flifloo.StaffToggle.Main; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import java.util.List; public class Staff implements CommandExecutor { private Main plugin; @@ -27,26 +31,32 @@ public class Staff implements CommandExecutor { sender.sendMessage(ChatColor.RED + "Command only for players !"); return false; } + Player player = (Player) sender; + PlayerInventory playerIvt = player.getInventory(); + String playerConf = "players." + player.getUniqueId(); + String state = playerConf + ".state"; + String armor = playerConf + ".inventory" + ".armor"; + String content = playerConf + ".inventory" + "content"; - if (args.length == 0 || args[0].equalsIgnoreCase("help")) { - message = language.getString("staff.help"); - sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); + if (!staffConf.isSet(state)) { + plugin.staffConf.set(state, false); } - else if (args[0].equalsIgnoreCase("modo") || args[0].equalsIgnoreCase("admin")) { - Player player = (Player) sender; - if (!staffConf.isSet("players." + player.getUniqueId())) { - player.sendMessage("Not config yet !"); - staffConf.set("players." + player.getUniqueId(), "test"); - plugin.staffConf.save(); - } else { - player.sendMessage("Fond config !"); - } - } - else { - message = language.getString("unknown"); - sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message)); - return false; + if (!staffConf.getBoolean(state)){ + plugin.staffConf.set(state, true); + plugin.staffConf.set(armor, playerIvt.getArmorContents()); + plugin.staffConf.set(content, playerIvt.getContents()); + playerIvt.clear(); + player.sendMessage("On"); + } else { + plugin.staffConf.set(state, false); + playerIvt.clear(); + ItemStack[] backupIvt = (ItemStack[]) staffConf.get(armor); + playerIvt.setArmorContents(backupIvt); + backupIvt = (ItemStack[]) staffConf.get(content); + playerIvt.setContents(backupIvt); + player.sendMessage("Off"); } + return true; } } diff --git a/src/fr/flifloo/StaffToggle/Configurations/Configuration.java b/src/fr/flifloo/StaffToggle/Configurations/Configuration.java index 7dc5d22..fdf26ba 100644 --- a/src/fr/flifloo/StaffToggle/Configurations/Configuration.java +++ b/src/fr/flifloo/StaffToggle/Configurations/Configuration.java @@ -48,4 +48,9 @@ public class Configuration{ this.plugin.getLogger().warning("Unable to save " + this.fileName); // shouldn't really happen, but save throws the exception } } + + public void set(String path, Object value) { + this.config.set(path, value); + this.save(); + } }