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

@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public final class DiscoSheep extends JavaPlugin { public final class DiscoSheep extends JavaPlugin {
static final String PERMISSION_PARTY = "discosheep.party"; static final String PERMISSION_PARTY = "discosheep.party";
static final String PERMISSION_ALL = "discosheep.partyall"; static final String PERMISSION_ALL = "discosheep.partyall";
static final String PERMISSION_FIREWORKS = "discosheep.fireworks"; static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
@ -21,7 +21,7 @@ public final class DiscoSheep extends JavaPlugin {
static final String PERMISSION_OTHER = "discosheep.other"; static final String PERMISSION_OTHER = "discosheep.other";
static final String PERMISSION_CHANGEPERIOD = "discosheep.changeperiod"; static final String PERMISSION_CHANGEPERIOD = "discosheep.changeperiod";
static final String PERMISSION_CHANGEDEFAULTS = "discosheep.changedefaults"; static final String PERMISSION_CHANGEDEFAULTS = "discosheep.changedefaults";
static final String PERMISSION_SAVECONFIG = "discosheep.saveconfig";
Map<String, DiscoParty> parties = new HashMap<String, DiscoParty>(); Map<String, DiscoParty> parties = new HashMap<String, DiscoParty>();
private BaaBaaBlockSheepEvents blockEvents = new BaaBaaBlockSheepEvents(this); private BaaBaaBlockSheepEvents blockEvents = new BaaBaaBlockSheepEvents(this);
FileConfiguration config; FileConfiguration config;
@ -68,6 +68,18 @@ public final class DiscoSheep extends JavaPlugin {
loadConfigFromDisk(); 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 @Override
public void onDisable() { public void onDisable() {
this.stopAllParties(); // or else the parties will continue FOREVER this.stopAllParties(); // or else the parties will continue FOREVER
@ -121,17 +133,17 @@ public final class DiscoSheep extends JavaPlugin {
} }
/*-- Actual commands begin here --*/ /*-- 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"); 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; return true;
} }
boolean stopMeCommand(CommandSender sender) { boolean stopMeCommand(CommandSender sender) {
stopParty(sender.getName()); stopParty(sender.getName());
return true; return true;
} }
boolean stopAllCommand(CommandSender sender) { boolean stopAllCommand(CommandSender sender) {
if (sender.hasPermission(PERMISSION_STOPALL)) { if (sender.hasPermission(PERMISSION_STOPALL)) {
stopAllParties(); stopAllParties();
return true; 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 (player.hasPermission(PERMISSION_PARTY)) {
if (!hasParty(player.getName())) { if (!hasParty(player.getName())) {
party.setPlayer(player); 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)) { if (sender.hasPermission(PERMISSION_RELOAD)) {
reloadConfigFromDisk(); reloadConfigFromDisk();
sender.sendMessage(ChatColor.GREEN + "DiscoSheep config reloaded from disk"); 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)) { if (sender.hasPermission(PERMISSION_OTHER)) {
Player p; Player p;
for (String playerName : players) { 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)) { if (sender.hasPermission(PERMISSION_ALL)) {
for (Player p : Bukkit.getServer().getOnlinePlayers()) { for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!hasParty(p.getName())) { if (!hasParty(p.getName())) {
@ -198,16 +210,27 @@ public final class DiscoSheep extends JavaPlugin {
return noPermsMessage(sender, PERMISSION_ALL); return noPermsMessage(sender, PERMISSION_ALL);
} }
} }
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 setDefaultsCommand(CommandSender sender, DiscoParty party) {
if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) {
party.setDefaultsFromCurrent();
return true;
} else {
return noPermsMessage(sender, PERMISSION_CHANGEDEFAULTS);
}
}
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); sender.sendMessage(ChatColor.RED + "You do not have the permission node " + ChatColor.GRAY + permission);
return false; return false;
} }

View File

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

View File

@ -23,6 +23,14 @@ permissions:
discosheep.other: true discosheep.other: true
discosheep.changeperiod: true discosheep.changeperiod: true
discosheep.changedefaults: 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: discosheep.party:
description: Allows a player to have a party of one description: Allows a player to have a party of one
default: op default: op
@ -49,4 +57,6 @@ permissions:
discosheep.changedefaults: discosheep.changedefaults:
description: Allows a player to change the default settings description: Allows a player to change the default settings
default: op default: op
discosheep.saveconfig:
description: Allows a player to save the config with current values set in memory
default: op