mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
Remove CommandIdentifier
This commit is contained in:
parent
39dd529e9c
commit
c0a272f431
@ -56,7 +56,7 @@ public class CommandManager {
|
|||||||
* their respective Method. The child map has the key of the command name
|
* their respective Method. The child map has the key of the command name
|
||||||
* (one for each alias) with the method.
|
* (one for each alias) with the method.
|
||||||
*/
|
*/
|
||||||
private final Map<CommandIdentifier, Method> commands = new HashMap<CommandIdentifier, Method>();
|
private final Map<String, Method> commands = new HashMap<String, Method>();
|
||||||
|
|
||||||
private final Map<String, List<Command>> subCommands = new HashMap<String, List<Command>>();
|
private final Map<String, List<Command>> subCommands = new HashMap<String, List<Command>>();
|
||||||
|
|
||||||
@ -96,9 +96,9 @@ public class CommandManager {
|
|||||||
String cmdName = args[0];
|
String cmdName = args[0];
|
||||||
String modifier = args.length >= 1 ? args[1] : "";
|
String modifier = args.length >= 1 ? args[1] : "";
|
||||||
|
|
||||||
Method method = commands.get(new CommandIdentifier(cmdName.toLowerCase(), modifier.toLowerCase()));
|
Method method = commands.get(cmdName.toLowerCase() + " " + modifier.toLowerCase());
|
||||||
if (method == null)
|
if (method == null)
|
||||||
method = commands.get(new CommandIdentifier(cmdName.toLowerCase(), "*"));
|
method = commands.get(cmdName.toLowerCase() + " *");
|
||||||
|
|
||||||
if (method != null && methodArgs != null && serverCommands.get(method) == null
|
if (method != null && methodArgs != null && serverCommands.get(method) == null
|
||||||
&& methodArgs[1] instanceof ConsoleCommandSender)
|
&& methodArgs[1] instanceof ConsoleCommandSender)
|
||||||
@ -155,9 +155,10 @@ public class CommandManager {
|
|||||||
|
|
||||||
public String[] getAllCommandModifiers(String command) {
|
public String[] getAllCommandModifiers(String command) {
|
||||||
Set<String> cmds = new HashSet<String>();
|
Set<String> cmds = new HashSet<String>();
|
||||||
for (CommandIdentifier identifier : commands.keySet()) {
|
for (String cmd : commands.keySet()) {
|
||||||
if (identifier.getCommand().equals(command)) {
|
String[] split = cmd.split(" ");
|
||||||
cmds.add(identifier.getModifier());
|
if (split[0].equalsIgnoreCase(command)) {
|
||||||
|
cmds.add(split[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,16 +184,16 @@ public class CommandManager {
|
|||||||
* This will check aliases as well.
|
* This will check aliases as well.
|
||||||
*/
|
*/
|
||||||
public boolean hasCommand(String command, String modifier) {
|
public boolean hasCommand(String command, String modifier) {
|
||||||
return commands.containsKey(new CommandIdentifier(command.toLowerCase(), modifier.toLowerCase()))
|
return commands.containsKey(command.toLowerCase() + " " + modifier.toLowerCase())
|
||||||
|| commands.containsKey(new CommandIdentifier(command.toLowerCase(), "*"));
|
|| commands.containsKey(command.toLowerCase() + " *");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Command> getCommands(String command) {
|
public List<Command> getCommands(String command) {
|
||||||
if (subCommands.containsKey(command))
|
if (subCommands.containsKey(command))
|
||||||
return subCommands.get(command);
|
return subCommands.get(command);
|
||||||
List<Command> cmds = new ArrayList<Command>();
|
List<Command> cmds = new ArrayList<Command>();
|
||||||
for (Entry<CommandIdentifier, Method> entry : commands.entrySet()) {
|
for (Entry<String, Method> entry : commands.entrySet()) {
|
||||||
if (!entry.getKey().getCommand().equalsIgnoreCase(command)
|
if (!entry.getKey().split(" ")[0].equalsIgnoreCase(command)
|
||||||
|| !entry.getValue().isAnnotationPresent(Command.class))
|
|| !entry.getValue().isAnnotationPresent(Command.class))
|
||||||
continue;
|
continue;
|
||||||
cmds.add(entry.getValue().getAnnotation(Command.class));
|
cmds.add(entry.getValue().getAnnotation(Command.class));
|
||||||
@ -247,9 +248,11 @@ public class CommandManager {
|
|||||||
String[] modifiers = cmd.modifiers();
|
String[] modifiers = cmd.modifiers();
|
||||||
|
|
||||||
// Cache the aliases too
|
// Cache the aliases too
|
||||||
for (String alias : cmd.aliases())
|
for (String alias : cmd.aliases()) {
|
||||||
for (String modifier : modifiers)
|
for (String modifier : modifiers) {
|
||||||
commands.put(new CommandIdentifier(alias, modifier), method);
|
commands.put(alias + " " + modifier, method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Requirements cmdRequirements = null;
|
Requirements cmdRequirements = null;
|
||||||
if (method.getDeclaringClass().isAnnotationPresent(Requirements.class))
|
if (method.getDeclaringClass().isAnnotationPresent(Requirements.class))
|
||||||
|
Loading…
Reference in New Issue
Block a user