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_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
@ -203,8 +215,19 @@ public final class DiscoSheep extends JavaPlugin {
if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) { if (sender.hasPermission(PERMISSION_CHANGEDEFAULTS)) {
party.setDefaultsFromCurrent(); party.setDefaultsFromCurrent();
return true; return true;
} else {
return noPermsMessage(sender, PERMISSION_CHANGEDEFAULTS);
} }
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) { boolean noPermsMessage(CommandSender sender, String permission) {

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