From 6c6ebafb9094040b71f85f65496cfc1e047ebefc Mon Sep 17 00:00:00 2001 From: Ne0nx3r0 Date: Mon, 29 Jul 2013 15:29:08 -0500 Subject: [PATCH] Support for case insensitivity, NPE fix --- aliases.yml | 8 ++--- com/ne0nx3r0/betteralias/alias/Alias.java | 21 +++++++----- .../betteralias/alias/AliasManager.java | 34 +++++++++++-------- .../listener/BetterAliasCommandListener.java | 10 +++--- plugin.yml | 2 +- 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/aliases.yml b/aliases.yml index dccdd5f..0e4b3f5 100644 --- a/aliases.yml +++ b/aliases.yml @@ -65,17 +65,17 @@ staff: # Console example # If this seems dangerous, that's because it is! # +makeOp: # Required permission will be betteralias.your.node -makeop: permission: your.node +# Must be makeOp, not Makeup, makeop, etc. + caseSensitive: true # Quotes are required because 0 uses a colon (:) - 0: "reply Usage: /makeop " + 0: "reply Usage: /makeOp " 1: - console /say !1 has been opped! - console /op !1 - /me has opped !1 - 2: console /say testing single line - 3: reply testing single line # Wait example wait: diff --git a/com/ne0nx3r0/betteralias/alias/Alias.java b/com/ne0nx3r0/betteralias/alias/Alias.java index f4229f7..5ac1a0f 100644 --- a/com/ne0nx3r0/betteralias/alias/Alias.java +++ b/com/ne0nx3r0/betteralias/alias/Alias.java @@ -6,20 +6,23 @@ import java.util.List; public class Alias { public final String command; + public final boolean caseSensitive; private final String permission; private final HashMap> parameters; - public Alias(String commandName) + public Alias(String commandName,boolean caseSensitive,String permissionNode) { - this.command = commandName; - this.permission = null; + this.caseSensitive = caseSensitive; + + if(this.caseSensitive) + { + this.command = commandName; + } + else + { + this.command = commandName.toLowerCase(); + } - this.parameters = new HashMap>(); - } - - public Alias(String commandName,String permissionNode) - { - this.command = commandName; this.permission = permissionNode; this.parameters = new HashMap>(); diff --git a/com/ne0nx3r0/betteralias/alias/AliasManager.java b/com/ne0nx3r0/betteralias/alias/AliasManager.java index 2c3f414..845b608 100644 --- a/com/ne0nx3r0/betteralias/alias/AliasManager.java +++ b/com/ne0nx3r0/betteralias/alias/AliasManager.java @@ -58,22 +58,16 @@ public class AliasManager for(String sAlias : aliasList) { - Alias alias; - - if(yml.getString(sAlias+".permission") != null) - { - alias = new Alias(sAlias,yml.getString(sAlias+".permission")); - } - else - { - alias = new Alias(sAlias); - } + Alias alias = new Alias( + sAlias, + yml.getBoolean(sAlias+".caseSensitive",false), + yml.getString(sAlias+".permission",null)); for(String sArg : yml.getConfigurationSection(sAlias).getKeys(false)) { List commandsList = new ArrayList(); - if(!sArg.equalsIgnoreCase("permission")) + if(!sArg.equalsIgnoreCase("permission") && !sArg.equalsIgnoreCase("caseSensitive")) { int iArg; @@ -411,11 +405,23 @@ public class AliasManager public Alias getAliasMatch(String sCommand) { - for(String sAlias : this.aliases.keySet()) + String sCommandLower = sCommand.toLowerCase(); + + for(Alias alias : this.aliases.values()) { - if(sCommand.startsWith(sAlias)) + if(alias.caseSensitive) { - return this.aliases.get(sAlias); + if(sCommand.startsWith(alias.command)) + { + return alias; + } + } + else// Case insensitive + { + if(sCommandLower.startsWith(alias.command)) + { + return alias; + } } } diff --git a/com/ne0nx3r0/betteralias/listener/BetterAliasCommandListener.java b/com/ne0nx3r0/betteralias/listener/BetterAliasCommandListener.java index 535a30c..a939912 100644 --- a/com/ne0nx3r0/betteralias/listener/BetterAliasCommandListener.java +++ b/com/ne0nx3r0/betteralias/listener/BetterAliasCommandListener.java @@ -27,10 +27,10 @@ public class BetterAliasCommandListener implements Listener Alias alias = plugin.aliasManager.getAliasMatch(sCommand); - String sArgs = sCommand.substring(alias.command.length()); - if(alias != null) - { + { + String sArgs = sCommand.substring(alias.command.length()); + Player player = e.getPlayer(); String sNode = "betteralias."+alias.getPermissionNode(); @@ -58,11 +58,11 @@ public class BetterAliasCommandListener implements Listener String sCommand = e.getCommand(); Alias alias = plugin.aliasManager.getAliasMatch(sCommand); - - String sArgs = sCommand.substring(alias.command.length()); if(alias != null) { + String sArgs = sCommand.substring(alias.command.length()); + if(plugin.aliasManager.sendAliasCommands(alias,e.getSender(),sArgs)) { e.setCommand("bareload donothing"); diff --git a/plugin.yml b/plugin.yml index 7dc41bf..bb14736 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: BetterAlias main: com.ne0nx3r0.betteralias.BetterAlias -version: '1.3' +version: '1.4' database: false description: Command alias system commands: