Permalink
Browse files

Changed /gc to globalchat

More refactoring progress
  • Loading branch information...
1 parent 289c173 commit 141d080ffa608daa85eb2047bfd545490a451225 @GuntherDW committed Dec 30, 2011
View
@@ -206,7 +206,10 @@ commands:
groupchat:
description: GroupChat control
usage: /<command>
- aliases: [ 'gc' ]
+# aliases: [ 'gc' ]
+ gc:
+ description: Remove ChatMode subscription
+ usage: /<command>
eject:
description: Eject your freeloader!
usage: /<command>
@@ -26,7 +26,9 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
import java.util.logging.Logger;
/**
@@ -37,18 +39,18 @@
private Map<String, iCommand> commandMap = new HashMap<String, iCommand>();
private Map<String, Method> newCommandMap = new HashMap<String, Method>();
private Map<Method, Object> instanceMap = new HashMap<Method, Object>();
- private AdminCommands adminCommands = new AdminCommands();
- private ChatCommands chatcommands = new ChatCommands();
- private DebugCommands debugCommands = new DebugCommands();
- private EssentialsCommands essentialsCommands = new EssentialsCommands();
- private GeneralCommands generalCommands = new GeneralCommands();
- private TeleportationCommands teleportationCommands = new TeleportationCommands();
- private WeatherCommands weatherCommands = new WeatherCommands();
+ /*private AdminCommands adminCommands;
+ private ChatCommands chatcommands;
+ private DebugCommands debugCommands;
+ private EssentialsCommands essentialsCommands;
+ private GeneralCommands generalCommands;
+ private TeleportationCommands teleportationCommands;
+ private WeatherCommands weatherCommands;*/
private Logger logger = Logger.getLogger("Minecraft");
private TweakcraftUtils plugin;
private Object getMethodInstance(Method method) {
- if(instanceMap.containsKey(method))
+ if (instanceMap.containsKey(method))
return instanceMap.get(method);
return null;
@@ -59,18 +61,18 @@ public CommandHandler(TweakcraftUtils instance) {
commandMap.clear();
newCommandMap.clear();
- addCommandClass(adminCommands);
- addCommandClass(chatcommands);
- addCommandClass(debugCommands);
- addCommandClass(essentialsCommands);
- addCommandClass(generalCommands);
- addCommandClass(teleportationCommands);
- addCommandClass(weatherCommands);
+ addCommandClass(new AdminCommands());
+ addCommandClass(new ChatCommands());
+ addCommandClass(new DebugCommands());
+ addCommandClass(new EssentialsCommands());
+ addCommandClass(new GeneralCommands());
+ addCommandClass(new TeleportationCommands());
+ addCommandClass(new WeatherCommands());
}
private void addCommandClass(Object instance) {
- for(Method m : instance.getClass().getDeclaredMethods()) {
- if(m.getAnnotation(aCommand.class)!=null)
+ for (Method m : instance.getClass().getDeclaredMethods()) {
+ if (m.getAnnotation(aCommand.class) != null)
injectCommand(m, instance);
}
}
@@ -79,12 +81,12 @@ private void addCommandClass(Object instance) {
private void injectCommand(Method method, Object instance) {
aCommand annotation = method.getAnnotation(aCommand.class);
String[] aliases = annotation.aliases();
- if(aliases.length>0) {
- if(newCommandMap.containsKey(aliases[0])) {
+ if (aliases.length > 0) {
+ if (newCommandMap.containsKey(aliases[0])) {
logger.warning("[TweakcraftUtils] Duplicate command found!");
- logger.warning("[TweakcraftUtils] Method : "+method.getName()+"!");
- logger.warning("[TweakcraftUtils] Command : "+aliases[0]+"!");
- return ;
+ logger.warning("[TweakcraftUtils] Method : " + method.getName() + "!");
+ logger.warning("[TweakcraftUtils] Command : " + aliases[0] + "!");
+ return;
}
newCommandMap.put(aliases[0], method);
instanceMap.put(method, instance);
@@ -93,13 +95,13 @@ private void injectCommand(Method method, Object instance) {
@SuppressWarnings("unchecked")
public void checkCommands() {
- if(plugin.getConfigHandler().enableDebug) { /* Show commands with no command attached */
+ if (plugin.getConfigHandler().enableDebug) { /* Show commands with no command attached */
PluginDescriptionFile pdFile = plugin.getDescription();
Map<String, Object> pluginCommands = (Map<String, Object>) pdFile.getCommands();
Set<String> cmds = pluginCommands.keySet();
- for(String c : cmds) {
- if(!this.newCommandMap.containsKey(c))
- logger.warning("[TweakcraftUtils] WARNING: Unmapped command : "+c);
+ for (String c : cmds) {
+ if (!this.newCommandMap.containsKey(c))
+ logger.warning("[TweakcraftUtils] WARNING: Unmapped command : " + c);
}
}
}
@@ -124,17 +126,17 @@ public boolean executeCommand(CommandSender sender, String name, String[] args,
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
Method command = newCommandMap.get(name);
- try{
+ try {
return (Boolean) command.invoke(getMethodInstance(command), sender, name, args, tweakcraftUtils);
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
- if(t instanceof PermissionsException)
+ if (t instanceof PermissionsException)
throw (PermissionsException) t;
- if(t instanceof CommandSenderException)
+ if (t instanceof CommandSenderException)
throw (CommandSenderException) t;
- if(t instanceof CommandUsageException)
+ if (t instanceof CommandUsageException)
throw (CommandUsageException) t;
- if(t instanceof CommandException)
+ if (t instanceof CommandException)
throw (CommandException) t;
logger.warning("[TweakcraftUtils] Error occured while executing command!");
@@ -52,6 +52,92 @@ public boolean chatmode(CommandSender sender, String command, String[] args, Twe
return this.chatCommand(sender, command, null, args, plugin);
}
+ @aCommand(
+ aliases = {"gc"},
+ permissionBase = "chat.mode.global",
+ description = "Remove ChatMode subscription",
+ section = "chat"
+ )
+ public boolean globalChat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
+ throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
+
+ this.chatCommand(sender, command, "global", args, plugin);
+
+ return true;
+ }
+
+ @aCommand(
+ aliases = {"lc"},
+ permissionBase = "chat.mode.local",
+ description = "Toggle local chat",
+ section = "chat"
+ )
+ public boolean localChat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
+ throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
+
+ if (!plugin.getConfigHandler().enableLocalChat) {
+ throw new CommandUsageException("LocalChat not enabled!");
+ }
+
+ this.chatCommand(sender, command, "local", args, plugin);
+
+ return true;
+ }
+
+ @aCommand(
+ aliases = {"rc"},
+ permissionBase = "chat.mode.region",
+ description = "Toggle region chat",
+ section = "chat"
+ )
+ public boolean regionChat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
+ throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
+
+ if (!plugin.getConfigHandler().enableWorldGuard) {
+ throw new CommandUsageException("WorldGuard not enabled!");
+ }
+
+ this.chatCommand(sender, command, "region", args, plugin);
+
+ return true;
+ }
+
+ @aCommand(
+ aliases = {"wc"},
+ permissionBase = "chat.mode.world",
+ description = "Toggle world chat",
+ section = "chat"
+ )
+ public boolean worldChat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
+ throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
+
+ if (!plugin.getConfigHandler().enableWorldChat) {
+ throw new CommandUsageException("WorldChat not enabled!");
+ }
+
+ this.chatCommand(sender, command, "world", args, plugin);
+
+ return true;
+ }
+
+
+ @aCommand(
+ aliases = {"zc"},
+ permissionBase = "chat.mode.zone",
+ description = "Toggle Zone chat",
+ section = "chat"
+ )
+ public boolean zoneChat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
+ throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
+ if (plugin.getConfigHandler().enableZones == false) {
+ throw new CommandUsageException("Zones not enabled!");
+ }
+
+ this.chatCommand(sender, command, "zones", args, plugin);
+
+ return true;
+ }
+
public boolean chatCommand(CommandSender sender, String command, String chatModeName, String[] realargs, TweakcraftUtils plugin)
throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
@@ -71,7 +157,7 @@ public boolean chatCommand(CommandSender sender, String command, String chatMode
} else {
chatMode = realargs[0].toLowerCase();
}
- args = Arrays.asList(realargs);
+ args.addAll(Arrays.asList(realargs));
String msg = "";
if (args.size() == 1) {
@@ -206,75 +292,5 @@ public boolean chatCommand(CommandSender sender, String command, String chatMode
return true;
}
- @aCommand(
- aliases = {"lc"},
- permissionBase = "chat.mode.local",
- description = "Toggle local chat",
- section = "chat"
- )
- public boolean localchat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
- throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
-
- if (!plugin.getConfigHandler().enableLocalChat) {
- throw new CommandUsageException("LocalChat not enabled!");
- }
-
- this.chatCommand(sender, command, "local", args, plugin);
-
- return true;
- }
-
- @aCommand(
- aliases = {"rc"},
- permissionBase = "chat.mode.region",
- description = "Toggle region chat",
- section = "chat"
- )
- public boolean regionchat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
- throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
-
- if (!plugin.getConfigHandler().enableWorldGuard) {
- throw new CommandUsageException("WorldGuard not enabled!");
- }
-
- this.chatCommand(sender, command, "region", args, plugin);
- return true;
- }
-
- @aCommand(
- aliases = {"wc"},
- permissionBase = "chat.mode.world",
- description = "Toggle world chat",
- section = "chat"
- )
- public boolean worldchat(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
- throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
-
- if (!plugin.getConfigHandler().enableWorldChat) {
- throw new CommandUsageException("WorldChat not enabled!");
- }
-
- this.chatCommand(sender, command, "world", args, plugin);
-
- return true;
- }
-
-
- @aCommand(
- aliases = {"zc"},
- permissionBase = "chat.mode.zone",
- description = "Toggle Zone chat",
- section = "chat"
- )
- public boolean executeCommand(CommandSender sender, String command, String[] args, TweakcraftUtils plugin)
- throws PermissionsException, CommandSenderException, CommandUsageException, CommandException {
- if (plugin.getConfigHandler().enableZones == false) {
- throw new CommandUsageException("Zones not enabled!");
- }
-
- this.chatCommand(sender, command, "zones", args, plugin);
-
- return true;
- }
}
Oops, something went wrong.

0 comments on commit 141d080

Please sign in to comment.