implemented /ds saveconfig

This commit is contained in:
Gibstick 2013-07-22 09:43:08 -04:00
parent 4e4ebc58f8
commit e15eb397da
3 changed files with 55 additions and 21 deletions

View File

@ -21,7 +21,7 @@ public final class DiscoSheep extends JavaPlugin {
static final String PERMISSION_OTHER = "discosheep.other";
static final String PERMISSION_CHANGEPERIOD = "discosheep.changeperiod";
static final String PERMISSION_CHANGEDEFAULTS = "discosheep.changedefaults";
static final String PERMISSION_SAVECONFIG = "discosheep.saveconfig";
Map<String, DiscoParty> parties = new HashMap<String, DiscoParty>();
private BaaBaaBlockSheepEvents blockEvents = new BaaBaaBlockSheepEvents(this);
FileConfiguration config;
@ -68,6 +68,18 @@ public final class DiscoSheep extends JavaPlugin {
loadConfigFromDisk();
}
void saveConfigToDisk() {
if (config == null) {
config = getConfig();
}
config.set("default.sheep", DiscoParty.defaultSheep);
config.set("default.radius", DiscoParty.defaultRadius);
config.set("default.duration", toSeconds_i(DiscoParty.defaultDuration));
config.set("default.period-ticks", DiscoParty.defaultPeriod);
saveConfig();
}
@Override
public void onDisable() {
this.stopAllParties(); // or else the parties will continue FOREVER
@ -121,17 +133,17 @@ public final class DiscoSheep extends JavaPlugin {
}
/*-- Actual commands begin here --*/
boolean helpCommand(CommandSender sender) {
boolean helpCommand(CommandSender sender) {
sender.sendMessage(ChatColor.YELLOW + "DiscoSheep Help\n" + ChatColor.GRAY + " Subcommands\n" + ChatColor.WHITE + "me, stop, all, stopall\n" + "You do not need permission to use the \"stop\" command\n" + "other <players>: start a party for the space-delimited list of players\n" + ChatColor.GRAY + " Arguments\n" + ChatColor.WHITE + "-n <integer>: set the number of sheep per player that spawn\n" + "-t <integer>: set the party duration in seconds\n" + "-p <ticks>: set the number of ticks between each disco beat\n" + "-r <integer>: set radius of the area in which sheep can spawn\n" + "-fw: enables fireworks");
return true;
}
boolean stopMeCommand(CommandSender sender) {
boolean stopMeCommand(CommandSender sender) {
stopParty(sender.getName());
return true;
}
boolean stopAllCommand(CommandSender sender) {
boolean stopAllCommand(CommandSender sender) {
if (sender.hasPermission(PERMISSION_STOPALL)) {
stopAllParties();
return true;
@ -140,7 +152,7 @@ public final class DiscoSheep extends JavaPlugin {
}
}
boolean partyCommand(Player player, DiscoParty party) {
boolean partyCommand(Player player, DiscoParty party) {
if (player.hasPermission(PERMISSION_PARTY)) {
if (!hasParty(player.getName())) {
party.setPlayer(player);
@ -154,7 +166,7 @@ public final class DiscoSheep extends JavaPlugin {
}
}
boolean reloadCommand(CommandSender sender) {
boolean reloadCommand(CommandSender sender) {
if (sender.hasPermission(PERMISSION_RELOAD)) {
reloadConfigFromDisk();
sender.sendMessage(ChatColor.GREEN + "DiscoSheep config reloaded from disk");
@ -164,7 +176,7 @@ public final class DiscoSheep extends JavaPlugin {
}
}
boolean partyOtherCommand(String[] players, CommandSender sender, DiscoParty party) {
boolean partyOtherCommand(String[] players, CommandSender sender, DiscoParty party) {
if (sender.hasPermission(PERMISSION_OTHER)) {
Player p;
for (String playerName : players) {
@ -184,7 +196,7 @@ public final class DiscoSheep extends JavaPlugin {
}
}
boolean partyAllCommand(CommandSender sender, DiscoParty party) {
boolean partyAllCommand(CommandSender sender, DiscoParty party) {
if (sender.hasPermission(PERMISSION_ALL)) {
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!hasParty(p.getName())) {
@ -199,15 +211,26 @@ public final class DiscoSheep extends JavaPlugin {
}
}
boolean setDefaultsCommand(CommandSender sender, DiscoParty party) {
if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) {
party.setDefaultsFromCurrent();
return true;
}
else return noPermsMessage(sender, PERMISSION_CHANGEDEFAULTS);
}
boolean setDefaultsCommand(CommandSender sender, DiscoParty party) {
if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) {
party.setDefaultsFromCurrent();
return true;
} else {
return noPermsMessage(sender, PERMISSION_CHANGEDEFAULTS);
}
}
boolean noPermsMessage(CommandSender sender, String permission) {
boolean saveConfigCommand(CommandSender sender) {
if (sender.hasPermission(PERMISSION_SAVECONFIG)) {
saveConfigToDisk();
return true;
} else {
return noPermsMessage(sender, PERMISSION_SAVECONFIG);
}
}
boolean noPermsMessage(CommandSender sender, String permission) {
sender.sendMessage(ChatColor.RED + "You do not have the permission node " + ChatColor.GRAY + permission);
return false;
}

View File

@ -78,6 +78,8 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
return parent.helpCommand(sender);
} else if (args[0].equalsIgnoreCase("reload")) {
return parent.reloadCommand(sender);
} else if (args[0].equalsIgnoreCase("save") || args[0].equalsIgnoreCase("saveconfig")) {
return parent.saveConfigCommand(sender);
}
}
@ -150,8 +152,7 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
return parent.partyOtherCommand(parsePlayerList(args, 1), sender, mainParty);
} else if (args[0].equalsIgnoreCase("defaults")) {
return parent.setDefaultsCommand(sender, mainParty);
}
else {
} else {
sender.sendMessage(ChatColor.RED + "Invalid argument (certain commands do not work from console).");
return false;
}

View File

@ -23,6 +23,14 @@ permissions:
discosheep.other: true
discosheep.changeperiod: true
discosheep.changedefaults: true
discosheep.admin:
description: Suggested permissions for administrators
default: op
children:
discosheep.stopall: true
discosheep.reload: true
discosheep.changedefaults: true
discosheep.saveconfig: true
discosheep.party:
description: Allows a player to have a party of one
default: op
@ -49,4 +57,6 @@ permissions:
discosheep.changedefaults:
description: Allows a player to change the default settings
default: op
discosheep.saveconfig:
description: Allows a player to save the config with current values set in memory
default: op