summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNEMESIS13cz <OfficialNemes@gmail.com>2016-08-18 20:44:50 +0200
committerNEMESIS13cz <OfficialNemes@gmail.com>2016-08-18 20:44:50 +0200
commit49016a10ae7eb853b8cf1d43d5f3cba5b9f28849 (patch)
tree7d3aef62163d2dd1f23921474058e9a774be3796
parent36c54e159f1c1fcc1f54ae70e201eeeb9b167fa9 (diff)
magik
-rw-r--r--com/nemez/cmdmgr/CommandManager.java20
-rw-r--r--com/nemez/cmdmgr/util/Executable.java28
-rw-r--r--test.cmd1
3 files changed, 42 insertions, 7 deletions
diff --git a/com/nemez/cmdmgr/CommandManager.java b/com/nemez/cmdmgr/CommandManager.java
index 2c7b953..0f3e7b9 100644
--- a/com/nemez/cmdmgr/CommandManager.java
+++ b/com/nemez/cmdmgr/CommandManager.java
@@ -85,7 +85,7 @@ import com.nemez.cmdmgr.util.Type;
public class CommandManager {
- public static boolean debugOutput = false;
+ public static boolean debugHelpMenu = false;
public static boolean errors = false;
public static String helpDescriptionFormatting = "§b";
@@ -244,6 +244,16 @@ public class CommandManager {
errors = true;
return false;
}
+ for (ICommandComponent comp : popped.getComponents()) {
+ if (comp instanceof ChainComponent) {
+ if (((ChainComponent) comp).type == null) {
+ ((ChainComponent) comp).type = popped.type;
+ }
+ if (((ChainComponent) comp).permission == null) {
+ ((ChainComponent) comp).permission = popped.permission;
+ }
+ }
+ }
if (bracketCounter == 0) {
postProcess(cmdName, popped, methods, plugin, methodContainer); // \o/
buffer = new StringBuilder();
@@ -305,7 +315,7 @@ public class CommandManager {
insideType = false;
if (currentArgComp == null) {
// this should never happen though, it should error out at the top when the type is ""
- plugin.getLogger().log(Level.WARNING, "Type error at line " + line + ": Type has to type?");
+ plugin.getLogger().log(Level.WARNING, "Type error at line " + line + ": Type has no type?");
errors = true;
return false;
}else{
@@ -391,6 +401,10 @@ public class CommandManager {
}
private static void postProcess(String cmdName, ChainComponent components, ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer) {
+ components.execute = null;
+ components.help = null;
+ components.permission = null;
+ components.type = null;
Executable cmd = new Executable(cmdName, constructHelpPages(cmdName, components));
cmd.register(methods, plugin, methodContainer);
}
@@ -445,7 +459,7 @@ public class CommandManager {
chain += temp;
}
}
- data += chain + "\0" + comp.permission + "\0" + comp.execute + "\0" + comp.help + "\0" + Type.get(comp.type) + "\0";
+ data += chain + "\0" + ((comp.permission == null || comp.permission.equals("-none-")) ? null : comp.permission) + "\0" + comp.execute + "\0" + comp.help + "\0" + Type.get(comp.type) + "\0";
for (String s : leaves) {
data += s;
}
diff --git a/com/nemez/cmdmgr/util/Executable.java b/com/nemez/cmdmgr/util/Executable.java
index dc90114..d71e40e 100644
--- a/com/nemez/cmdmgr/util/Executable.java
+++ b/com/nemez/cmdmgr/util/Executable.java
@@ -44,6 +44,22 @@ public class Executable extends org.bukkit.command.Command {
for (HelpPageCommand cmd : page) {
if (cmd != null) {
processLine(cmd.usage.split("\\ "), cmd.permission, cmd.method, methods, methodContainer, plugin, cmd.type);
+ if (CommandManager.debugHelpMenu) {
+ continue;
+ }
+ String newUsage = "";
+ boolean ignore = false;
+ for (char c : cmd.usage.toCharArray()) {
+ if (c == ':' || c == '>') {
+ ignore = !ignore;
+ if (c == '>') {
+ newUsage += c;
+ }
+ }else if (!ignore) {
+ newUsage += c;
+ }
+ }
+ cmd.usage = newUsage;
}
}
}
@@ -169,7 +185,7 @@ public class Executable extends org.bukkit.command.Command {
if (annotations[0].hook().equals(methodArray[0])) {
Class<?>[] params = m.getParameterTypes();
if (params.length -1 != methodParams.size()) {
- System.err.println("error again! :D");
+ plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Arguments don't match");
return;
}else{
for (int i = 0; i < params.length; i++) {
@@ -292,9 +308,13 @@ public class Executable extends org.bukkit.command.Command {
HelpPageCommand[] pageData = help.get(page);
sender.sendMessage(CommandManager.helpPageHeaderFormatting + "### Help Page " + (page + 1) + "/" + (help.size()) + " ###");
for (HelpPageCommand c : pageData) {
- if (c != null && (c.permission == null || sender.hasPermission(c.permission))) {
- sender.sendMessage(CommandManager.helpUsageFormatting + c.usage);
- sender.sendMessage(CommandManager.helpDescriptionFormatting + c.description);
+ if (c != null) {
+ if (c.type == null || c.type == Type.BOTH || (c.type == Type.CONSOLE && !(sender instanceof Player)) || (c.type == Type.PLAYER && sender instanceof Player)) {
+ if (c.permission == null || sender.hasPermission(c.permission)) {
+ sender.sendMessage(CommandManager.helpUsageFormatting + c.usage);
+ sender.sendMessage(CommandManager.helpDescriptionFormatting + c.description);
+ }
+ }
}
}
}
diff --git a/test.cmd b/test.cmd
index 1b60081..7d3bc01 100644
--- a/test.cmd
+++ b/test.cmd
@@ -10,6 +10,7 @@ command home {
run home_set name;
perm home.set;
help Sets a new home;
+ type none;
}
del [string:name] {
run home_del name;