Added alias support
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
command home {
|
command home {
|
||||||
|
alias h;
|
||||||
|
alias bleh;
|
||||||
set [string:name] {
|
set [string:name] {
|
||||||
[int:x] [int:y] [int:z] {
|
[int:x] [int:y] [int:z] {
|
||||||
run home_set_coords name x y z;
|
run home_set_coords name x y z;
|
||||||
@@ -32,4 +33,4 @@ command home {
|
|||||||
help Reks you;
|
help Reks you;
|
||||||
run noskope;
|
run noskope;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,8 @@ public class CommandManager {
|
|||||||
boolean insideType = false;
|
boolean insideType = false;
|
||||||
/* if we are currently gathering chars from the command name */
|
/* if we are currently gathering chars from the command name */
|
||||||
boolean gettingName = false;
|
boolean gettingName = false;
|
||||||
|
/* if we are currently gathering chars for aliases */
|
||||||
|
boolean gettingAlias = false;
|
||||||
/* the previous char, used for backslash escaping */
|
/* the previous char, used for backslash escaping */
|
||||||
char previous = '\0';
|
char previous = '\0';
|
||||||
/* the current 'array' of sub-commands we are parsing */
|
/* the current 'array' of sub-commands we are parsing */
|
||||||
@@ -246,7 +248,7 @@ public class CommandManager {
|
|||||||
int line = 0;
|
int line = 0;
|
||||||
// buffer for '...' and '"' properties of string types
|
// buffer for '...' and '"' properties of string types
|
||||||
StringBuilder sideBuffer = new StringBuilder();
|
StringBuilder sideBuffer = new StringBuilder();
|
||||||
|
|
||||||
/* iterate over all characters */
|
/* iterate over all characters */
|
||||||
for (int i = 0; i < chars.length; i++) {
|
for (int i = 0; i < chars.length; i++) {
|
||||||
/* get current char */
|
/* get current char */
|
||||||
@@ -288,7 +290,7 @@ public class CommandManager {
|
|||||||
/* help this is an example; */
|
/* help this is an example; */
|
||||||
/* ^ */
|
/* ^ */
|
||||||
}else if (current == ';') {
|
}else if (current == ';') {
|
||||||
/* semicolon is bashslash escaped, treat it as a normal character */
|
/* semicolon is backslash escaped, treat it as a normal character */
|
||||||
if (previous == '\\') {
|
if (previous == '\\') {
|
||||||
buffer.append(';');
|
buffer.append(';');
|
||||||
}else{
|
}else{
|
||||||
@@ -299,7 +301,10 @@ public class CommandManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* we are defining the 'help' property, set it to what we just gathered */
|
/* we are defining the 'help' property, set it to what we just gathered */
|
||||||
if (currentProp == Property.HELP) {
|
if (gettingAlias) {
|
||||||
|
stack.get().aliases.add(buffer.toString());
|
||||||
|
gettingAlias = false;
|
||||||
|
}else if (currentProp == Property.HELP) {
|
||||||
stack.get().help = buffer.toString();
|
stack.get().help = buffer.toString();
|
||||||
/* same as above, except its the function to run */
|
/* same as above, except its the function to run */
|
||||||
}else if (currentProp == Property.EXECUTE) {
|
}else if (currentProp == Property.EXECUTE) {
|
||||||
@@ -412,6 +417,8 @@ public class CommandManager {
|
|||||||
if (buffer.toString().equals("command") && !gettingName && cmdName == null) {
|
if (buffer.toString().equals("command") && !gettingName && cmdName == null) {
|
||||||
gettingName = true;
|
gettingName = true;
|
||||||
/* we got other properties, their values will follow */
|
/* we got other properties, their values will follow */
|
||||||
|
}else if (buffer.toString().equals("alias") && !gettingAlias) {
|
||||||
|
gettingAlias = true;
|
||||||
}else if (buffer.toString().equals("help")) {
|
}else if (buffer.toString().equals("help")) {
|
||||||
currentProp = Property.HELP;
|
currentProp = Property.HELP;
|
||||||
}else if (buffer.toString().equals("run")) {
|
}else if (buffer.toString().equals("run")) {
|
||||||
@@ -596,7 +603,7 @@ public class CommandManager {
|
|||||||
components.permission = null;
|
components.permission = null;
|
||||||
components.type = null;
|
components.type = null;
|
||||||
Executable cmd = new Executable(cmdName, constructHelpPages(cmdName, components));
|
Executable cmd = new Executable(cmdName, constructHelpPages(cmdName, components));
|
||||||
cmd.register(methods, plugin, methodContainer);
|
cmd.register(methods, plugin, methodContainer, components.getAliases());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArrayList<HelpPageCommand[]> constructHelpPages(String cmdName, ChainComponent root) {
|
private static ArrayList<HelpPageCommand[]> constructHelpPages(String cmdName, ChainComponent root) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class ChainComponent implements ICommandComponent {
|
|||||||
public String help;
|
public String help;
|
||||||
public String execute;
|
public String execute;
|
||||||
public Type type;
|
public Type type;
|
||||||
|
public ArrayList<String> aliases = new ArrayList<String>();
|
||||||
|
|
||||||
public ChainComponent() {
|
public ChainComponent() {
|
||||||
components = new ArrayList<ICommandComponent>();
|
components = new ArrayList<ICommandComponent>();
|
||||||
@@ -47,4 +48,8 @@ public class ChainComponent implements ICommandComponent {
|
|||||||
public ArrayList<ICommandComponent> getComponents() {
|
public ArrayList<ICommandComponent> getComponents() {
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class Executable extends org.bukkit.command.Command {
|
|||||||
this.commands = new ArrayList<ExecutableDefinition>();
|
this.commands = new ArrayList<ExecutableDefinition>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer) {
|
public void register(ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer, ArrayList<String> aliases) {
|
||||||
for (HelpPageCommand[] page : help) {
|
for (HelpPageCommand[] page : help) {
|
||||||
for (HelpPageCommand cmd : page) {
|
for (HelpPageCommand cmd : page) {
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
@@ -95,6 +95,13 @@ public class Executable extends org.bukkit.command.Command {
|
|||||||
Map<String, Command> knownCommands = (Map<String, Command>) knownCommandsField.get(map);
|
Map<String, Command> knownCommands = (Map<String, Command>) knownCommandsField.get(map);
|
||||||
knownCommands.remove(name);
|
knownCommands.remove(name);
|
||||||
map.register(name, this);
|
map.register(name, this);
|
||||||
|
for (String alias : aliases) {
|
||||||
|
Executable cmd = new Executable(alias, this.help);
|
||||||
|
cmd.commands = this.commands;
|
||||||
|
cmd.plugin = this.plugin;
|
||||||
|
knownCommands.remove(alias);
|
||||||
|
map.register(alias, cmd);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "Failed to register command '" + name + "'!");
|
plugin.getLogger().log(Level.SEVERE, "Failed to register command '" + name + "'!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: CommandManagerTest
|
name: CommandManagerTest
|
||||||
main: CmdMgrTest
|
main: com.nemez.cmdMgrExample.CmdMgrExample
|
||||||
version: 13.37
|
version: 13.37
|
||||||
author: Nemes
|
author: Nemes
|
||||||
|
|||||||
Reference in New Issue
Block a user