diff --git a/dist/DiscoSheep.jar b/dist/DiscoSheep.jar index 917010e..158e26c 100644 Binary files a/dist/DiscoSheep.jar and b/dist/DiscoSheep.jar differ diff --git a/src/gibstick/bukkit/discosheep/DiscoSheep.java b/src/gibstick/bukkit/discosheep/DiscoSheep.java index af0ec70..3f79d5a 100644 --- a/src/gibstick/bukkit/discosheep/DiscoSheep.java +++ b/src/gibstick/bukkit/discosheep/DiscoSheep.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.bukkit.configuration.MemoryConfiguration; +import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -13,13 +13,16 @@ public final class DiscoSheep extends JavaPlugin { Map parties = new HashMap(); private BaaBaaBlockSheepEvents blockEvents = new BaaBaaBlockSheepEvents(this); + FileConfiguration config; @Override public void onEnable() { getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this)); getServer().getPluginManager().registerEvents(blockEvents, this); - FileConfiguration config = this.getConfig(); + if (config == null) { + config = this.getConfig(); + } config.addDefault("max.sheep", DiscoParty.maxSheep); config.addDefault("max.radius", DiscoParty.maxRadius); @@ -30,8 +33,12 @@ public final class DiscoSheep extends JavaPlugin { config.addDefault("default.radius", DiscoParty.defaultRadius); config.addDefault("default.duration", toSeconds_i(DiscoParty.defaultDuration)); config.addDefault("default.period-ticks", DiscoParty.defaultPeriod); - config.options().copyDefaults(true); + loadConfigFromDisk(); + } + + void loadConfigFromDisk() { + getConfig().options().copyDefaults(true); saveConfig(); DiscoParty.maxSheep = getConfig().getInt("max.sheep"); @@ -44,10 +51,16 @@ public final class DiscoSheep extends JavaPlugin { DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration")); DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks"); } + + void reloadConfigFromDisk() { + reloadConfig(); + loadConfigFromDisk(); + } @Override public void onDisable() { this.stopAllParties(); + this.config = null; } int toTicks(double seconds) { diff --git a/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java b/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java index 899a784..d63622c 100644 --- a/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java +++ b/src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java @@ -19,10 +19,10 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { private static final String PERMISSION_ALL = "discosheep.partyall"; private static final String PERMISSION_FIREWORKS = "discosheep.fireworks"; private static final String PERMISSION_STOP = "discosheep.stop"; - private static final String PERMISSION_SUPER = "disosheep.*"; + private static final String PERMISSION_RELOAD = "discosheep.reload"; private boolean senderHasPerm(CommandSender sender, String permission) { - return sender.hasPermission(permission) || sender.hasPermission(PERMISSION_SUPER); + return sender.hasPermission(permission); } private void noPermsMessage(CommandSender sender, String permission) { @@ -65,11 +65,6 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { isPlayer = true; } - if (!senderHasPerm(sender, PERMISSION_PARTY)) { - noPermsMessage(sender, PERMISSION_PARTY); - return true; - } - for (int i = 1; i < args.length; i++) { if (args[i].equalsIgnoreCase("-fw")) { if (senderHasPerm(sender, PERMISSION_FIREWORKS)) { @@ -133,14 +128,37 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { noPermsMessage(sender, PERMISSION_STOP); } return true; - } else if (args[0].equalsIgnoreCase("me")) { - if (isPlayer) { + } else if (args[0].equalsIgnoreCase("me") && isPlayer) { + if (senderHasPerm(sender, PERMISSION_PARTY)) { parent.startParty(player, duration, sheepNumber, radius, period, fireworks); return true; + } else { + noPermsMessage(sender, PERMISSION_PARTY); + } + } else if (args[0].equalsIgnoreCase("help")) { + sender.sendMessage(ChatColor.YELLOW + "DiscoSheep Help\n" + + ChatColor.GRAY + " Subcommands\n" + ChatColor.WHITE + + "me: start a party for yourself\n" + + "all: start a party for all players on the server\n" + + "stop: stop all parties (takes no arguments)\n" + + ChatColor.GRAY + " Arguments\n" + ChatColor.WHITE + + "-n : set the number of sheep per player that spawn\n" + + "-t : set the party duration in seconds\n" + + "-p : set the number of ticks between each disco beat\n" + + "-r : set radius of the area in which sheep can spawn\n" + + "-fw: enables fireworks"); + return true; + } else if (args[0].equalsIgnoreCase("reload")) { + if (senderHasPerm(sender, PERMISSION_RELOAD)) { + parent.reloadConfigFromDisk(); + sender.sendMessage(ChatColor.GREEN + "DiscoSheep config reloaded from disk"); + return true; + } else { + noPermsMessage(sender, PERMISSION_RELOAD); } } else { sender.sendMessage(ChatColor.RED + "Invalid argument."); - return true; + return false; } } diff --git a/src/plugin.yml b/src/plugin.yml index e7b7fd5..a79c424 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,7 +1,35 @@ name: DiscoSheep main: gibstick.bukkit.discosheep.DiscoSheep -version: 0.9 +authors: [Gibstick, RangerMauve] +version: 1.0 commands: ds: description: "Main DiscoSheep command" - usage: /ds [arguments] \ No newline at end of file + usage: | + [arguments] + Use /ds help for more information +permissions: + discosheep.*: + description: Permission node for all DiscoSheep commands + default: op + children: + discosheep.party: true + discosheep.partyall: true + discosheep.fireworks: true + discosheep.stop: true + discosheep.reload: true + discosheep.party: + description: Allows a player to have a party of one + default: op + discosheep.partyall: + description: Allows a player to call a server-wide party + default: op + discosheep.stop: + description: Allows a player to stop all parties on the server + default: op + discosheep.fireworks: + description: Allows a player to enable have parties with fireworks + default: op + discosheep.reload: + description: Allows a player to reload settings from config.yml + default: op \ No newline at end of file