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 # Console example
# If this seems dangerous, that's because it is! # If this seems dangerous, that's because it is!
# #
makeOp:
# Required permission will be betteralias.your.node # Required permission will be betteralias.your.node
makeop:
permission: your.node permission: your.node
# Must be makeOp, not Makeup, makeop, etc.
caseSensitive: true
# Quotes are required because 0 uses a colon (:) # Quotes are required because 0 uses a colon (:)
0: "reply Usage: /makeop <username>" 0: "reply Usage: /makeOp <username>"
1: 1:
- console /say !1 has been opped! - console /say !1 has been opped!
- console /op !1 - console /op !1
- /me has opped !1 - /me has opped !1
2: console /say testing single line
3: reply testing single line
# Wait example # Wait example
wait: wait:

View File

@ -6,20 +6,23 @@ import java.util.List;
public class Alias public class Alias
{ {
public final String command; public final String command;
public final boolean caseSensitive;
private final String permission; private final String permission;
private final HashMap<Integer, List<AliasCommand>> parameters; private final HashMap<Integer, List<AliasCommand>> parameters;
public Alias(String commandName) public Alias(String commandName,boolean caseSensitive,String permissionNode)
{ {
this.command = commandName; this.caseSensitive = caseSensitive;
this.permission = null;
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.permission = permissionNode;
this.parameters = new HashMap<Integer,List<AliasCommand>>(); this.parameters = new HashMap<Integer,List<AliasCommand>>();

View File

@ -58,22 +58,16 @@ public class AliasManager
for(String sAlias : aliasList) for(String sAlias : aliasList)
{ {
Alias alias; Alias alias = new Alias(
sAlias,
if(yml.getString(sAlias+".permission") != null) yml.getBoolean(sAlias+".caseSensitive",false),
{ yml.getString(sAlias+".permission",null));
alias = new Alias(sAlias,yml.getString(sAlias+".permission"));
}
else
{
alias = new Alias(sAlias);
}
for(String sArg : yml.getConfigurationSection(sAlias).getKeys(false)) for(String sArg : yml.getConfigurationSection(sAlias).getKeys(false))
{ {
List<AliasCommand> commandsList = new ArrayList<AliasCommand>(); List<AliasCommand> commandsList = new ArrayList<AliasCommand>();
if(!sArg.equalsIgnoreCase("permission")) if(!sArg.equalsIgnoreCase("permission") && !sArg.equalsIgnoreCase("caseSensitive"))
{ {
int iArg; int iArg;
@ -411,11 +405,23 @@ public class AliasManager
public Alias getAliasMatch(String sCommand) 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); Alias alias = plugin.aliasManager.getAliasMatch(sCommand);
String sArgs = sCommand.substring(alias.command.length());
if(alias != null) if(alias != null)
{ {
String sArgs = sCommand.substring(alias.command.length());
Player player = e.getPlayer(); Player player = e.getPlayer();
String sNode = "betteralias."+alias.getPermissionNode(); String sNode = "betteralias."+alias.getPermissionNode();
@ -58,11 +58,11 @@ public class BetterAliasCommandListener implements Listener
String sCommand = e.getCommand(); String sCommand = e.getCommand();
Alias alias = plugin.aliasManager.getAliasMatch(sCommand); Alias alias = plugin.aliasManager.getAliasMatch(sCommand);
String sArgs = sCommand.substring(alias.command.length());
if(alias != null) if(alias != null)
{ {
String sArgs = sCommand.substring(alias.command.length());
if(plugin.aliasManager.sendAliasCommands(alias,e.getSender(),sArgs)) if(plugin.aliasManager.sendAliasCommands(alias,e.getSender(),sArgs))
{ {
e.setCommand("bareload donothing"); e.setCommand("bareload donothing");

View File

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