Support for case insensitivity, NPE fix

This commit is contained in:
Ne0nx3r0 2013-07-29 15:29:08 -05:00
parent a5fb024fc7
commit 6c6ebafb90
5 changed files with 42 additions and 33 deletions

View File

@ -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 <username>"
0: "reply Usage: /makeOp <username>"
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:

View File

@ -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<Integer, List<AliasCommand>> 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<Integer,List<AliasCommand>>();
}
public Alias(String commandName,String permissionNode)
{
this.command = commandName;
this.permission = permissionNode;
this.parameters = new HashMap<Integer,List<AliasCommand>>();

View File

@ -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<AliasCommand> commandsList = new ArrayList<AliasCommand>();
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;
}
}
}

View File

@ -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");

View File

@ -1,6 +1,6 @@
name: BetterAlias
main: com.ne0nx3r0.betteralias.BetterAlias
version: '1.3'
version: '1.4'
database: false
description: Command alias system
commands: