Remake set method for auto save in configurations, simplify staff command and add save and restore of inventory
This commit is contained in:
parent
0647d1d717
commit
fb217cf7fe
2 changed files with 32 additions and 17 deletions
|
@ -8,6 +8,10 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import fr.flifloo.StaffToggle.Main;
|
import fr.flifloo.StaffToggle.Main;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Staff implements CommandExecutor {
|
public class Staff implements CommandExecutor {
|
||||||
private Main plugin;
|
private Main plugin;
|
||||||
|
@ -27,26 +31,32 @@ public class Staff implements CommandExecutor {
|
||||||
sender.sendMessage(ChatColor.RED + "Command only for players !");
|
sender.sendMessage(ChatColor.RED + "Command only for players !");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
|
||||||
message = language.getString("staff.help");
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("modo") || args[0].equalsIgnoreCase("admin")) {
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if (!staffConf.isSet("players." + player.getUniqueId())) {
|
PlayerInventory playerIvt = player.getInventory();
|
||||||
player.sendMessage("Not config yet !");
|
String playerConf = "players." + player.getUniqueId();
|
||||||
staffConf.set("players." + player.getUniqueId(), "test");
|
String state = playerConf + ".state";
|
||||||
plugin.staffConf.save();
|
String armor = playerConf + ".inventory" + ".armor";
|
||||||
|
String content = playerConf + ".inventory" + "content";
|
||||||
|
|
||||||
|
if (!staffConf.isSet(state)) {
|
||||||
|
plugin.staffConf.set(state, 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 {
|
} else {
|
||||||
player.sendMessage("Fond config !");
|
plugin.staffConf.set(state, false);
|
||||||
}
|
playerIvt.clear();
|
||||||
}
|
ItemStack[] backupIvt = (ItemStack[]) staffConf.get(armor);
|
||||||
else {
|
playerIvt.setArmorContents(backupIvt);
|
||||||
message = language.getString("unknown");
|
backupIvt = (ItemStack[]) staffConf.get(content);
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
playerIvt.setContents(backupIvt);
|
||||||
return false;
|
player.sendMessage("Off");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue