diff --git a/src/com/garbagemule/MobArena/commands/CommandHandler.java b/src/com/garbagemule/MobArena/commands/CommandHandler.java index 8c6fd98..aa7c1c7 100644 --- a/src/com/garbagemule/MobArena/commands/CommandHandler.java +++ b/src/com/garbagemule/MobArena/commands/CommandHandler.java @@ -202,6 +202,7 @@ public class CommandHandler implements CommandExecutor register(ListClassesCommand.class); register(SetClassCommand.class); + register(SetClassPriceCommand.class); register(RemoveClassCommand.class); register(ClassChestCommand.class); register(ListClassPermsCommand.class); diff --git a/src/com/garbagemule/MobArena/commands/setup/SetClassPriceCommand.java b/src/com/garbagemule/MobArena/commands/setup/SetClassPriceCommand.java new file mode 100644 index 0000000..19f0967 --- /dev/null +++ b/src/com/garbagemule/MobArena/commands/setup/SetClassPriceCommand.java @@ -0,0 +1,70 @@ +package com.garbagemule.MobArena.commands.setup; + +import com.garbagemule.MobArena.ArenaClass; +import com.garbagemule.MobArena.Messenger; +import com.garbagemule.MobArena.Msg; +import com.garbagemule.MobArena.commands.Command; +import com.garbagemule.MobArena.commands.CommandInfo; +import com.garbagemule.MobArena.commands.Commands; +import com.garbagemule.MobArena.framework.ArenaMaster; +import com.garbagemule.MobArena.util.TextUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandInfo( + name = "setclassprice", + pattern = "set(class)?price|fee", + usage = "/ma setclassprice $", + desc = "set the price of a class", + permission = "mobarena.setup.classes" +) +public class SetClassPriceCommand implements Command +{ + @Override + public boolean execute(ArenaMaster am, CommandSender sender, String... args) { + // Require at least a class name + if (args.length < 1) return false; + + // Grab the argument, if any. + String arg1 = args[0]; + String arg2 = (args.length > 1 ? args[1] : ""); + + // Grab the class. + ArenaClass ac = am.getClasses().get(arg1); + if (ac == null) { + Messenger.tell(sender, "No class named '" + arg1 + "'."); + return true; + } + + // Config-file value to set, and message to print + String value; + String msg; + + if (!arg2.equals("")) { + // Strip the dollar sign, if it's there + if (arg2.startsWith("$")) { + arg2 = arg2.substring(1); + } + + // Not a valid number? Bail! + if (!arg2.matches("([1-9]\\d*)|(\\d*.\\d\\d?)")) { + Messenger.tell(sender, "Could not parse price '" + arg2 + "'. Expected e.g. $10 or $2.50 or $.25"); + return true; + } + double price = Double.parseDouble(arg2); + + value = "$" + arg2; + msg = "Price for class '" + ac.getConfigName() + "' was set to " + am.getPlugin().economyFormat(price); + } else { + value = null; + msg = "Price for class '" + ac.getConfigName() + "' was removed. The class is now free!"; + } + + // Set the value, save and reload config + am.getPlugin().getConfig().set("classes." + ac.getConfigName() + ".price", value); + am.getPlugin().saveConfig(); + am.loadClasses(); + Messenger.tell(sender, msg); + return true; + } +}