Added "multiword" strings
This commit is contained in:
@@ -52,7 +52,7 @@ public class CmdMgrTest extends JavaPlugin {
|
||||
|
||||
@Command(hook="noskope")
|
||||
public boolean executeMagik(CommandSender sender) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("You executed!!!!!!!!!:");
|
||||
sender.sendMessage("/home yolo swag");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -92,12 +92,12 @@ public class CommandManager {
|
||||
public static boolean errors = false;
|
||||
|
||||
/* Switches for color and formatting in the built-in help message and pagination text */
|
||||
public static String helpDescriptionFormatting = "<EFBFBD>b";
|
||||
public static String helpUsageFormatting = "<EFBFBD>6";
|
||||
public static String helpPageHeaderFormatting = "<EFBFBD>a";
|
||||
public static String helpInvalidPageFormatting = "<EFBFBD>c";
|
||||
public static String noPermissionFormatting = "<EFBFBD>c";
|
||||
public static String notAllowedFormatting = "<EFBFBD>c";
|
||||
public static String helpDescriptionFormatting = "<EFBFBD>b";
|
||||
public static String helpUsageFormatting = "<EFBFBD>6";
|
||||
public static String helpPageHeaderFormatting = "<EFBFBD>a";
|
||||
public static String helpInvalidPageFormatting = "<EFBFBD>c";
|
||||
public static String noPermissionFormatting = "<EFBFBD>c";
|
||||
public static String notAllowedFormatting = "<EFBFBD>c";
|
||||
|
||||
/**
|
||||
* Registers a command from a String of source code
|
||||
@@ -210,6 +210,8 @@ public class CommandManager {
|
||||
int bracketCounter = 0;
|
||||
/* line counter */
|
||||
int line = 0;
|
||||
// buffer for '...' and '"' properties of string types
|
||||
StringBuilder sideBuffer = new StringBuilder();
|
||||
|
||||
/* iterate over all characters */
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
@@ -234,7 +236,7 @@ public class CommandManager {
|
||||
errors = true;
|
||||
return false;
|
||||
}else{
|
||||
/* okay, resolved what type this is */
|
||||
/* okay, resolve what type this is */
|
||||
currentArgComp = resolveComponentType(buffer.toString());
|
||||
buffer = new StringBuilder();
|
||||
/* type didn't fit any definition, throw an error */
|
||||
@@ -439,6 +441,11 @@ public class CommandManager {
|
||||
/* set the value of the current type and reset the buffer */
|
||||
currentArgComp.argName = buffer.toString();
|
||||
buffer = new StringBuilder();
|
||||
if (currentArgComp instanceof StringComponent) {
|
||||
StringComponent strComp = (StringComponent) currentArgComp;
|
||||
strComp.infinite = sideBuffer.toString().contains("...");
|
||||
}
|
||||
sideBuffer = new StringBuilder();
|
||||
}
|
||||
}else{
|
||||
/* we are not defining a type, throw an error */
|
||||
@@ -452,7 +459,7 @@ public class CommandManager {
|
||||
buffer.append('&');
|
||||
}else{
|
||||
/* for color codes and formatting */
|
||||
buffer.append('<27>');
|
||||
buffer.append('<27>');
|
||||
}
|
||||
}else if (current == 'n' && currentProp == Property.HELP) {
|
||||
if (previous == '\\') {
|
||||
@@ -471,8 +478,18 @@ public class CommandManager {
|
||||
buffer.append('\\');
|
||||
}
|
||||
}else if (current != '\r' && current != '\n' && current != '\t') {
|
||||
if (currentArgComp != null && current == '.') {
|
||||
if (currentArgComp instanceof StringComponent) {
|
||||
sideBuffer.append(current);
|
||||
}else{
|
||||
plugin.getLogger().log(Level.WARNING, "Syntax error at line " + line + ": '...' is invalid for non-string types.");
|
||||
errors = true;
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
buffer.append(current);
|
||||
}
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.nemez.cmdmgr.component;
|
||||
|
||||
public class StringComponent extends ArgumentComponent {
|
||||
|
||||
public boolean infinite = false;
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
return input;
|
||||
@@ -14,6 +16,6 @@ public class StringComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":str>";
|
||||
return "<" + (infinite ? "..." : "") + argName + ":str>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,8 @@ public class Executable extends org.bukkit.command.Command {
|
||||
break;
|
||||
case "str":
|
||||
StringComponent comp7 = new StringComponent();
|
||||
comp7.argName = type[0].substring(1);
|
||||
comp7.argName = type[0].substring(1).replace("...", "");
|
||||
comp7.infinite = type[0].substring(1).contains("...");
|
||||
paramName = comp7.argName;
|
||||
command.add(comp7);
|
||||
break;
|
||||
@@ -316,7 +317,7 @@ public class Executable extends org.bukkit.command.Command {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (k != defs.get(j).getLength()) {
|
||||
if (k != defs.get(j).getLength(k)) {
|
||||
defs.remove(j);
|
||||
j--;
|
||||
}
|
||||
@@ -365,9 +366,14 @@ public class Executable extends org.bukkit.command.Command {
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] linkedArgs = new Object[arguments.size() + 1];
|
||||
Object[] linkedArgs = new Object[def.getNumOfArgs() + 1];
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
linkedArgs[def.getLink(i) + 1] = arguments.get(i);
|
||||
int link = def.getLink(i) + 1;
|
||||
if (linkedArgs[link] != null) {
|
||||
linkedArgs[link] = linkedArgs[link].toString() + " " + arguments.get(i).toString();
|
||||
}else{
|
||||
linkedArgs[link] = arguments.get(i);
|
||||
}
|
||||
}
|
||||
if (!def.invoke(linkedArgs, sender, plugin)) {
|
||||
printPage(sender, 1);
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.nemez.cmdmgr.CommandManager;
|
||||
import com.nemez.cmdmgr.component.ArgumentComponent;
|
||||
import com.nemez.cmdmgr.component.ICommandComponent;
|
||||
import com.nemez.cmdmgr.component.OptionalComponent;
|
||||
import com.nemez.cmdmgr.component.StringComponent;
|
||||
|
||||
public class ExecutableDefinition {
|
||||
|
||||
@@ -31,23 +32,59 @@ public class ExecutableDefinition {
|
||||
}
|
||||
|
||||
public boolean valid(int index, String arg) {
|
||||
if (index < 0 || index >= components.size()) {
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
if (index >= components.size()) {
|
||||
if (components.get(components.size() - 1) instanceof StringComponent) {
|
||||
StringComponent strComp = (StringComponent) components.get(components.size() - 1);
|
||||
if (strComp.infinite) {
|
||||
return strComp.valid(arg);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return components.get(index).valid(arg);
|
||||
}
|
||||
|
||||
public Object get(int index, String arg) {
|
||||
if (index < 0 || index >= components.size()) {
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
if (index >= components.size()) {
|
||||
if (components.get(components.size() - 1) instanceof StringComponent) {
|
||||
StringComponent strComp = (StringComponent) components.get(components.size() - 1);
|
||||
if (strComp.infinite) {
|
||||
return strComp.get(arg);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return components.get(index).get(arg);
|
||||
}
|
||||
|
||||
public boolean isArgument(int index) {
|
||||
if (index < 0 || index >= components.size()) {
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
if (index >= components.size()) {
|
||||
if (components.get(components.size() - 1) instanceof StringComponent) {
|
||||
StringComponent strComp = (StringComponent) components.get(components.size() - 1);
|
||||
if (strComp.infinite) {
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return components.get(index) instanceof ArgumentComponent;
|
||||
}
|
||||
|
||||
@@ -70,14 +107,44 @@ public class ExecutableDefinition {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
public int getLength(int argSize) {
|
||||
if (argSize >= components.size()) {
|
||||
if (components.get(components.size() - 1) instanceof StringComponent) {
|
||||
StringComponent strComp = (StringComponent) components.get(components.size() - 1);
|
||||
if (strComp.infinite) {
|
||||
return argSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
return components.size();
|
||||
}
|
||||
|
||||
public int getNumOfArgs() {
|
||||
int counter = 0;
|
||||
for (ICommandComponent c : components) {
|
||||
if (c instanceof ArgumentComponent) {
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
public int getLink(int i) {
|
||||
if (i < 0 || i > paramLinks.size()) {
|
||||
if (i < 0) {
|
||||
return i;
|
||||
}
|
||||
if (i >= paramLinks.size()) {
|
||||
if (components.get(components.size() - 1) instanceof StringComponent) {
|
||||
StringComponent strComp = (StringComponent) components.get(components.size() - 1);
|
||||
if (strComp.infinite) {
|
||||
return paramLinks.get(paramLinks.size() - 1);
|
||||
}else{
|
||||
return i;
|
||||
}
|
||||
}else{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return paramLinks.get(i);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user