diff --git a/src/com/garbagemule/MobArena/commands/Command.java b/src/com/garbagemule/MobArena/commands/Command.java
index 9851e53..99d8e1b 100644
--- a/src/com/garbagemule/MobArena/commands/Command.java
+++ b/src/com/garbagemule/MobArena/commands/Command.java
@@ -8,13 +8,22 @@ public interface Command
{
/**
* Execute the command using the given arguments.
- * If any arguments are provided, the first argument is -NOT- the
- * same as the command name, i.e. the CommandHandler must strip the
- * array of this element.
+ *
+ * If the method returns false, the command handler will print the usage
+ * message (usage + description) for the command, and as such, if the
+ * execution was successful in any way, the method should return true.
+ * Note that "successful in any way" means if the execution managed to
+ * complete in the sense that it itself prints a message to the sender,
+ * or otherwise executed properly, not if the intent of the command
+ * wasn't fulfilled. Typically, this means that false is only returned
+ * if the command was executed with a set of arguments that did not
+ * match the usage message.
+ *
* @param am an ArenaMaster instance
* @param sender the sender
* @param args array of arguments
- * @return true, if the command was successful
+ * @return true, if the command succeeded in any way, false if the
+ * command handler should print the usage message to the sender
*/
public boolean execute(ArenaMaster am, CommandSender sender, String... args);
}
diff --git a/src/com/garbagemule/MobArena/commands/CommandHandler.java b/src/com/garbagemule/MobArena/commands/CommandHandler.java
index 7c2ce20..ed95365 100644
--- a/src/com/garbagemule/MobArena/commands/CommandHandler.java
+++ b/src/com/garbagemule/MobArena/commands/CommandHandler.java
@@ -1,10 +1,6 @@
package com.garbagemule.MobArena.commands;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
@@ -56,7 +52,7 @@ public class CommandHandler implements CommandExecutor
if (matches.size() > 1) {
Messenger.tell(sender, Msg.MISC_MULTIPLE_MATCHES);
for (Command cmd : matches) {
- showUsage(cmd, sender);
+ showUsage(cmd, sender, false);
}
return true;
}
@@ -79,13 +75,15 @@ public class CommandHandler implements CommandExecutor
// Check if the last argument is a ?, in which case, display usage and description
if (last.equals("?") || last.equals("help")) {
- showUsage(command, sender);
+ showUsage(command, sender, true);
return true;
}
// Otherwise, execute the command!
String[] params = trimFirstArg(args);
- command.execute(am, sender, params);
+ if (!command.execute(am, sender, params)) {
+ showUsage(command, sender, true);
+ }
return true;
}
@@ -113,11 +111,11 @@ public class CommandHandler implements CommandExecutor
* @param cmd a Command
* @param sender a CommandSender
*/
- private void showUsage(Command cmd, CommandSender sender) {
+ private void showUsage(Command cmd, CommandSender sender, boolean prefix) {
CommandInfo info = cmd.getClass().getAnnotation(CommandInfo.class);
if (!plugin.has(sender, info.permission())) return;
- sender.sendMessage(info.usage() + " " + ChatColor.YELLOW + info.desc());
+ sender.sendMessage((prefix ? "Usage: " : "") + info.usage() + " " + ChatColor.YELLOW + info.desc());
}
/**
@@ -135,10 +133,33 @@ public class CommandHandler implements CommandExecutor
* @param sender a player or the console
*/
private void showHelp(CommandSender sender) {
- Messenger.tell(sender, "Available MobArena commands:");
-
+ StringBuilder user = new StringBuilder();
+ StringBuilder admin = new StringBuilder();
+ StringBuilder setup = new StringBuilder();
+
for (Command cmd : commands.values()) {
- showUsage(cmd, sender);
+ CommandInfo info = cmd.getClass().getAnnotation(CommandInfo.class);
+ if (!plugin.has(sender, info.permission())) continue;
+
+ StringBuilder buffy;
+ if (info.permission().startsWith("mobarena.admin")) {
+ buffy = admin;
+ } else if (info.permission().startsWith("mobarena.setup")) {
+ buffy = setup;
+ } else {
+ buffy = user;
+ }
+ buffy.append("\n")
+ .append(ChatColor.RESET).append(info.usage()).append(" ")
+ .append(ChatColor.YELLOW).append(info.desc());
+ }
+
+ if (admin.length() == 0 && setup.length() == 0) {
+ Messenger.tell(sender, "Available commands: " + user.toString());
+ } else {
+ Messenger.tell(sender, "User commands: " + user.toString());
+ if (admin.length() > 0) Messenger.tell(sender, "Admin commands: " + admin.toString());
+ if (setup.length() > 0) Messenger.tell(sender, "Setup commands: " + setup.toString());
}
}
@@ -148,57 +169,64 @@ public class CommandHandler implements CommandExecutor
* method, but this is neater, albeit more manual work.
*/
private void registerCommands() {
- commands = new HashMap();
+ commands = new LinkedHashMap();
// mobarena.use
- register(ArenaListCommand.class);
register(JoinCommand.class);
register(LeaveCommand.class);
- register(NotReadyCommand.class);
register(SpecCommand.class);
+ register(ArenaListCommand.class);
register(PlayerListCommand.class);
-
+ register(NotReadyCommand.class);
+
// mobarena.admin
- register(DisableCommand.class);
register(EnableCommand.class);
+ register(DisableCommand.class);
register(ForceCommand.class);
register(KickCommand.class);
register(RestoreCommand.class);
// mobarena.setup
- register(AddArenaCommand.class);
- register(AddClassPermCommand.class);
- register(AddContainerCommand.class);
- register(AddSpawnpointCommand.class);
- register(ArenaCommand.class);
- register(CheckDataCommand.class);
- register(CheckSpawnsCommand.class);
register(ConfigCommand.class);
- register(ContainersCommand.class);
- register(EditArenaCommand.class);
- register(ExpandLobbyRegionCommand.class);
- register(ExpandRegionCommand.class);
- register(ListClassesCommand.class);
- register(ListClassPermsCommand.class);
- register(ProtectCommand.class);
+
+ register(AddArenaCommand.class);
register(RemoveArenaCommand.class);
- register(RemoveClassCommand.class);
- register(RemoveClassPermCommand.class);
- register(RemoveContainerCommand.class);
- register(RemoveLeaderboardCommand.class);
- register(RemoveSpawnpointCommand.class);
+ register(EditArenaCommand.class);
+
+ register(ArenaCommand.class);
register(SetArenaCommand.class);
- register(SetClassCommand.class);
- register(SetLobbyRegionCommand.class);
- register(SetRegionCommand.class);
+
register(SetWarpCommand.class);
+ register(SetRegionCommand.class);
+ register(SetLobbyRegionCommand.class);
+ register(ExpandRegionCommand.class);
+ register(ExpandLobbyRegionCommand.class);
register(ShowRegionCommand.class);
register(ShowLobbyRegionCommand.class);
+ register(CheckDataCommand.class);
+
register(ShowSpawnsCommand.class);
register(SpawnpointsCommand.class);
+ register(AddSpawnpointCommand.class);
+ register(RemoveSpawnpointCommand.class);
+ register(CheckSpawnsCommand.class);
+
+ register(ContainersCommand.class);
+ register(AddContainerCommand.class);
+ register(RemoveContainerCommand.class);
+
+ register(ListClassesCommand.class);
+ register(SetClassCommand.class);
+ register(RemoveClassCommand.class);
+ register(ClassChestCommand.class);
+ register(ListClassPermsCommand.class);
+ register(AddClassPermCommand.class);
+ register(RemoveClassPermCommand.class);
+
+ register(ProtectCommand.class);
+ register(RemoveLeaderboardCommand.class);
register(AutoGenerateCommand.class);
register(AutoDegenerateCommand.class);
- register(ClassChestCommand.class);
}
/**
diff --git a/src/com/garbagemule/MobArena/commands/admin/DisableCommand.java b/src/com/garbagemule/MobArena/commands/admin/DisableCommand.java
index 7fc6d70..83ca268 100644
--- a/src/com/garbagemule/MobArena/commands/admin/DisableCommand.java
+++ b/src/com/garbagemule/MobArena/commands/admin/DisableCommand.java
@@ -33,9 +33,8 @@ public class DisableCommand implements Command
Arena arena = am.getArenaWithName(arg1);
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
-
disable(arena, sender);
return true;
}
@@ -43,7 +42,6 @@ public class DisableCommand implements Command
am.setEnabled(false);
am.saveConfig();
Messenger.tell(sender, "MobArena " + ChatColor.RED + "disabled");
-
return true;
}
diff --git a/src/com/garbagemule/MobArena/commands/admin/EnableCommand.java b/src/com/garbagemule/MobArena/commands/admin/EnableCommand.java
index 5849aef..9c16e79 100644
--- a/src/com/garbagemule/MobArena/commands/admin/EnableCommand.java
+++ b/src/com/garbagemule/MobArena/commands/admin/EnableCommand.java
@@ -33,9 +33,8 @@ public class EnableCommand implements Command
Arena arena = am.getArenaWithName(arg1);
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
-
enable(arena, sender);
return true;
}
@@ -43,7 +42,6 @@ public class EnableCommand implements Command
am.setEnabled(true);
am.saveConfig();
Messenger.tell(sender, "MobArena " + ChatColor.GREEN + "enabled");
-
return true;
}
diff --git a/src/com/garbagemule/MobArena/commands/admin/ForceCommand.java b/src/com/garbagemule/MobArena/commands/admin/ForceCommand.java
index ed1ffed..bbd438d 100644
--- a/src/com/garbagemule/MobArena/commands/admin/ForceCommand.java
+++ b/src/com/garbagemule/MobArena/commands/admin/ForceCommand.java
@@ -18,6 +18,9 @@ public class ForceCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
+ // Require at least one argument
+ if (args.length < 1) return false;
+
// Grab the argument, if any.
String arg1 = (args.length > 0 ? args[0] : "");
String arg2 = (args.length > 1 ? args[1] : "");
@@ -28,7 +31,6 @@ public class ForceCommand implements Command
for (Arena arena : am.getArenas()) {
arena.forceEnd();
}
-
Messenger.tell(sender, Msg.FORCE_END_ENDED);
am.resetArenaMap();
return true;
@@ -38,53 +40,46 @@ public class ForceCommand implements Command
Arena arena = am.getArenaWithName(arg2);
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
if (arena.getAllPlayers().isEmpty()) {
Messenger.tell(sender, Msg.FORCE_END_EMPTY);
- return false;
+ return true;
}
// And end it!
arena.forceEnd();
Messenger.tell(sender, Msg.FORCE_END_ENDED);
-
return true;
}
if (arg1.equals("start")) {
// Require argument.
- if (arg2.equals("")) {
- Messenger.tell(sender, "Usage: /ma force start ");
- return false;
- }
+ if (arg2.equals("")) return false;
// Grab the arena.
Arena arena = am.getArenaWithName(arg2);
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
if (arena.isRunning()) {
Messenger.tell(sender, Msg.FORCE_START_RUNNING);
- return false;
+ return true;
}
if (arena.getReadyPlayersInLobby().isEmpty()) {
Messenger.tell(sender, Msg.FORCE_START_NOT_READY);
- return false;
+ return true;
}
// And start it!
arena.forceStart();
Messenger.tell(sender, Msg.FORCE_START_STARTED);
-
return true;
}
-
- Messenger.tell(sender, "Usage: /ma force start|end ()");
- return true;
+ return false;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/admin/KickCommand.java b/src/com/garbagemule/MobArena/commands/admin/KickCommand.java
index eb498d3..6fe799b 100644
--- a/src/com/garbagemule/MobArena/commands/admin/KickCommand.java
+++ b/src/com/garbagemule/MobArena/commands/admin/KickCommand.java
@@ -19,28 +19,21 @@ public class KickCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+ // Require a player name
+ if (args.length != 1) return false;
- // Require an argument
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma kick ");
- return false;
- }
-
- Arena arena = am.getArenaWithPlayer(arg1);
+ Arena arena = am.getArenaWithPlayer(args[0]);
if (arena == null) {
Messenger.tell(sender, "That player is not in an arena.");
- return false;
+ return true;
}
// Grab the Player object.
- Player bp = am.getPlugin().getServer().getPlayer(arg1);
+ Player bp = am.getPlugin().getServer().getPlayer(args[0]);
// Force leave.
arena.playerLeave(bp);
-
- Messenger.tell(sender, "Player '" + arg1 + "' was kicked from arena '" + arena.configName() + "'.");
+ Messenger.tell(sender, "Player '" + args[0] + "' was kicked from arena '" + arena.configName() + "'.");
Messenger.tell(bp, "You were kicked by " + sender.getName() + ".");
return true;
}
diff --git a/src/com/garbagemule/MobArena/commands/admin/RestoreCommand.java b/src/com/garbagemule/MobArena/commands/admin/RestoreCommand.java
index cca6c9e..3298809 100644
--- a/src/com/garbagemule/MobArena/commands/admin/RestoreCommand.java
+++ b/src/com/garbagemule/MobArena/commands/admin/RestoreCommand.java
@@ -18,26 +18,19 @@ public class RestoreCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+ // Require a player name
+ if (args.length != 1) return false;
- // Require an argument
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma restore ");
- return false;
- }
-
- if (am.getArenaWithPlayer(arg1) != null) {
+ if (am.getArenaWithPlayer(args[0]) != null) {
Messenger.tell(sender, "Player is currently in an arena.");
- return false;
+ return true;
}
- if (InventoryManager.restoreFromFile(am.getPlugin(), am.getPlugin().getServer().getPlayer(arg1))) {
- Messenger.tell(sender, "Restored " + arg1 + "'s inventory!");
+ if (InventoryManager.restoreFromFile(am.getPlugin(), am.getPlugin().getServer().getPlayer(args[0]))) {
+ Messenger.tell(sender, "Restored " + args[0] + "'s inventory!");
} else {
- Messenger.tell(sender, "Failed to restore " + arg1 + "'s inventory.");
+ Messenger.tell(sender, "Failed to restore " + args[0] + "'s inventory.");
}
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/AddArenaCommand.java b/src/com/garbagemule/MobArena/commands/setup/AddArenaCommand.java
index a587c57..e682730 100644
--- a/src/com/garbagemule/MobArena/commands/setup/AddArenaCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/AddArenaCommand.java
@@ -21,31 +21,25 @@ public class AddArenaCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
-
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+
+ // Require an arena name
+ if (args.length != 1) return false;
// Cast the sender.
Player p = (Player) sender;
-
- // Require an argument
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma addarena ");
- return true;
- }
- Arena arena = am.getArenaWithName(arg1);
+ Arena arena = am.getArenaWithName(args[0]);
if (arena != null) {
Messenger.tell(sender, "An arena with that name already exists.");
return true;
}
- arena = am.createArenaNode(arg1, p.getWorld());
+ arena = am.createArenaNode(args[0], p.getWorld());
am.setSelectedArena(arena);
- Messenger.tell(sender, "New arena with name '" + arg1 + "' created!");
+ Messenger.tell(sender, "New arena with name '" + args[0] + "' created!");
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/AddClassPermCommand.java b/src/com/garbagemule/MobArena/commands/setup/AddClassPermCommand.java
index 2e1016c..b03617c 100644
--- a/src/com/garbagemule/MobArena/commands/setup/AddClassPermCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/AddClassPermCommand.java
@@ -18,30 +18,24 @@ public class AddClassPermCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
- String arg2 = (args.length > 1 ? args[1] : "");
-
- if (arg1.equals("") || arg2.equals("")) {
- Messenger.tell(sender, "Usage: /ma addclassperm ");
- return false;
- }
-
+ // Require classname and permission
+ if (args.length != 2) return false;
+
// Grab the arena class
- ArenaClass arenaClass = am.getClasses().get(arg1);
+ ArenaClass arenaClass = am.getClasses().get(args[0]);
if (arenaClass == null) {
- Messenger.tell(sender, "The class '" + TextUtils.camelCase(arg1) + "' does not exist.");
- return false;
+ Messenger.tell(sender, "The class '" + TextUtils.camelCase(args[0]) + "' does not exist.");
+ return true;
}
// Try to add the permission.
- if (am.addClassPermission(arg1, arg2)) {
- Messenger.tell(sender, "Added permission '" + arg2 + "' to class '" + TextUtils.camelCase(arg1) + "'.");
+ if (am.addClassPermission(args[0], args[1])) {
+ Messenger.tell(sender, "Added permission '" + args[1] + "' to class '" + TextUtils.camelCase(args[0]) + "'.");
return true;
}
// If it wasn't added, notify.
- Messenger.tell(sender, "Permission '" + arg2 + "' was NOT added to class '" + TextUtils.camelCase(arg1) + "'.");
- return false;
+ Messenger.tell(sender, "Permission '" + args[1] + "' was NOT added to class '" + TextUtils.camelCase(args[0]) + "'.");
+ return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/AddContainerCommand.java b/src/com/garbagemule/MobArena/commands/setup/AddContainerCommand.java
index bec6870..222a35b 100644
--- a/src/com/garbagemule/MobArena/commands/setup/AddContainerCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/AddContainerCommand.java
@@ -21,27 +21,23 @@ public class AddContainerCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
-
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+
+ // Require a point name
+ if (args.length != 1 || args[0].matches("^[a-zA-Z][a-zA-Z0-9]*$")) return false;
// Cast the sender.
Player p = (Player) sender;
-
- if (!arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$")) {
- Messenger.tell(sender, "Usage: /ma addcontainer ");
- return false;
- }
-
+
+ // Make sure we're looking at a container
if (!(p.getTargetBlock(null, 50).getState() instanceof InventoryHolder)) {
Messenger.tell(sender, "You must look at container.");
- return false;
+ return true;
}
- am.getSelectedArena().getRegion().addChest(arg1, p.getTargetBlock(null, 50).getLocation());
- Messenger.tell(sender, "Container '" + arg1 + "' added for arena \"" + am.getSelectedArena().configName() + "\"");
+ am.getSelectedArena().getRegion().addChest(args[0], p.getTargetBlock(null, 50).getLocation());
+ Messenger.tell(sender, "Container '" + args[0] + "' added for arena \"" + am.getSelectedArena().configName() + "\"");
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/AddSpawnpointCommand.java b/src/com/garbagemule/MobArena/commands/setup/AddSpawnpointCommand.java
index 5e3fca9..e07f04f 100644
--- a/src/com/garbagemule/MobArena/commands/setup/AddSpawnpointCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/AddSpawnpointCommand.java
@@ -22,19 +22,14 @@ public class AddSpawnpointCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
-
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+
+ // Require a point name
+ if (args.length != 1 || args[0].matches("^[a-zA-Z][a-zA-Z0-9]*$")) return false;
// Cast the sender.
Player p = (Player) sender;
-
- if (!arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$")) {
- Messenger.tell(sender, "Usage: /ma addspawn ");
- return true;
- }
// Make a world check first
Arena arena = am.getSelectedArena();
@@ -57,7 +52,7 @@ public class AddSpawnpointCommand implements Command
if (changeWorld) arena.setWorld(aw);
} else {
// Add the spawnpoint
- am.getSelectedArena().getRegion().addSpawn(arg1, p.getLocation());
+ am.getSelectedArena().getRegion().addSpawn(args[0], p.getLocation());
// Notify the player if world changed
if (changeWorld) {
@@ -67,7 +62,7 @@ public class AddSpawnpointCommand implements Command
}
// Then notify about point set
- Messenger.tell(sender, "Spawnpoint '" + arg1 + "' added for arena '" + am.getSelectedArena().configName() + "'");
+ Messenger.tell(sender, "Spawnpoint '" + args[0] + "' added for arena '" + am.getSelectedArena().configName() + "'");
arena.getRegion().checkData(am.getPlugin(), sender, false, false, false, true);
}
return true;
diff --git a/src/com/garbagemule/MobArena/commands/setup/AutoDegenerateCommand.java b/src/com/garbagemule/MobArena/commands/setup/AutoDegenerateCommand.java
index 41c2b94..ba80297 100644
--- a/src/com/garbagemule/MobArena/commands/setup/AutoDegenerateCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/AutoDegenerateCommand.java
@@ -18,33 +18,28 @@ public class AutoDegenerateCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the arguments, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+ // Require an arena name
+ if (args.length != 1) return false;
- // Require an argument
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma autodegenerate ");
- return true;
- }
-
+ // We have to make sure at least one arena exists before degenerating
if (am.getArenas().size() < 2) {
Messenger.tell(sender, "At least one arena must exist!");
return true;
}
// Check if arena exists.
- Arena arena = am.getArenaWithName(arg1);
+ Arena arena = am.getArenaWithName(args[0]);
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
- if (!MAUtils.undoItHippieMonster(arg1, am.getPlugin(), true)) {
+ if (!MAUtils.undoItHippieMonster(args[0], am.getPlugin(), true)) {
Messenger.tell(sender, "Could not degenerate arena.");
return true;
}
- Messenger.tell(sender, "Arena with name '" + arg1 + "' degenerated.");
+ Messenger.tell(sender, "Arena with name '" + args[0] + "' degenerated.");
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/AutoGenerateCommand.java b/src/com/garbagemule/MobArena/commands/setup/AutoGenerateCommand.java
index de4f911..f881af6 100644
--- a/src/com/garbagemule/MobArena/commands/setup/AutoGenerateCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/AutoGenerateCommand.java
@@ -21,34 +21,28 @@ public class AutoGenerateCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
-
- // Grab the arguments, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+
+ // Require an arena name
+ if (args.length != 1) return false;
// Cast the sender.
Player p = (Player) sender;
-
- // Require an argument
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma autogenerate ");
- return true;
- }
// Check if arena already exists.
- Arena arena = am.getArenaWithName(arg1);
+ Arena arena = am.getArenaWithName(args[0]);
if (arena != null) {
Messenger.tell(sender, "An arena with that name already exists.");
return true;
}
- if (!MAUtils.doooooItHippieMonster(p.getLocation(), 13, arg1, am.getPlugin())) {
+ if (!MAUtils.doooooItHippieMonster(p.getLocation(), 13, args[0], am.getPlugin())) {
Messenger.tell(sender, "Could not auto-generate arena.");
return true;
}
- Messenger.tell(sender, "Arena with name '" + arg1 + "' generated.");
+ Messenger.tell(sender, "Arena with name '" + args[0] + "' generated.");
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/CheckDataCommand.java b/src/com/garbagemule/MobArena/commands/setup/CheckDataCommand.java
index f333be3..47f2e10 100644
--- a/src/com/garbagemule/MobArena/commands/setup/CheckDataCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/CheckDataCommand.java
@@ -10,7 +10,7 @@ import com.garbagemule.MobArena.framework.ArenaMaster;
@CommandInfo(
name = "checkdata",
pattern = "checkdata",
- usage = "/ma checkdata",
+ usage = "/ma checkdata ()",
desc = "check if all required points are set up",
permission = "mobarena.setup.checkdata"
)
@@ -24,7 +24,7 @@ public class CheckDataCommand implements Command
Arena arena = arg1.equals("") ? am.getSelectedArena() : am.getArenaWithName(arg1);
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
arena.getRegion().checkData(am.getPlugin(), sender, true, true, true, true);
diff --git a/src/com/garbagemule/MobArena/commands/setup/CheckSpawnsCommand.java b/src/com/garbagemule/MobArena/commands/setup/CheckSpawnsCommand.java
index 66a5853..6637f1f 100644
--- a/src/com/garbagemule/MobArena/commands/setup/CheckSpawnsCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/CheckSpawnsCommand.java
@@ -23,7 +23,7 @@ public class CheckSpawnsCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
// Grab the argument, if any.
@@ -33,29 +33,23 @@ public class CheckSpawnsCommand implements Command
Player p = (Player) sender;
Arena arena;
-
if (arg1.equals("")) {
arena = am.getArenaAtLocation(p.getLocation());
if (arena == null) {
arena = am.getSelectedArena();
}
-
if (arena.getRegion().getSpawnpoints().isEmpty()) {
Messenger.tell(sender, "There are no spawnpoints in the selected arena.");
- return false;
+ return true;
}
- }
- else {
+ } else {
arena = am.getArenaWithName(arg1);
-
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
}
-
arena.getRegion().checkSpawns(p);
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/ClassChestCommand.java b/src/com/garbagemule/MobArena/commands/setup/ClassChestCommand.java
index 7e2fa73..39b4899 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ClassChestCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ClassChestCommand.java
@@ -26,14 +26,12 @@ public class ClassChestCommand implements Command {
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
- }
-
- if (args.length != 1) {
- Messenger.tell(sender, "Usage: /ma classchest ");
return true;
}
+ // Require a class name
+ if (args.length != 1) return false;
+
ArenaClass ac = am.getClasses().get(args[0].toLowerCase());
if (ac == null) {
Messenger.tell(sender, "Class not found.");
diff --git a/src/com/garbagemule/MobArena/commands/setup/ConfigCommand.java b/src/com/garbagemule/MobArena/commands/setup/ConfigCommand.java
index ff2f2f8..c919164 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ConfigCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ConfigCommand.java
@@ -17,23 +17,18 @@ public class ConfigCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
-
- if (arg1.equals("reload")) {
+ // Require reload/save
+ if (args.length != 1) return false;
+
+ if (args[0].equals("reload")) {
am.reloadConfig();
Messenger.tell(sender, "Config reloaded.");
- return true;
- }
-
- if (arg1.equals("save")) {
+ } else if (args[0].equals("save")) {
am.saveConfig();
Messenger.tell(sender, "Config saved.");
- return true;
+ } else {
+ return false;
}
-
- // Requires an argument.
- Messenger.tell(sender, "Usage: /ma config reload|save");
- return false;
+ return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/EditArenaCommand.java b/src/com/garbagemule/MobArena/commands/setup/EditArenaCommand.java
index 77db98e..96c32e4 100644
--- a/src/com/garbagemule/MobArena/commands/setup/EditArenaCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/EditArenaCommand.java
@@ -36,15 +36,13 @@ public class EditArenaCommand implements Command
// Argument is [true|false]
if (arg1.matches("true|on") || arg1.matches("false|off")) {
arena = am.getSelectedArena();
- arena.setEditMode(arg1.equals("true"));
+ arena.setEditMode(arg1.matches("true|on"));
}
// Argument is
else {
arena = am.getArenaWithName(arg1);
if (arena == null) {
Messenger.tell(sender, "There is no arena with that name.");
- Messenger.tell(sender, "Usage: /ma editarena (true|false)");
- Messenger.tell(sender, " or /ma editarena (true|false)");
return true;
}
arena.setEditMode(!arena.inEditMode());
@@ -54,18 +52,14 @@ public class EditArenaCommand implements Command
// Two arguments
else {
if (!(arg2.matches("true|on") || arg2.matches("false|off"))) {
- Messenger.tell(sender, "Usage: /ma editarena (true|false)");
- Messenger.tell(sender, " or /ma editarena (true|false)");
- return true;
+ return false;
}
arena = am.getArenaWithName(arg1);
if (arena == null) {
Messenger.tell(sender, "There is no arena with that name.");
- Messenger.tell(sender, "Usage: /ma editarena (true|false)");
- Messenger.tell(sender, " or /ma editarena (true|false)");
return true;
}
- arena.setEditMode(arg2.equals("true"));
+ arena.setEditMode(arg2.matches("true|on"));
}
Messenger.tell(sender, "Edit mode for arena '" + arena.configName() + "': " + ((arena.inEditMode()) ? ChatColor.GREEN + "true" : ChatColor.RED + "false"));
diff --git a/src/com/garbagemule/MobArena/commands/setup/ExpandLobbyRegionCommand.java b/src/com/garbagemule/MobArena/commands/setup/ExpandLobbyRegionCommand.java
index 55111c2..0fb8112 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ExpandLobbyRegionCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ExpandLobbyRegionCommand.java
@@ -17,40 +17,29 @@ public class ExpandLobbyRegionCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
- String arg2 = (args.length > 1 ? args[1] : "");
-
- if (args.length != 2 || !arg1.matches("(-)?[0-9]+")) {
- Messenger.tell(sender, "Usage: /ma expandlobbyregion up|down|out");
- return false;
- }
+ // Require amount and direction
+ if (args.length != 2 || !args[0].matches("(-)?[0-9]+")) return false;
if (!am.getSelectedArena().getRegion().isLobbyDefined()) {
Messenger.tell(sender, "You must first define l1 and l2");
return true;
}
- if (arg2.equals("up")) {
- am.getSelectedArena().getRegion().expandLobbyUp(Integer.parseInt(arg1));
- }
- else if (arg2.equals("down")) {
- am.getSelectedArena().getRegion().expandLobbyDown(Integer.parseInt(arg1));
- }
- else if (arg2.equals("out")) {
- am.getSelectedArena().getRegion().expandLobbyOut(Integer.parseInt(arg1));
- }
- else {
- Messenger.tell(sender, "Usage: /ma expandlobbyregion up|down|out");
- return true;
+ if (args[1].equals("up")) {
+ am.getSelectedArena().getRegion().expandLobbyUp(Integer.parseInt(args[0]));
+ } else if (args[1].equals("down")) {
+ am.getSelectedArena().getRegion().expandLobbyDown(Integer.parseInt(args[0]));
+ } else if (args[1].equals("out")) {
+ am.getSelectedArena().getRegion().expandLobbyOut(Integer.parseInt(args[0]));
+ } else {
+ return false;
}
// In case of a "negative" region, fix it!
am.getSelectedArena().getRegion().fixLobbyRegion();
- Messenger.tell(sender, "Lobby region for '" + am.getSelectedArena().configName() + "' expanded " + arg2 + " by " + arg1 + " blocks.");
+ Messenger.tell(sender, "Lobby region for '" + am.getSelectedArena().configName() + "' expanded " + args[1] + " by " + args[0] + " blocks.");
am.getSelectedArena().getRegion().save();
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/ExpandRegionCommand.java b/src/com/garbagemule/MobArena/commands/setup/ExpandRegionCommand.java
index cea8aeb..c187b26 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ExpandRegionCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ExpandRegionCommand.java
@@ -17,40 +17,29 @@ public class ExpandRegionCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
- String arg2 = (args.length > 1 ? args[1] : "");
-
- if (args.length != 2 || !arg1.matches("(-)?[0-9]+")) {
- Messenger.tell(sender, "Usage: /ma expandregion up|down|out");
- return false;
- }
+ // Require amount and direction
+ if (args.length != 2 || !args[0].matches("(-)?[0-9]+")) return false;
if (!am.getSelectedArena().getRegion().isDefined()) {
Messenger.tell(sender, "You must first define p1 and p2");
return true;
}
-
- if (arg2.equals("up")) {
- am.getSelectedArena().getRegion().expandUp(Integer.parseInt(arg1));
- }
- else if (arg2.equals("down")) {
- am.getSelectedArena().getRegion().expandDown(Integer.parseInt(arg1));
- }
- else if (arg2.equals("out")) {
- am.getSelectedArena().getRegion().expandOut(Integer.parseInt(arg1));
- }
- else {
- Messenger.tell(sender, "Usage: /ma expandregion up|down|out");
- return true;
+
+ if (args[1].equals("up")) {
+ am.getSelectedArena().getRegion().expandUp(Integer.parseInt(args[0]));
+ } else if (args[1].equals("down")) {
+ am.getSelectedArena().getRegion().expandDown(Integer.parseInt(args[0]));
+ } else if (args[1].equals("out")) {
+ am.getSelectedArena().getRegion().expandOut(Integer.parseInt(args[0]));
+ } else {
+ return false;
}
// In case of a "negative" region, fix it!
am.getSelectedArena().getRegion().fixRegion();
- Messenger.tell(sender, "Region for '" + am.getSelectedArena().configName() + "' expanded " + arg2 + " by " + arg1 + " blocks.");
+ Messenger.tell(sender, "Region for '" + am.getSelectedArena().configName() + "' expanded " + args[1] + " by " + args[0] + " blocks.");
am.getSelectedArena().getRegion().save();
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/ListClassPermsCommand.java b/src/com/garbagemule/MobArena/commands/setup/ListClassPermsCommand.java
index 2973677..7f7f48e 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ListClassPermsCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ListClassPermsCommand.java
@@ -21,17 +21,11 @@ public class ListClassPermsCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+ // Require a class name
+ if (args.length != 1) return false;
- // Require an argument.
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma listclassperms ");
- return true;
- }
-
- ArenaClass arenaClass = am.getClasses().get(arg1);
- String className = TextUtils.camelCase(arg1);
+ ArenaClass arenaClass = am.getClasses().get(args[0]);
+ String className = TextUtils.camelCase(args[0]);
if (arenaClass == null) {
Messenger.tell(sender, "The class '" + className + "' does not exist.");
diff --git a/src/com/garbagemule/MobArena/commands/setup/ProtectCommand.java b/src/com/garbagemule/MobArena/commands/setup/ProtectCommand.java
index 478407c..81ebf7e 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ProtectCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ProtectCommand.java
@@ -43,8 +43,6 @@ public class ProtectCommand implements Command
arena = am.getArenaWithName(arg1);
if (arena == null) {
Messenger.tell(sender, "There is no arena with that name.");
- Messenger.tell(sender, "Usage: /ma protect (true|false)");
- Messenger.tell(sender, " or /ma protect (true|false)");
return true;
}
arena.setProtected(!arena.isProtected());
@@ -54,18 +52,14 @@ public class ProtectCommand implements Command
// Two arguments
else {
if (!(arg2.matches("true|on") || arg2.matches("false|off"))) {
- Messenger.tell(sender, "Usage: /ma protect (true|false)");
- Messenger.tell(sender, " or /ma protect (true|false)");
- return true;
+ return false;
}
arena = am.getArenaWithName(arg1);
if (arena == null) {
Messenger.tell(sender, "There is no arena with that name.");
- Messenger.tell(sender, "Usage: /ma protect (true|false)");
- Messenger.tell(sender, " or /ma protect (true|false)");
return true;
}
- arena.setProtected(arg2.equals("true"));
+ arena.setProtected(arg2.matches("true|on"));
}
arena.getPlugin().saveConfig();
diff --git a/src/com/garbagemule/MobArena/commands/setup/RemoveArenaCommand.java b/src/com/garbagemule/MobArena/commands/setup/RemoveArenaCommand.java
index c2adf4c..21bdb68 100644
--- a/src/com/garbagemule/MobArena/commands/setup/RemoveArenaCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/RemoveArenaCommand.java
@@ -18,24 +18,18 @@ public class RemoveArenaCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
-
- // Require an argument
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma removearena ");
- return false;
- }
+ // Require an arena name
+ if (args.length != 1) return false;
if (am.getArenas().size() == 1) {
Messenger.tell(sender, "At least one arena must exist.");
- return false;
+ return true;
}
- Arena arena = am.getArenaWithName(arg1);
+ Arena arena = am.getArenaWithName(args[0]);
if (arena == null) {
Messenger.tell(sender, "There is no arena with that name.");
- return false;
+ return true;
}
am.removeArenaNode(arena);
diff --git a/src/com/garbagemule/MobArena/commands/setup/RemoveClassCommand.java b/src/com/garbagemule/MobArena/commands/setup/RemoveClassCommand.java
index fb514d2..6ade546 100644
--- a/src/com/garbagemule/MobArena/commands/setup/RemoveClassCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/RemoveClassCommand.java
@@ -18,21 +18,15 @@ public class RemoveClassCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
-
- // Require an argument.
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma removeclass ");
- return false;
- }
+ // Require a class name
+ if (args.length != 1) return false;
// Find the class
- ArenaClass arenaClass = am.getClasses().get(arg1);
- String className = TextUtils.camelCase(arg1);
+ ArenaClass arenaClass = am.getClasses().get(args[0]);
+ String className = TextUtils.camelCase(args[0]);
if (arenaClass == null) {
Messenger.tell(sender, "The class '" + className + "' does not exist.");
- return false;
+ return true;
}
am.removeClassNode(className);
diff --git a/src/com/garbagemule/MobArena/commands/setup/RemoveClassPermCommand.java b/src/com/garbagemule/MobArena/commands/setup/RemoveClassPermCommand.java
index 6c616ab..fa084e2 100644
--- a/src/com/garbagemule/MobArena/commands/setup/RemoveClassPermCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/RemoveClassPermCommand.java
@@ -18,30 +18,24 @@ public class RemoveClassPermCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
- String arg2 = (args.length > 1 ? args[1] : "");
-
- if (arg1.equals("") || arg2.equals("")) {
- Messenger.tell(sender, "Usage: /ma removeclassperm ");
- return false;
- }
-
+ // Require class name and permission
+ if (args.length != 2) return false;
+
// Grab the arena class
- ArenaClass arenaClass = am.getClasses().get(arg1);
+ ArenaClass arenaClass = am.getClasses().get(args[0]);
if (arenaClass == null) {
- Messenger.tell(sender, "The class '" + TextUtils.camelCase(arg1) + "' does not exist.");
- return false;
+ Messenger.tell(sender, "The class '" + TextUtils.camelCase(args[0]) + "' does not exist.");
+ return true;
}
// Remove the permission.
- if (am.removeClassPermission(arg1, arg2)) {
- Messenger.tell(sender, "Removed permission '" + arg2 + "' from class '" + TextUtils.camelCase(arg1) + "'.");
+ if (am.removeClassPermission(args[0], args[1])) {
+ Messenger.tell(sender, "Removed permission '" + args[1] + "' from class '" + TextUtils.camelCase(args[0]) + "'.");
return true;
}
// If it wasn't removed, notify.
- Messenger.tell(sender, "Permission '" + arg2 + "' was NOT removed from class '" + TextUtils.camelCase(arg1) + "'.");
- return false;
+ Messenger.tell(sender, "Permission '" + args[1] + "' was NOT removed from class '" + TextUtils.camelCase(args[0]) + "'.");
+ return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/RemoveContainerCommand.java b/src/com/garbagemule/MobArena/commands/setup/RemoveContainerCommand.java
index f20463f..9d429b4 100644
--- a/src/com/garbagemule/MobArena/commands/setup/RemoveContainerCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/RemoveContainerCommand.java
@@ -17,19 +17,14 @@ public class RemoveContainerCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+ // Require a point name
+ if (args.length != 1 || !args[0].matches("^[a-zA-Z][a-zA-Z0-9]*$")) return false;
- // Require an argument
- if (!arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$")) {
- Messenger.tell(sender, "Usage: /ma removecontainer ");
- return false;
+ if (am.getSelectedArena().getRegion().removeChest(args[0])) {
+ Messenger.tell(sender, "Container " + args[0] + " removed for arena '" + am.getSelectedArena().configName() + "'");
+ } else {
+ Messenger.tell(sender, "Could not find the container " + args[0] + "for the arena '" + am.getSelectedArena().configName() + "'");
}
-
- if (am.getSelectedArena().getRegion().removeChest(arg1))
- Messenger.tell(sender, "Container " + arg1 + " removed for arena '" + am.getSelectedArena().configName() + "'");
- else
- Messenger.tell(sender, "Could not find the container " + arg1 + "for the arena '" + am.getSelectedArena().configName() + "'");
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java b/src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java
index 7fec32f..760139f 100644
--- a/src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java
@@ -9,14 +9,14 @@ import com.garbagemule.MobArena.commands.CommandInfo;
import com.garbagemule.MobArena.framework.ArenaMaster;
@CommandInfo(
- name = "removeleaderboard",
- pattern = "(del(.)*|r(e)?m(ove)?)leaderboard",
- usage = "/ma removeleaderboard ",
- desc = "remove the selected arena's leaderboard",
- permission = "mobarena.setup.leaderboards"
- )
-public class RemoveLeaderboardCommand implements Command{
-
+ name = "removeleaderboard",
+ pattern = "(del(.)*|r(e)?m(ove)?)leaderboard",
+ usage = "/ma removeleaderboard ()",
+ desc = "remove the selected arena's leaderboard",
+ permission = "mobarena.setup.leaderboards"
+)
+public class RemoveLeaderboardCommand implements Command
+{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
// Grab the argument, if any.
@@ -28,29 +28,22 @@ public class RemoveLeaderboardCommand implements Command{
am.getSelectedArena().getRegion().set("leaderboard", null);
Messenger.tell(sender, "Leaderboard for " + am.getSelectedArena().arenaName() + " successfully removed!");
return true;
- }
- else {
+ } else {
Messenger.tell(sender, Msg.ARENA_LBOARD_NOT_FOUND);
}
- }
- else {
+ } else {
if (am.getArenaWithName(arg1) != null) {
if (am.getSelectedArena().getRegion().getLeaderboard() != null) {
am.getArenaWithName(arg1).getRegion().set("leaderboard", null);
Messenger.tell(sender, "Leaderboard for " + am.getArenaWithName(arg1).arenaName() + " successfully removed!");
return true;
- }
- else {
+ } else {
Messenger.tell(sender, Msg.ARENA_LBOARD_NOT_FOUND);
}
- }
- else {
- Messenger.tell(sender, "Usage: /ma removeleaderboard ");
- return false;
+ } else {
+ Messenger.tell(sender, "No arena with that name exists.");
}
}
-
- return false;
+ return true;
}
-
}
\ No newline at end of file
diff --git a/src/com/garbagemule/MobArena/commands/setup/RemoveSpawnpointCommand.java b/src/com/garbagemule/MobArena/commands/setup/RemoveSpawnpointCommand.java
index 5630343..89b5d86 100644
--- a/src/com/garbagemule/MobArena/commands/setup/RemoveSpawnpointCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/RemoveSpawnpointCommand.java
@@ -17,19 +17,14 @@ public class RemoveSpawnpointCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+ // Require a point name
+ if (args.length != 1 || !args[0].matches("^[a-zA-Z][a-zA-Z0-9]*$")) return false;
- // Require an argument
- if (!arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$")) {
- Messenger.tell(sender, "Usage: /ma removespawn ");
- return true;
+ if (am.getSelectedArena().getRegion().removeSpawn(args[0])) {
+ Messenger.tell(sender, "Spawnpoint " + args[0] + " removed for arena '" + am.getSelectedArena().configName() + "'");
+ } else {
+ Messenger.tell(sender, "Could not find the spawnpoint " + args[0] + "for the arena '" + am.getSelectedArena().configName() + "'");
}
-
- if (am.getSelectedArena().getRegion().removeSpawn(arg1))
- Messenger.tell(sender, "Spawnpoint " + arg1 + " removed for arena '" + am.getSelectedArena().configName() + "'");
- else
- Messenger.tell(sender, "Could not find the spawnpoint " + arg1 + "for the arena '" + am.getSelectedArena().configName() + "'");
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/SetArenaCommand.java b/src/com/garbagemule/MobArena/commands/setup/SetArenaCommand.java
index c451752..8a4c64e 100644
--- a/src/com/garbagemule/MobArena/commands/setup/SetArenaCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/SetArenaCommand.java
@@ -18,24 +18,16 @@ public class SetArenaCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
-
- // Require an argument
- if (arg1.equals("")) {
- Messenger.tell(sender, "Usage: /ma setarena ");
- return false;
- }
+ // Require an arena name
+ if (args.length != 1) return false;
- Arena arena = am.getArenaWithName(arg1);
+ Arena arena = am.getArenaWithName(args[0]);
if (arena != null) {
am.setSelectedArena(arena);
Messenger.tell(sender, "Currently selected arena: " + arena.configName());
- }
- else {
+ } else {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
}
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/SetClassCommand.java b/src/com/garbagemule/MobArena/commands/setup/SetClassCommand.java
index a8c569d..df2f439 100644
--- a/src/com/garbagemule/MobArena/commands/setup/SetClassCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/SetClassCommand.java
@@ -21,8 +21,11 @@ public class SetClassCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
+
+ // Require at least a class name
+ if (args.length < 1) return false;
// Grab the argument, if any.
String arg1 = (args.length > 0 ? args[0] : "");
@@ -31,19 +34,9 @@ public class SetClassCommand implements Command
// Cast the sender.
Player p = (Player) sender;
- // Require an argument.
- if (arg1.equals("")) {
- Messenger.tell(p, "Usage: /ma setclass (safe) ");
- return true;
- }
-
// Check if we're overwriting.
boolean safe = arg1.equals("safe");
-
- if (safe && arg2.equals("")) {
- Messenger.tell(p, "Usage: /ma setclass (safe) ");
- return true;
- }
+ if (safe && arg2.equals("")) return false;
// If so, use arg2, otherwise, use arg1
String className = TextUtils.camelCase(safe ? arg2 : arg1);
diff --git a/src/com/garbagemule/MobArena/commands/setup/SetLobbyRegionCommand.java b/src/com/garbagemule/MobArena/commands/setup/SetLobbyRegionCommand.java
index df1c3cc..535c241 100644
--- a/src/com/garbagemule/MobArena/commands/setup/SetLobbyRegionCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/SetLobbyRegionCommand.java
@@ -22,7 +22,7 @@ public class SetLobbyRegionCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
// Grab the argument, if any.
diff --git a/src/com/garbagemule/MobArena/commands/setup/SetRegionCommand.java b/src/com/garbagemule/MobArena/commands/setup/SetRegionCommand.java
index 21358a3..062f4a6 100644
--- a/src/com/garbagemule/MobArena/commands/setup/SetRegionCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/SetRegionCommand.java
@@ -22,19 +22,14 @@ public class SetRegionCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
-
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+
+ // Require a region point
+ if (args.length != 1 || !args[0].matches("p1|p2")) return false;
// Cast the sender.
Player p = (Player) sender;
-
- if (!(arg1.equals("p1") || arg1.equals("p2"))) {
- Messenger.tell(sender, "Usage: /ma setregion p1|p2");
- return true;
- }
Arena arena = am.getSelectedArena();
World aw = arena.getWorld();
@@ -46,8 +41,8 @@ public class SetRegionCommand implements Command
}
arena.setWorld(p.getWorld());
- arena.getRegion().set(arg1, p.getLocation());
- Messenger.tell(sender, "Region point " + arg1 + " for arena '" + am.getSelectedArena().configName() + "' set.");
+ arena.getRegion().set(args[0], p.getLocation());
+ Messenger.tell(sender, "Region point " + args[0] + " for arena '" + am.getSelectedArena().configName() + "' set.");
arena.getRegion().checkData(am.getPlugin(), sender, true, true, false, false);
return true;
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/SetWarpCommand.java b/src/com/garbagemule/MobArena/commands/setup/SetWarpCommand.java
index 2c54051..99b990b 100644
--- a/src/com/garbagemule/MobArena/commands/setup/SetWarpCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/SetWarpCommand.java
@@ -9,9 +9,6 @@ import com.garbagemule.MobArena.*;
import com.garbagemule.MobArena.commands.*;
import com.garbagemule.MobArena.framework.ArenaMaster;
-import java.util.Arrays;
-import java.util.List;
-
@CommandInfo(
name = "setwarp",
pattern = "set(warp|point)",
@@ -21,26 +18,25 @@ import java.util.List;
)
public class SetWarpCommand implements Command
{
- private static final List WARPS = Arrays.asList("arena", "lobby", "spectator", "exit");
-
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
-
- // Grab the argument, if any.
- String arg1 = (args.length > 0 ? args[0] : "");
+
+ // Require a point name
+ if (args.length != 1) return false;
// Cast the sender.
Player p = (Player) sender;
// spec -> spectator
- if (arg1.equals("spec")) arg1 = "spectator";
+ if (args[0].equals("spec")) args[0] = "spectator";
- if (!WARPS.contains(arg1)) {
- Messenger.tell(sender, "Usage: /ma setwarp arena|lobby|spectator|exit");
+ // Check that the point is valid
+ if (!args[0].matches("arena|lobby|spectator|exit")) {
+ Messenger.tell(sender, "There's no warp called '" + args[0] + "'.");
return true;
}
@@ -48,13 +44,13 @@ public class SetWarpCommand implements Command
Arena arena = am.getSelectedArena();
World aw = arena.getWorld();
World pw = p.getLocation().getWorld();
- boolean changeWorld = !arg1.equals("exit") && !aw.getName().equals(pw.getName());
+ boolean changeWorld = !args[0].equals("exit") && !aw.getName().equals(pw.getName());
// Change worlds to make sure the region check doesn't fail
if (changeWorld) arena.setWorld(pw);
// Make sure the arena warp is inside the region
- if (arg1.equals("arena") && !arena.getRegion().contains(p.getLocation())) {
+ if (args[0].equals("arena") && !arena.getRegion().contains(p.getLocation())) {
if (arena.getRegion().isDefined()) {
Messenger.tell(sender, "You must be inside the arena region!");
} else {
@@ -65,7 +61,7 @@ public class SetWarpCommand implements Command
if (changeWorld) arena.setWorld(aw);
} else {
// Set the region point
- arena.getRegion().set(arg1, p.getLocation());
+ arena.getRegion().set(args[0], p.getLocation());
// Notify the player if world changed
if (changeWorld) {
@@ -74,7 +70,7 @@ public class SetWarpCommand implements Command
}
// Then notify about point set
- Messenger.tell(sender, "Warp point '" + arg1 + "' was set for arena '" + am.getSelectedArena().configName() + "'");
+ Messenger.tell(sender, "Warp point '" + args[0] + "' was set for arena '" + am.getSelectedArena().configName() + "'");
arena.getRegion().checkData(am.getPlugin(), sender, true, false, true, false);
}
return true;
diff --git a/src/com/garbagemule/MobArena/commands/setup/ShowLobbyRegionCommand.java b/src/com/garbagemule/MobArena/commands/setup/ShowLobbyRegionCommand.java
index 8eecc2a..a7d69f2 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ShowLobbyRegionCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ShowLobbyRegionCommand.java
@@ -12,7 +12,7 @@ import org.bukkit.entity.Player;
@CommandInfo(
name = "showlobbyregion",
- pattern = "showlobbyregion",
+ pattern = "showlobby(region)?",
usage = "/ma showlobbyregion ()",
desc = "show a lobby region",
permission = "mobarena.setup.showlobbyregion"
@@ -23,7 +23,7 @@ public class ShowLobbyRegionCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
// Grab the argument, if any.
@@ -33,25 +33,22 @@ public class ShowLobbyRegionCommand implements Command
Player p = (Player) sender;
Arena arena;
-
if (arg1.equals("")) {
arena = am.getArenaAtLocation(p.getLocation());
if (arena == null) {
arena = am.getSelectedArena();
}
- }
- else {
+ } else {
arena = am.getArenaWithName(arg1);
-
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
}
if (!arena.getRegion().isLobbyDefined()) {
Messenger.tell(sender, "The lobby region is not defined for the selected arena.");
- return false;
+ return true;
}
// Show an error message if we aren't in the right world
@@ -59,11 +56,9 @@ public class ShowLobbyRegionCommand implements Command
Messenger.tell(sender, "Arena '" + arena.configName() +
"' is in world '" + arena.getWorld().getName() +
"' and you are in world '" + p.getWorld().getName() + "'");
- return false;
+ return true;
}
-
arena.getRegion().showLobbyRegion(p);
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/ShowRegionCommand.java b/src/com/garbagemule/MobArena/commands/setup/ShowRegionCommand.java
index c276505..7c4ffb0 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ShowRegionCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ShowRegionCommand.java
@@ -10,7 +10,7 @@ import com.garbagemule.MobArena.framework.ArenaMaster;
@CommandInfo(
name = "showregion",
- pattern = "showregion",
+ pattern = "show(region|arena)",
usage = "/ma showregion ()",
desc = "show an arena region",
permission = "mobarena.setup.showregion"
@@ -21,7 +21,7 @@ public class ShowRegionCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
// Grab the argument, if any.
@@ -31,25 +31,22 @@ public class ShowRegionCommand implements Command
Player p = (Player) sender;
Arena arena;
-
if (arg1.equals("")) {
arena = am.getArenaAtLocation(p.getLocation());
if (arena == null) {
arena = am.getSelectedArena();
}
- }
- else {
+ } else {
arena = am.getArenaWithName(arg1);
-
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
}
if (!arena.getRegion().isDefined()) {
Messenger.tell(sender, "The region is not defined for the selected arena.");
- return false;
+ return true;
}
// Show an error message if we aren't in the right world
@@ -57,11 +54,9 @@ public class ShowRegionCommand implements Command
Messenger.tell(sender, "Arena '" + arena.configName() +
"' is in world '" + arena.getWorld().getName() +
"' and you are in world '" + p.getWorld().getName() + "'");
- return false;
+ return true;
}
-
arena.getRegion().showRegion(p);
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/ShowSpawnsCommand.java b/src/com/garbagemule/MobArena/commands/setup/ShowSpawnsCommand.java
index 439f49b..0660ed0 100644
--- a/src/com/garbagemule/MobArena/commands/setup/ShowSpawnsCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/ShowSpawnsCommand.java
@@ -23,7 +23,7 @@ public class ShowSpawnsCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
// Grab the argument, if any.
@@ -33,7 +33,6 @@ public class ShowSpawnsCommand implements Command
Player p = (Player) sender;
Arena arena;
-
if (arg1.equals("")) {
arena = am.getArenaAtLocation(p.getLocation());
if (arena == null) {
@@ -42,20 +41,16 @@ public class ShowSpawnsCommand implements Command
if (arena.getRegion().getSpawnpoints().isEmpty()) {
Messenger.tell(sender, "There are no spawnpoints in the selected arena.");
- return false;
+ return true;
}
- }
- else {
+ } else {
arena = am.getArenaWithName(arg1);
-
if (arena == null) {
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
- return false;
+ return true;
}
}
-
arena.getRegion().showSpawns(p);
-
return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/setup/SpawnpointsCommand.java b/src/com/garbagemule/MobArena/commands/setup/SpawnpointsCommand.java
index 61b7f1b..e58709b 100644
--- a/src/com/garbagemule/MobArena/commands/setup/SpawnpointsCommand.java
+++ b/src/com/garbagemule/MobArena/commands/setup/SpawnpointsCommand.java
@@ -27,11 +27,9 @@ public class SpawnpointsCommand implements Command
buffy.append(s);
buffy.append(" ");
}
- }
- else {
+ } else {
buffy.append(Msg.MISC_NONE);
}
-
Messenger.tell(sender, "Spawnpoints for arena '" + am.getSelectedArena().configName() + "': " + buffy.toString());
return true;
}
diff --git a/src/com/garbagemule/MobArena/commands/user/JoinCommand.java b/src/com/garbagemule/MobArena/commands/user/JoinCommand.java
index 4f933f6..f7b83a2 100644
--- a/src/com/garbagemule/MobArena/commands/user/JoinCommand.java
+++ b/src/com/garbagemule/MobArena/commands/user/JoinCommand.java
@@ -21,7 +21,7 @@ public class JoinCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
// Cast the sender, grab the argument, if any.
@@ -30,20 +30,20 @@ public class JoinCommand implements Command
// Run some rough sanity checks, and grab the arena to join.
Arena toArena = Commands.getArenaToJoinOrSpec(am, p, arg1);
- Arena fromArena = am.getArenaWithPlayer(p);
if (toArena == null) {
- return false;
+ return true;
}
// Deny joining from other arenas
+ Arena fromArena = am.getArenaWithPlayer(p);
if (fromArena != null && (fromArena.inArena(p) || fromArena.inLobby(p))) {
Messenger.tell(p, Msg.JOIN_ALREADY_PLAYING);
- return false;
+ return true;
}
// Per-arena sanity checks
if (!toArena.canJoin(p)) {
- return false;
+ return true;
}
// Force leave previous arena
diff --git a/src/com/garbagemule/MobArena/commands/user/LeaveCommand.java b/src/com/garbagemule/MobArena/commands/user/LeaveCommand.java
index 85639ee..c89673b 100644
--- a/src/com/garbagemule/MobArena/commands/user/LeaveCommand.java
+++ b/src/com/garbagemule/MobArena/commands/user/LeaveCommand.java
@@ -21,7 +21,7 @@ public class LeaveCommand implements Command
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
if (!Commands.isPlayer(sender)) {
Messenger.tell(sender, Msg.MISC_NOT_FROM_CONSOLE);
- return false;
+ return true;
}
// Cast the sender.
@@ -32,7 +32,7 @@ public class LeaveCommand implements Command
arena = am.getArenaWithSpectator(p);
if (arena == null) {
Messenger.tell(p, Msg.LEAVE_NOT_PLAYING);
- return false;
+ return true;
}
}
diff --git a/src/com/garbagemule/MobArena/commands/user/NotReadyCommand.java b/src/com/garbagemule/MobArena/commands/user/NotReadyCommand.java
index 0953c06..e9e8875 100644
--- a/src/com/garbagemule/MobArena/commands/user/NotReadyCommand.java
+++ b/src/com/garbagemule/MobArena/commands/user/NotReadyCommand.java
@@ -31,18 +31,15 @@ public class NotReadyCommand implements Command
Messenger.tell(sender, Msg.ARENA_DOES_NOT_EXIST);
return false;
}
- }
- else if (Commands.isPlayer(sender)) {
+ } else if (Commands.isPlayer(sender)) {
Player p = (Player) sender;
arena = am.getArenaWithPlayer(p);
if (arena == null) {
Messenger.tell(sender, Msg.LEAVE_NOT_PLAYING);
- return false;
+ return true;
}
- }
- else {
- Messenger.tell(sender, "Usage: /ma notready ");
+ } else {
return false;
}
diff --git a/src/com/garbagemule/MobArena/commands/user/PlayerListCommand.java b/src/com/garbagemule/MobArena/commands/user/PlayerListCommand.java
index 2af4c27..e476e39 100644
--- a/src/com/garbagemule/MobArena/commands/user/PlayerListCommand.java
+++ b/src/com/garbagemule/MobArena/commands/user/PlayerListCommand.java
@@ -35,9 +35,8 @@ public class PlayerListCommand implements Command
}
list = MAUtils.listToString(arena.getPlayersInArena(), am.getPlugin());
- }
- else {
- StringBuffer buffy = new StringBuffer();
+ } else {
+ StringBuilder buffy = new StringBuilder();
List players = new LinkedList();
for (Arena arena : am.getArenas()) {
diff --git a/src/com/garbagemule/MobArena/commands/user/SpecCommand.java b/src/com/garbagemule/MobArena/commands/user/SpecCommand.java
index 2fd9df0..fabedd6 100644
--- a/src/com/garbagemule/MobArena/commands/user/SpecCommand.java
+++ b/src/com/garbagemule/MobArena/commands/user/SpecCommand.java
@@ -30,20 +30,20 @@ public class SpecCommand implements Command
// Run some rough sanity checks, and grab the arena to spec.
Arena toArena = Commands.getArenaToJoinOrSpec(am, p, arg1);
- Arena fromArena = am.getArenaWithPlayer(p);
if (toArena == null) {
- return false;
+ return true;
}
// Deny spectating from other arenas
+ Arena fromArena = am.getArenaWithPlayer(p);
if (fromArena != null && (fromArena.inArena(p) || fromArena.inLobby(p))) {
Messenger.tell(p, Msg.SPEC_ALREADY_PLAYING);
- return false;
+ return true;
}
// Per-arena sanity checks
if (!toArena.canSpec(p)) {
- return false;
+ return true;
}
// Force leave previous arena