0
This commit is contained in:
NEMESIS13cz
2016-08-18 20:44:50 +02:00
parent 36c54e159f
commit 49016a10ae
3 changed files with 42 additions and 7 deletions

View File

@@ -85,7 +85,7 @@ import com.nemez.cmdmgr.util.Type;
public class CommandManager { public class CommandManager {
public static boolean debugOutput = false; public static boolean debugHelpMenu = false;
public static boolean errors = false; public static boolean errors = false;
public static String helpDescriptionFormatting = "<EFBFBD>b"; public static String helpDescriptionFormatting = "<EFBFBD>b";
@@ -244,6 +244,16 @@ public class CommandManager {
errors = true; errors = true;
return false; 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) { if (bracketCounter == 0) {
postProcess(cmdName, popped, methods, plugin, methodContainer); // \o/ postProcess(cmdName, popped, methods, plugin, methodContainer); // \o/
buffer = new StringBuilder(); buffer = new StringBuilder();
@@ -305,7 +315,7 @@ public class CommandManager {
insideType = false; insideType = false;
if (currentArgComp == null) { if (currentArgComp == null) {
// this should never happen though, it should error out at the top when the type is "" // 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; errors = true;
return false; return false;
}else{ }else{
@@ -391,6 +401,10 @@ public class CommandManager {
} }
private static void postProcess(String cmdName, ChainComponent components, ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer) { 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)); Executable cmd = new Executable(cmdName, constructHelpPages(cmdName, components));
cmd.register(methods, plugin, methodContainer); cmd.register(methods, plugin, methodContainer);
} }
@@ -445,7 +459,7 @@ public class CommandManager {
chain += temp; 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) { for (String s : leaves) {
data += s; data += s;
} }

View File

@@ -44,6 +44,22 @@ public class Executable extends org.bukkit.command.Command {
for (HelpPageCommand cmd : page) { for (HelpPageCommand cmd : page) {
if (cmd != null) { if (cmd != null) {
processLine(cmd.usage.split("\\ "), cmd.permission, cmd.method, methods, methodContainer, plugin, cmd.type); 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])) { if (annotations[0].hook().equals(methodArray[0])) {
Class<?>[] params = m.getParameterTypes(); Class<?>[] params = m.getParameterTypes();
if (params.length -1 != methodParams.size()) { 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; return;
}else{ }else{
for (int i = 0; i < params.length; i++) { 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); HelpPageCommand[] pageData = help.get(page);
sender.sendMessage(CommandManager.helpPageHeaderFormatting + "### Help Page " + (page + 1) + "/" + (help.size()) + " ###"); sender.sendMessage(CommandManager.helpPageHeaderFormatting + "### Help Page " + (page + 1) + "/" + (help.size()) + " ###");
for (HelpPageCommand c : pageData) { for (HelpPageCommand c : pageData) {
if (c != null && (c.permission == null || sender.hasPermission(c.permission))) { if (c != null) {
sender.sendMessage(CommandManager.helpUsageFormatting + c.usage); if (c.type == null || c.type == Type.BOTH || (c.type == Type.CONSOLE && !(sender instanceof Player)) || (c.type == Type.PLAYER && sender instanceof Player)) {
sender.sendMessage(CommandManager.helpDescriptionFormatting + c.description); if (c.permission == null || sender.hasPermission(c.permission)) {
sender.sendMessage(CommandManager.helpUsageFormatting + c.usage);
sender.sendMessage(CommandManager.helpDescriptionFormatting + c.description);
}
}
} }
} }
} }

View File

@@ -10,6 +10,7 @@ command home {
run home_set name; run home_set name;
perm home.set; perm home.set;
help Sets a new home; help Sets a new home;
type none;
} }
del [string:name] { del [string:name] {
run home_del name; run home_del name;