Added flags and fixed cmd->java parameter ordering
This commit is contained in:
@@ -7,8 +7,10 @@ import java.util.logging.Level;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.nemez.cmdmgr.CommandManager;
|
||||
import com.nemez.cmdmgr.component.ArgumentComponent;
|
||||
import com.nemez.cmdmgr.component.ICommandComponent;
|
||||
import com.nemez.cmdmgr.component.OptionalComponent;
|
||||
|
||||
public class ExecutableDefinition {
|
||||
|
||||
@@ -17,13 +19,15 @@ public class ExecutableDefinition {
|
||||
private Method target;
|
||||
private Object methodContainer;
|
||||
private Type type;
|
||||
private ArrayList<Integer> paramLinks;
|
||||
|
||||
public ExecutableDefinition(ArrayList<ICommandComponent> cmd, String perm, Method method, Object methodContainer, Type type) {
|
||||
public ExecutableDefinition(ArrayList<ICommandComponent> cmd, ArrayList<Integer> paramLinks, String perm, Method method, Object methodContainer, Type type) {
|
||||
this.components = cmd;
|
||||
this.permission = perm;
|
||||
this.target = method;
|
||||
this.methodContainer = methodContainer;
|
||||
this.type = type;
|
||||
this.paramLinks = paramLinks;
|
||||
}
|
||||
|
||||
public boolean valid(int index, String arg) {
|
||||
@@ -47,6 +51,13 @@ public class ExecutableDefinition {
|
||||
return components.get(index) instanceof ArgumentComponent;
|
||||
}
|
||||
|
||||
public boolean isOptional(int index) {
|
||||
if (index < 0 || index >= components.size()) {
|
||||
return false;
|
||||
}
|
||||
return components.get(index) instanceof OptionalComponent;
|
||||
}
|
||||
|
||||
public boolean isHelp() {
|
||||
return target == null && components.get(0).valid("help") && components.get(1).getComponentInfo().equals("<page:i32>");
|
||||
}
|
||||
@@ -63,23 +74,27 @@ public class ExecutableDefinition {
|
||||
return components.size();
|
||||
}
|
||||
|
||||
public boolean invoke(ArrayList<Object> args, CommandSender sender, JavaPlugin plugin) {
|
||||
public int getLink(int i) {
|
||||
if (i < 0 || i > paramLinks.size()) {
|
||||
return i;
|
||||
}
|
||||
return paramLinks.get(i);
|
||||
}
|
||||
|
||||
public boolean invoke(Object[] args, CommandSender sender, JavaPlugin plugin) {
|
||||
if (target == null) {
|
||||
return false;
|
||||
}
|
||||
Object[] arguments = new Object[args.size() + 1];
|
||||
for (int i = 1; i < arguments.length; i++) {
|
||||
arguments[i] = args.get(i - 1);
|
||||
}
|
||||
arguments[0] = sender;
|
||||
args[0] = sender;
|
||||
try {
|
||||
if (target.getReturnType() == void.class) {
|
||||
target.invoke(methodContainer, arguments);
|
||||
target.invoke(methodContainer, args);
|
||||
return true;
|
||||
}else if (target.getReturnType() == boolean.class) {
|
||||
return (boolean) target.invoke(methodContainer, arguments);
|
||||
return (boolean) target.invoke(methodContainer, args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(CommandManager.helpInvalidPageFormatting + "An internal error occured, please contact the server administrator and/or report a bug.");
|
||||
plugin.getLogger().log(Level.WARNING, "Runtime Error: invalid method");
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user