Added "multiword" strings
This commit is contained in:
118
CmdMgrTest.java
118
CmdMgrTest.java
@@ -1,59 +1,59 @@
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
import com.nemez.cmdmgr.CommandManager;
|
||||
|
||||
public class CmdMgrTest extends JavaPlugin {
|
||||
|
||||
public void onEnable() {
|
||||
CommandManager.registerCommand(new File("plugins/test.cmd"), this, this);
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
@Command(hook="home_set")
|
||||
public boolean executeSetHome(CommandSender sender, String name) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home set " + name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command(hook="home_set_coords")
|
||||
public boolean executeSetHomeBasedOnCoords(CommandSender sender, String name, int x, int y, int z) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home set " + name + " " + x + " " + y + " " + z);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command(hook="home_del")
|
||||
public void executeDelHome(CommandSender sender, String name, boolean aFlag) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home del " + name);
|
||||
sender.sendMessage("-a - " + aFlag);
|
||||
}
|
||||
|
||||
@Command(hook="home_list")
|
||||
public void executeListHomes(CommandSender sender) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home list");
|
||||
}
|
||||
|
||||
@Command(hook="home_tp")
|
||||
public void executeTeleportHome(CommandSender sender, String name) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home " + name);
|
||||
}
|
||||
|
||||
@Command(hook="noskope")
|
||||
public boolean executeMagik(CommandSender sender) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home yolo swag");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
import com.nemez.cmdmgr.CommandManager;
|
||||
|
||||
public class CmdMgrTest extends JavaPlugin {
|
||||
|
||||
public void onEnable() {
|
||||
CommandManager.registerCommand(new File("plugins/test.cmd"), this, this);
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
@Command(hook="home_set")
|
||||
public boolean executeSetHome(CommandSender sender, String name) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home set " + name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command(hook="home_set_coords")
|
||||
public boolean executeSetHomeBasedOnCoords(CommandSender sender, String name, int x, int y, int z) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home set " + name + " " + x + " " + y + " " + z);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Command(hook="home_del")
|
||||
public void executeDelHome(CommandSender sender, String name, boolean aFlag) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home del " + name);
|
||||
sender.sendMessage("-a - " + aFlag);
|
||||
}
|
||||
|
||||
@Command(hook="home_list")
|
||||
public void executeListHomes(CommandSender sender) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home list");
|
||||
}
|
||||
|
||||
@Command(hook="home_tp")
|
||||
public void executeTeleportHome(CommandSender sender, String name) {
|
||||
sender.sendMessage("You executed:");
|
||||
sender.sendMessage("/home " + name);
|
||||
}
|
||||
|
||||
@Command(hook="noskope")
|
||||
public boolean executeMagik(CommandSender sender) {
|
||||
sender.sendMessage("You executed!!!!!!!!!:");
|
||||
sender.sendMessage("/home yolo swag");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# CommandManager
|
||||
Scripting-based Spigot/Bukkit command manager
|
||||
|
||||
Feel free to use and PR enhancements/customizations! If you're a nice person, you can give me credit.
|
||||
# CommandManager
|
||||
Scripting-based Spigot/Bukkit command manager
|
||||
|
||||
Feel free to use and PR enhancements/customizations! If you're a nice person, you can give me credit.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.nemez.cmdmgr;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Command {
|
||||
|
||||
String hook();
|
||||
}
|
||||
package com.nemez.cmdmgr;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Command {
|
||||
|
||||
String hook();
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public abstract class ArgumentComponent implements ICommandComponent {
|
||||
|
||||
public String argName;
|
||||
public int position;
|
||||
|
||||
@Override
|
||||
public String argName() {
|
||||
return argName;
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public abstract class ArgumentComponent implements ICommandComponent {
|
||||
|
||||
public String argName;
|
||||
public int position;
|
||||
|
||||
@Override
|
||||
public String argName() {
|
||||
return argName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class BooleanComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
if (input.toLowerCase().equals("true") || input.toLowerCase().equals("yes")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
if (input.toLowerCase().equals("true") || input.toLowerCase().equals("false") || input.toLowerCase().equals("yes") || input.toLowerCase().equals("no")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":bool>";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class BooleanComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
if (input.toLowerCase().equals("true") || input.toLowerCase().equals("yes")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
if (input.toLowerCase().equals("true") || input.toLowerCase().equals("false") || input.toLowerCase().equals("yes") || input.toLowerCase().equals("no")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":bool>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class ByteComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Byte.parseByte(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Byte.parseByte(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i8>";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class ByteComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Byte.parseByte(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Byte.parseByte(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i8>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.nemez.cmdmgr.util.Type;
|
||||
|
||||
public class ChainComponent implements ICommandComponent {
|
||||
|
||||
private ArrayList<ICommandComponent> components;
|
||||
public String permission;
|
||||
public String help;
|
||||
public String execute;
|
||||
public Type type;
|
||||
|
||||
public ChainComponent() {
|
||||
components = new ArrayList<ICommandComponent>();
|
||||
}
|
||||
|
||||
public void append(ICommandComponent comp) {
|
||||
components.add(comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String argName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "chain[" + components.size() + "]";
|
||||
}
|
||||
|
||||
public int capacity() {
|
||||
return components.size();
|
||||
}
|
||||
|
||||
public ArrayList<ICommandComponent> getComponents() {
|
||||
return components;
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.nemez.cmdmgr.util.Type;
|
||||
|
||||
public class ChainComponent implements ICommandComponent {
|
||||
|
||||
private ArrayList<ICommandComponent> components;
|
||||
public String permission;
|
||||
public String help;
|
||||
public String execute;
|
||||
public Type type;
|
||||
|
||||
public ChainComponent() {
|
||||
components = new ArrayList<ICommandComponent>();
|
||||
}
|
||||
|
||||
public void append(ICommandComponent comp) {
|
||||
components.add(comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String argName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "chain[" + components.size() + "]";
|
||||
}
|
||||
|
||||
public int capacity() {
|
||||
return components.size();
|
||||
}
|
||||
|
||||
public ArrayList<ICommandComponent> getComponents() {
|
||||
return components;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class ConstantComponent implements ICommandComponent {
|
||||
|
||||
private String component;
|
||||
|
||||
public ConstantComponent(String comp) {
|
||||
component = comp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
if (input.equals(component)) {
|
||||
return input;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return input.equals(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String argName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class ConstantComponent implements ICommandComponent {
|
||||
|
||||
private String component;
|
||||
|
||||
public ConstantComponent(String comp) {
|
||||
component = comp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
if (input.equals(component)) {
|
||||
return input;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return input.equals(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String argName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class DoubleComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Double.parseDouble(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Double.parseDouble(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":fp64>";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class DoubleComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Double.parseDouble(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Double.parseDouble(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":fp64>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class FloatComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Float.parseFloat(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Float.parseFloat(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":fp32>";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class FloatComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Float.parseFloat(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Float.parseFloat(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":fp32>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public interface ICommandComponent {
|
||||
|
||||
public Object get(String input);
|
||||
public boolean valid(String input);
|
||||
public String argName();
|
||||
public String getComponentInfo();
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public interface ICommandComponent {
|
||||
|
||||
public Object get(String input);
|
||||
public boolean valid(String input);
|
||||
public String argName();
|
||||
public String getComponentInfo();
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class IntegerComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Integer.parseInt(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Integer.parseInt(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i32>";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class IntegerComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Integer.parseInt(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Integer.parseInt(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i32>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class LongComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Long.parseLong(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Long.parseLong(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i64>";
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class LongComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Long.parseLong(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Long.parseLong(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i64>";
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class OptionalComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
return input.equals(argName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return input.equals(argName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":flag>";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class OptionalComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
return input.equals(argName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return input.equals(argName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":flag>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class ShortComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Short.parseShort(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Short.parseShort(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i16>";
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class ShortComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
try {
|
||||
return Short.parseShort(input);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
try {
|
||||
Short.parseShort(input);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":i16>";
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class StringComponent extends ArgumentComponent {
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + argName + ":str>";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.component;
|
||||
|
||||
public class StringComponent extends ArgumentComponent {
|
||||
|
||||
public boolean infinite = false;
|
||||
|
||||
@Override
|
||||
public Object get(String input) {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean valid(String input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentInfo() {
|
||||
return "<" + (infinite ? "..." : "") + argName + ":str>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.nemez.cmdmgr.component.ChainComponent;
|
||||
|
||||
public class BranchStack {
|
||||
|
||||
private ArrayList<ChainComponent> components;
|
||||
|
||||
public BranchStack() {
|
||||
components = new ArrayList<ChainComponent>();
|
||||
}
|
||||
|
||||
public void push(ChainComponent comp) {
|
||||
components.add(comp);
|
||||
}
|
||||
|
||||
public ChainComponent pop() {
|
||||
if (components.size() > 0) {
|
||||
ChainComponent toPop = components.remove(components.size() - 1);
|
||||
return toPop;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ChainComponent get() {
|
||||
if (components.size() > 0) {
|
||||
return components.get(components.size() - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.nemez.cmdmgr.component.ChainComponent;
|
||||
|
||||
public class BranchStack {
|
||||
|
||||
private ArrayList<ChainComponent> components;
|
||||
|
||||
public BranchStack() {
|
||||
components = new ArrayList<ChainComponent>();
|
||||
}
|
||||
|
||||
public void push(ChainComponent comp) {
|
||||
components.add(comp);
|
||||
}
|
||||
|
||||
public ChainComponent pop() {
|
||||
if (components.size() > 0) {
|
||||
ChainComponent toPop = components.remove(components.size() - 1);
|
||||
return toPop;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ChainComponent get() {
|
||||
if (components.size() > 0) {
|
||||
return components.get(components.size() - 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,398 +1,404 @@
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
import com.nemez.cmdmgr.CommandManager;
|
||||
import com.nemez.cmdmgr.component.BooleanComponent;
|
||||
import com.nemez.cmdmgr.component.ByteComponent;
|
||||
import com.nemez.cmdmgr.component.ConstantComponent;
|
||||
import com.nemez.cmdmgr.component.DoubleComponent;
|
||||
import com.nemez.cmdmgr.component.FloatComponent;
|
||||
import com.nemez.cmdmgr.component.ICommandComponent;
|
||||
import com.nemez.cmdmgr.component.IntegerComponent;
|
||||
import com.nemez.cmdmgr.component.LongComponent;
|
||||
import com.nemez.cmdmgr.component.OptionalComponent;
|
||||
import com.nemez.cmdmgr.component.ShortComponent;
|
||||
import com.nemez.cmdmgr.component.StringComponent;
|
||||
|
||||
public class Executable extends org.bukkit.command.Command {
|
||||
|
||||
private ArrayList<ExecutableDefinition> commands;
|
||||
private ArrayList<HelpPageCommand[]> help;
|
||||
private String name;
|
||||
private JavaPlugin plugin;
|
||||
|
||||
public Executable(String name, ArrayList<HelpPageCommand[]> help) {
|
||||
super(name);
|
||||
this.help = help;
|
||||
this.name = name;
|
||||
this.commands = new ArrayList<ExecutableDefinition>();
|
||||
}
|
||||
|
||||
public void register(ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer) {
|
||||
for (HelpPageCommand[] page : help) {
|
||||
for (HelpPageCommand cmd : page) {
|
||||
if (cmd != null) {
|
||||
processLine(cmd.usage.split("\\ "), cmd.permission, cmd.method, methods, methodContainer, plugin, cmd.type);
|
||||
String newUsage = "";
|
||||
String buffer = "";
|
||||
String typeBuffer = "";
|
||||
boolean ignore = false;
|
||||
boolean toBuffer = false;
|
||||
for (char c : cmd.usage.toCharArray()) {
|
||||
if (c == '<') {
|
||||
toBuffer = true;
|
||||
}else if (c == ':') {
|
||||
toBuffer = false;
|
||||
ignore = true;
|
||||
}else if (c == '>') {
|
||||
ignore = false;
|
||||
if (typeBuffer.equals("flag")) {
|
||||
newUsage += '[' + buffer + (CommandManager.debugHelpMenu ? ':' + typeBuffer : "") + ']';
|
||||
}else{
|
||||
newUsage += '<' + buffer + (CommandManager.debugHelpMenu ? ':' + typeBuffer : "") + '>';
|
||||
}
|
||||
buffer = "";
|
||||
typeBuffer = "";
|
||||
}else{
|
||||
if (toBuffer) {
|
||||
buffer += c;
|
||||
}else if (ignore) {
|
||||
typeBuffer += c;
|
||||
}else{
|
||||
newUsage += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd.usage = newUsage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
final Field cmdMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
cmdMap.setAccessible(true);
|
||||
CommandMap map = (CommandMap) cmdMap.get(Bukkit.getServer());
|
||||
map.register(name, this);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to register command '" + name + "'!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (CommandManager.errors) {
|
||||
plugin.getLogger().log(Level.WARNING, "There were parser errors, some commands may not function properly!");
|
||||
CommandManager.errors = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void processLine(String[] line, String permission, String method, ArrayList<Method> methods, Object methodContainer, JavaPlugin plugin, Type etype) {
|
||||
ArrayList<ICommandComponent> command = new ArrayList<ICommandComponent>();
|
||||
if (method == null && line[1].equals("help")) {
|
||||
command.add(new ConstantComponent("help"));
|
||||
IntegerComponent pageID = new IntegerComponent();
|
||||
pageID.argName = "page";
|
||||
command.add(pageID);
|
||||
ExecutableDefinition def = new ExecutableDefinition(command, null, permission, null, methodContainer, Type.BOTH);
|
||||
commands.add(def);
|
||||
return;
|
||||
}
|
||||
HashMap<Integer, ICommandComponent> methodParams = new HashMap<Integer, ICommandComponent>();
|
||||
method = method.trim() + " ";
|
||||
String[] methodArray = method.split(" ");
|
||||
Method target = null;
|
||||
ArrayList<Integer> links = new ArrayList<Integer>();
|
||||
|
||||
for (String s : line) {
|
||||
if (s.contains("/")) {
|
||||
continue;
|
||||
}
|
||||
if (s.contains(":")) {
|
||||
String[] type = s.split(":");
|
||||
String paramName = "";
|
||||
switch (type[1].substring(0, type[1].length() - 1)) {
|
||||
case "i8":
|
||||
ByteComponent comp1 = new ByteComponent();
|
||||
comp1.argName = type[0].substring(1);
|
||||
paramName = comp1.argName;
|
||||
command.add(comp1);
|
||||
break;
|
||||
case "i16":
|
||||
ShortComponent comp2 = new ShortComponent();
|
||||
comp2.argName = type[0].substring(1);
|
||||
paramName = comp2.argName;
|
||||
command.add(comp2);
|
||||
break;
|
||||
case "i32":
|
||||
IntegerComponent comp3 = new IntegerComponent();
|
||||
comp3.argName = type[0].substring(1);
|
||||
paramName = comp3.argName;
|
||||
command.add(comp3);
|
||||
break;
|
||||
case "i64":
|
||||
LongComponent comp4 = new LongComponent();
|
||||
comp4.argName = type[0].substring(1);
|
||||
paramName = comp4.argName;
|
||||
command.add(comp4);
|
||||
break;
|
||||
case "fp32":
|
||||
FloatComponent comp5 = new FloatComponent();
|
||||
comp5.argName = type[0].substring(1);
|
||||
paramName = comp5.argName;
|
||||
command.add(comp5);
|
||||
break;
|
||||
case "fp64":
|
||||
DoubleComponent comp6 = new DoubleComponent();
|
||||
comp6.argName = type[0].substring(1);
|
||||
paramName = comp6.argName;
|
||||
command.add(comp6);
|
||||
break;
|
||||
case "str":
|
||||
StringComponent comp7 = new StringComponent();
|
||||
comp7.argName = type[0].substring(1);
|
||||
paramName = comp7.argName;
|
||||
command.add(comp7);
|
||||
break;
|
||||
case "bool":
|
||||
BooleanComponent comp8 = new BooleanComponent();
|
||||
comp8.argName = type[0].substring(1);
|
||||
paramName = comp8.argName;
|
||||
command.add(comp8);
|
||||
break;
|
||||
case "flag":
|
||||
OptionalComponent comp9 = new OptionalComponent();
|
||||
comp9.argName = type[0].substring(1);
|
||||
paramName = comp9.argName;
|
||||
command.add(comp9);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
int index = 0;
|
||||
for (int i = 1; i < methodArray.length; i++) {
|
||||
if (methodArray[i] != null && !methodArray[i].trim().equals("")) {
|
||||
if (methodArray[i].trim().equals(paramName)) {
|
||||
methodParams.put(index, command.get(command.size() - 1));
|
||||
links.add(index);
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
command.add(new ConstantComponent(s));
|
||||
}
|
||||
}
|
||||
|
||||
for (Method m : methods) {
|
||||
Command[] annotations = m.getAnnotationsByType(Command.class);
|
||||
if (annotations == null || annotations.length != 1) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + ")");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}else{
|
||||
if (annotations[0].hook().equals(methodArray[0])) {
|
||||
Class<?>[] params = m.getParameterTypes();
|
||||
if (params.length -1 != methodParams.size()) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Arguments don't match");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}else{
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (i == 0) {
|
||||
if (params[0] != CommandSender.class) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): First argument is not CommandSender");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
ICommandComponent comp = methodParams.get(i - 1);
|
||||
if (comp instanceof ByteComponent && params[i] == byte.class) {
|
||||
|
||||
}else if (comp instanceof ShortComponent && params[i] == short.class) {
|
||||
|
||||
}else if (comp instanceof IntegerComponent && params[i] == int.class) {
|
||||
|
||||
}else if (comp instanceof LongComponent && params[i] == long.class) {
|
||||
|
||||
}else if (comp instanceof FloatComponent && params[i] == float.class) {
|
||||
|
||||
}else if (comp instanceof DoubleComponent && params[i] == double.class) {
|
||||
|
||||
}else if (comp instanceof StringComponent && params[i] == String.class) {
|
||||
|
||||
}else if (comp instanceof BooleanComponent && params[i] == boolean.class) {
|
||||
|
||||
}else if (comp instanceof OptionalComponent && params[i] == boolean.class) {
|
||||
|
||||
}else{
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Invalid method arguments");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
target = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Method not found");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}
|
||||
if (etype == null) {
|
||||
etype = Type.BOTH;
|
||||
}
|
||||
ExecutableDefinition def = new ExecutableDefinition(command, links, permission, target, methodContainer, etype);
|
||||
commands.add(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String name, String[] args_) {
|
||||
char[] rawArgs = (String.join(" ", args_) + ' ').toCharArray();
|
||||
int argSize = 0;
|
||||
char last = '\0';
|
||||
boolean inString = false;
|
||||
|
||||
for (char c : rawArgs) {
|
||||
if (c == '"') {
|
||||
if (last != '\\') {
|
||||
inString = !inString;
|
||||
}
|
||||
}else if (c == ' ' && !inString) {
|
||||
argSize++;
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
last = '\0';
|
||||
String[] args = new String[argSize];
|
||||
String buffer = "";
|
||||
int index = 0;
|
||||
|
||||
for (char c : rawArgs) {
|
||||
if (c == '"') {
|
||||
if (last != '\\') {
|
||||
inString = !inString;
|
||||
}else{
|
||||
buffer = buffer.substring(0, buffer.length() - 1) + '"';
|
||||
}
|
||||
}else if (c == ' ' && !inString) {
|
||||
args[index] = buffer;
|
||||
buffer = "";
|
||||
index++;
|
||||
}else{
|
||||
buffer += c;
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
|
||||
ArrayList<ExecutableDefinition> defs = new ArrayList<ExecutableDefinition>();
|
||||
defs.addAll(commands);
|
||||
defLoop: for (int j = 0; j < defs.size(); j++) {
|
||||
int i = 0, k = 0;
|
||||
for (; i < args.length; i++, k++) {
|
||||
if (!defs.get(j).valid(k, args[i])) {
|
||||
if (!defs.get(j).isOptional(k)) {
|
||||
defs.remove(j);
|
||||
j--;
|
||||
continue defLoop;
|
||||
}else{
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (k != defs.get(j).getLength()) {
|
||||
defs.remove(j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (args.length == 0 || defs.size() == 0) {
|
||||
printPage(sender, 1);
|
||||
}else{
|
||||
ExecutableDefinition def = defs.get(0);
|
||||
for (ExecutableDefinition d : defs) {
|
||||
if (d.isHelp() && args[0].equals("help")) {
|
||||
try {
|
||||
int page = Integer.parseInt(args[1]);
|
||||
printPage(sender, page);
|
||||
} catch (Exception e) {
|
||||
printPage(sender, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (def.getPermission() != null && !sender.hasPermission(def.getPermission())) {
|
||||
sender.sendMessage(CommandManager.noPermissionFormatting + "You do not have permission to execute this command.");
|
||||
return true;
|
||||
}
|
||||
if (def.getExecType() == Type.PLAYER) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(CommandManager.notAllowedFormatting + "Only players are allowed to run this command.");
|
||||
return true;
|
||||
}
|
||||
}else if (def.getExecType() == Type.CONSOLE) {
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage(CommandManager.notAllowedFormatting + "Only console is allowed to run this command.");
|
||||
return true;
|
||||
}
|
||||
}else if (def.getExecType() == Type.NOBODY) {
|
||||
sender.sendMessage(CommandManager.notAllowedFormatting + "Nobody can run this command.");
|
||||
return true;
|
||||
}
|
||||
ArrayList<Object> arguments = new ArrayList<Object>();
|
||||
for (int i = 0, j = 0; i < args.length; i++, j++) {
|
||||
if (def.isArgument(j)) {
|
||||
if (def.valid(j, args[i])) {
|
||||
arguments.add(def.get(j, args[i]));
|
||||
}else if (def.isOptional(j)) {
|
||||
arguments.add(false);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] linkedArgs = new Object[arguments.size() + 1];
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
linkedArgs[def.getLink(i) + 1] = arguments.get(i);
|
||||
}
|
||||
if (!def.invoke(linkedArgs, sender, plugin)) {
|
||||
printPage(sender, 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void printPage(CommandSender sender, int page) {
|
||||
page--;
|
||||
if (page < 0 || page >= help.size()) {
|
||||
sender.sendMessage(CommandManager.helpInvalidPageFormatting + "Non-existant page (" + (page + 1) + ").\nThere are " + help.size() + " pages.");
|
||||
}else{
|
||||
HelpPageCommand[] pageData = help.get(page);
|
||||
sender.sendMessage(CommandManager.helpPageHeaderFormatting + "### Help Page " + (page + 1) + "/" + (help.size()) + " ###");
|
||||
for (HelpPageCommand c : pageData) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.nemez.cmdmgr.Command;
|
||||
import com.nemez.cmdmgr.CommandManager;
|
||||
import com.nemez.cmdmgr.component.BooleanComponent;
|
||||
import com.nemez.cmdmgr.component.ByteComponent;
|
||||
import com.nemez.cmdmgr.component.ConstantComponent;
|
||||
import com.nemez.cmdmgr.component.DoubleComponent;
|
||||
import com.nemez.cmdmgr.component.FloatComponent;
|
||||
import com.nemez.cmdmgr.component.ICommandComponent;
|
||||
import com.nemez.cmdmgr.component.IntegerComponent;
|
||||
import com.nemez.cmdmgr.component.LongComponent;
|
||||
import com.nemez.cmdmgr.component.OptionalComponent;
|
||||
import com.nemez.cmdmgr.component.ShortComponent;
|
||||
import com.nemez.cmdmgr.component.StringComponent;
|
||||
|
||||
public class Executable extends org.bukkit.command.Command {
|
||||
|
||||
private ArrayList<ExecutableDefinition> commands;
|
||||
private ArrayList<HelpPageCommand[]> help;
|
||||
private String name;
|
||||
private JavaPlugin plugin;
|
||||
|
||||
public Executable(String name, ArrayList<HelpPageCommand[]> help) {
|
||||
super(name);
|
||||
this.help = help;
|
||||
this.name = name;
|
||||
this.commands = new ArrayList<ExecutableDefinition>();
|
||||
}
|
||||
|
||||
public void register(ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer) {
|
||||
for (HelpPageCommand[] page : help) {
|
||||
for (HelpPageCommand cmd : page) {
|
||||
if (cmd != null) {
|
||||
processLine(cmd.usage.split("\\ "), cmd.permission, cmd.method, methods, methodContainer, plugin, cmd.type);
|
||||
String newUsage = "";
|
||||
String buffer = "";
|
||||
String typeBuffer = "";
|
||||
boolean ignore = false;
|
||||
boolean toBuffer = false;
|
||||
for (char c : cmd.usage.toCharArray()) {
|
||||
if (c == '<') {
|
||||
toBuffer = true;
|
||||
}else if (c == ':') {
|
||||
toBuffer = false;
|
||||
ignore = true;
|
||||
}else if (c == '>') {
|
||||
ignore = false;
|
||||
if (typeBuffer.equals("flag")) {
|
||||
newUsage += '[' + buffer + (CommandManager.debugHelpMenu ? ':' + typeBuffer : "") + ']';
|
||||
}else{
|
||||
newUsage += '<' + buffer + (CommandManager.debugHelpMenu ? ':' + typeBuffer : "") + '>';
|
||||
}
|
||||
buffer = "";
|
||||
typeBuffer = "";
|
||||
}else{
|
||||
if (toBuffer) {
|
||||
buffer += c;
|
||||
}else if (ignore) {
|
||||
typeBuffer += c;
|
||||
}else{
|
||||
newUsage += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd.usage = newUsage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.plugin = plugin;
|
||||
try {
|
||||
final Field cmdMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
cmdMap.setAccessible(true);
|
||||
CommandMap map = (CommandMap) cmdMap.get(Bukkit.getServer());
|
||||
map.register(name, this);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to register command '" + name + "'!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (CommandManager.errors) {
|
||||
plugin.getLogger().log(Level.WARNING, "There were parser errors, some commands may not function properly!");
|
||||
CommandManager.errors = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void processLine(String[] line, String permission, String method, ArrayList<Method> methods, Object methodContainer, JavaPlugin plugin, Type etype) {
|
||||
ArrayList<ICommandComponent> command = new ArrayList<ICommandComponent>();
|
||||
if (method == null && line[1].equals("help")) {
|
||||
command.add(new ConstantComponent("help"));
|
||||
IntegerComponent pageID = new IntegerComponent();
|
||||
pageID.argName = "page";
|
||||
command.add(pageID);
|
||||
ExecutableDefinition def = new ExecutableDefinition(command, null, permission, null, methodContainer, Type.BOTH);
|
||||
commands.add(def);
|
||||
return;
|
||||
}
|
||||
HashMap<Integer, ICommandComponent> methodParams = new HashMap<Integer, ICommandComponent>();
|
||||
method = method.trim() + " ";
|
||||
String[] methodArray = method.split(" ");
|
||||
Method target = null;
|
||||
ArrayList<Integer> links = new ArrayList<Integer>();
|
||||
|
||||
for (String s : line) {
|
||||
if (s.contains("/")) {
|
||||
continue;
|
||||
}
|
||||
if (s.contains(":")) {
|
||||
String[] type = s.split(":");
|
||||
String paramName = "";
|
||||
switch (type[1].substring(0, type[1].length() - 1)) {
|
||||
case "i8":
|
||||
ByteComponent comp1 = new ByteComponent();
|
||||
comp1.argName = type[0].substring(1);
|
||||
paramName = comp1.argName;
|
||||
command.add(comp1);
|
||||
break;
|
||||
case "i16":
|
||||
ShortComponent comp2 = new ShortComponent();
|
||||
comp2.argName = type[0].substring(1);
|
||||
paramName = comp2.argName;
|
||||
command.add(comp2);
|
||||
break;
|
||||
case "i32":
|
||||
IntegerComponent comp3 = new IntegerComponent();
|
||||
comp3.argName = type[0].substring(1);
|
||||
paramName = comp3.argName;
|
||||
command.add(comp3);
|
||||
break;
|
||||
case "i64":
|
||||
LongComponent comp4 = new LongComponent();
|
||||
comp4.argName = type[0].substring(1);
|
||||
paramName = comp4.argName;
|
||||
command.add(comp4);
|
||||
break;
|
||||
case "fp32":
|
||||
FloatComponent comp5 = new FloatComponent();
|
||||
comp5.argName = type[0].substring(1);
|
||||
paramName = comp5.argName;
|
||||
command.add(comp5);
|
||||
break;
|
||||
case "fp64":
|
||||
DoubleComponent comp6 = new DoubleComponent();
|
||||
comp6.argName = type[0].substring(1);
|
||||
paramName = comp6.argName;
|
||||
command.add(comp6);
|
||||
break;
|
||||
case "str":
|
||||
StringComponent comp7 = new StringComponent();
|
||||
comp7.argName = type[0].substring(1).replace("...", "");
|
||||
comp7.infinite = type[0].substring(1).contains("...");
|
||||
paramName = comp7.argName;
|
||||
command.add(comp7);
|
||||
break;
|
||||
case "bool":
|
||||
BooleanComponent comp8 = new BooleanComponent();
|
||||
comp8.argName = type[0].substring(1);
|
||||
paramName = comp8.argName;
|
||||
command.add(comp8);
|
||||
break;
|
||||
case "flag":
|
||||
OptionalComponent comp9 = new OptionalComponent();
|
||||
comp9.argName = type[0].substring(1);
|
||||
paramName = comp9.argName;
|
||||
command.add(comp9);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
int index = 0;
|
||||
for (int i = 1; i < methodArray.length; i++) {
|
||||
if (methodArray[i] != null && !methodArray[i].trim().equals("")) {
|
||||
if (methodArray[i].trim().equals(paramName)) {
|
||||
methodParams.put(index, command.get(command.size() - 1));
|
||||
links.add(index);
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
command.add(new ConstantComponent(s));
|
||||
}
|
||||
}
|
||||
|
||||
for (Method m : methods) {
|
||||
Command[] annotations = m.getAnnotationsByType(Command.class);
|
||||
if (annotations == null || annotations.length != 1) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + ")");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}else{
|
||||
if (annotations[0].hook().equals(methodArray[0])) {
|
||||
Class<?>[] params = m.getParameterTypes();
|
||||
if (params.length -1 != methodParams.size()) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Arguments don't match");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}else{
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (i == 0) {
|
||||
if (params[0] != CommandSender.class) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): First argument is not CommandSender");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
ICommandComponent comp = methodParams.get(i - 1);
|
||||
if (comp instanceof ByteComponent && params[i] == byte.class) {
|
||||
|
||||
}else if (comp instanceof ShortComponent && params[i] == short.class) {
|
||||
|
||||
}else if (comp instanceof IntegerComponent && params[i] == int.class) {
|
||||
|
||||
}else if (comp instanceof LongComponent && params[i] == long.class) {
|
||||
|
||||
}else if (comp instanceof FloatComponent && params[i] == float.class) {
|
||||
|
||||
}else if (comp instanceof DoubleComponent && params[i] == double.class) {
|
||||
|
||||
}else if (comp instanceof StringComponent && params[i] == String.class) {
|
||||
|
||||
}else if (comp instanceof BooleanComponent && params[i] == boolean.class) {
|
||||
|
||||
}else if (comp instanceof OptionalComponent && params[i] == boolean.class) {
|
||||
|
||||
}else{
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Invalid method arguments");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
target = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Method not found");
|
||||
CommandManager.errors = true;
|
||||
return;
|
||||
}
|
||||
if (etype == null) {
|
||||
etype = Type.BOTH;
|
||||
}
|
||||
ExecutableDefinition def = new ExecutableDefinition(command, links, permission, target, methodContainer, etype);
|
||||
commands.add(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String name, String[] args_) {
|
||||
char[] rawArgs = (String.join(" ", args_) + ' ').toCharArray();
|
||||
int argSize = 0;
|
||||
char last = '\0';
|
||||
boolean inString = false;
|
||||
|
||||
for (char c : rawArgs) {
|
||||
if (c == '"') {
|
||||
if (last != '\\') {
|
||||
inString = !inString;
|
||||
}
|
||||
}else if (c == ' ' && !inString) {
|
||||
argSize++;
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
last = '\0';
|
||||
String[] args = new String[argSize];
|
||||
String buffer = "";
|
||||
int index = 0;
|
||||
|
||||
for (char c : rawArgs) {
|
||||
if (c == '"') {
|
||||
if (last != '\\') {
|
||||
inString = !inString;
|
||||
}else{
|
||||
buffer = buffer.substring(0, buffer.length() - 1) + '"';
|
||||
}
|
||||
}else if (c == ' ' && !inString) {
|
||||
args[index] = buffer;
|
||||
buffer = "";
|
||||
index++;
|
||||
}else{
|
||||
buffer += c;
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
|
||||
ArrayList<ExecutableDefinition> defs = new ArrayList<ExecutableDefinition>();
|
||||
defs.addAll(commands);
|
||||
defLoop: for (int j = 0; j < defs.size(); j++) {
|
||||
int i = 0, k = 0;
|
||||
for (; i < args.length; i++, k++) {
|
||||
if (!defs.get(j).valid(k, args[i])) {
|
||||
if (!defs.get(j).isOptional(k)) {
|
||||
defs.remove(j);
|
||||
j--;
|
||||
continue defLoop;
|
||||
}else{
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (k != defs.get(j).getLength(k)) {
|
||||
defs.remove(j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (args.length == 0 || defs.size() == 0) {
|
||||
printPage(sender, 1);
|
||||
}else{
|
||||
ExecutableDefinition def = defs.get(0);
|
||||
for (ExecutableDefinition d : defs) {
|
||||
if (d.isHelp() && args[0].equals("help")) {
|
||||
try {
|
||||
int page = Integer.parseInt(args[1]);
|
||||
printPage(sender, page);
|
||||
} catch (Exception e) {
|
||||
printPage(sender, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (def.getPermission() != null && !sender.hasPermission(def.getPermission())) {
|
||||
sender.sendMessage(CommandManager.noPermissionFormatting + "You do not have permission to execute this command.");
|
||||
return true;
|
||||
}
|
||||
if (def.getExecType() == Type.PLAYER) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(CommandManager.notAllowedFormatting + "Only players are allowed to run this command.");
|
||||
return true;
|
||||
}
|
||||
}else if (def.getExecType() == Type.CONSOLE) {
|
||||
if (sender instanceof Player) {
|
||||
sender.sendMessage(CommandManager.notAllowedFormatting + "Only console is allowed to run this command.");
|
||||
return true;
|
||||
}
|
||||
}else if (def.getExecType() == Type.NOBODY) {
|
||||
sender.sendMessage(CommandManager.notAllowedFormatting + "Nobody can run this command.");
|
||||
return true;
|
||||
}
|
||||
ArrayList<Object> arguments = new ArrayList<Object>();
|
||||
for (int i = 0, j = 0; i < args.length; i++, j++) {
|
||||
if (def.isArgument(j)) {
|
||||
if (def.valid(j, args[i])) {
|
||||
arguments.add(def.get(j, args[i]));
|
||||
}else if (def.isOptional(j)) {
|
||||
arguments.add(false);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] linkedArgs = new Object[def.getNumOfArgs() + 1];
|
||||
for (int i = 0; i < arguments.size(); 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);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void printPage(CommandSender sender, int page) {
|
||||
page--;
|
||||
if (page < 0 || page >= help.size()) {
|
||||
sender.sendMessage(CommandManager.helpInvalidPageFormatting + "Non-existant page (" + (page + 1) + ").\nThere are " + help.size() + " pages.");
|
||||
}else{
|
||||
HelpPageCommand[] pageData = help.get(page);
|
||||
sender.sendMessage(CommandManager.helpPageHeaderFormatting + "### Help Page " + (page + 1) + "/" + (help.size()) + " ###");
|
||||
for (HelpPageCommand c : pageData) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +1,171 @@
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
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 {
|
||||
|
||||
private ArrayList<ICommandComponent> components;
|
||||
private String permission;
|
||||
private Method target;
|
||||
private Object methodContainer;
|
||||
private Type type;
|
||||
private ArrayList<Integer> paramLinks;
|
||||
|
||||
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) {
|
||||
if (index < 0 || index >= components.size()) {
|
||||
return false;
|
||||
}
|
||||
return components.get(index).valid(arg);
|
||||
}
|
||||
|
||||
public Object get(int index, String arg) {
|
||||
if (index < 0 || index >= components.size()) {
|
||||
return null;
|
||||
}
|
||||
return components.get(index).get(arg);
|
||||
}
|
||||
|
||||
public boolean isArgument(int index) {
|
||||
if (index < 0 || index >= components.size()) {
|
||||
return false;
|
||||
}
|
||||
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>");
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public Type getExecType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return components.size();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
args[0] = sender;
|
||||
try {
|
||||
if (target.getReturnType() == void.class) {
|
||||
target.invoke(methodContainer, args);
|
||||
return true;
|
||||
}else if (target.getReturnType() == boolean.class) {
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
import com.nemez.cmdmgr.component.StringComponent;
|
||||
|
||||
public class ExecutableDefinition {
|
||||
|
||||
private ArrayList<ICommandComponent> components;
|
||||
private String permission;
|
||||
private Method target;
|
||||
private Object methodContainer;
|
||||
private Type type;
|
||||
private ArrayList<Integer> paramLinks;
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
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>");
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public Type getExecType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
public boolean invoke(Object[] args, CommandSender sender, JavaPlugin plugin) {
|
||||
if (target == null) {
|
||||
return false;
|
||||
}
|
||||
args[0] = sender;
|
||||
try {
|
||||
if (target.getReturnType() == void.class) {
|
||||
target.invoke(methodContainer, args);
|
||||
return true;
|
||||
}else if (target.getReturnType() == boolean.class) {
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
public class HelpPageCommand {
|
||||
|
||||
public String permission;
|
||||
public String usage;
|
||||
public String description;
|
||||
public String method;
|
||||
public Type type;
|
||||
|
||||
public HelpPageCommand(String perm, String usage, String description, String method, Type type) {
|
||||
this.permission = perm;
|
||||
this.usage = usage;
|
||||
this.description = description;
|
||||
this.method = method;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
public class HelpPageCommand {
|
||||
|
||||
public String permission;
|
||||
public String usage;
|
||||
public String description;
|
||||
public String method;
|
||||
public Type type;
|
||||
|
||||
public HelpPageCommand(String perm, String usage, String description, String method, Type type) {
|
||||
this.permission = perm;
|
||||
this.usage = usage;
|
||||
this.description = description;
|
||||
this.method = method;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
public enum Property {
|
||||
|
||||
NONE, PERMISSION, HELP, EXECUTE, TYPE;
|
||||
|
||||
}
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
public enum Property {
|
||||
|
||||
NONE, PERMISSION, HELP, EXECUTE, TYPE;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
public enum Type {
|
||||
|
||||
BOTH, PLAYER, CONSOLE, NOBODY;
|
||||
|
||||
public static Type parse(String string) {
|
||||
if (string.equals("both")) {
|
||||
return BOTH;
|
||||
}else if (string.equals("player")) {
|
||||
return PLAYER;
|
||||
}else if (string.equals("console")) {
|
||||
return CONSOLE;
|
||||
}else if (string.equals("nobody")) {
|
||||
return NOBODY;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String get(Type t) {
|
||||
if (t == null) {
|
||||
return "null";
|
||||
}
|
||||
switch (t) {
|
||||
case BOTH:
|
||||
return "both";
|
||||
case PLAYER:
|
||||
return "player";
|
||||
case CONSOLE:
|
||||
return "console";
|
||||
case NOBODY:
|
||||
return "nobody";
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
package com.nemez.cmdmgr.util;
|
||||
|
||||
public enum Type {
|
||||
|
||||
BOTH, PLAYER, CONSOLE, NOBODY;
|
||||
|
||||
public static Type parse(String string) {
|
||||
if (string.equals("both")) {
|
||||
return BOTH;
|
||||
}else if (string.equals("player")) {
|
||||
return PLAYER;
|
||||
}else if (string.equals("console")) {
|
||||
return CONSOLE;
|
||||
}else if (string.equals("nobody")) {
|
||||
return NOBODY;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String get(Type t) {
|
||||
if (t == null) {
|
||||
return "null";
|
||||
}
|
||||
switch (t) {
|
||||
case BOTH:
|
||||
return "both";
|
||||
case PLAYER:
|
||||
return "player";
|
||||
case CONSOLE:
|
||||
return "console";
|
||||
case NOBODY:
|
||||
return "nobody";
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: CommandManagerTest
|
||||
main: CmdMgrTest
|
||||
version: 13.37
|
||||
name: CommandManagerTest
|
||||
main: CmdMgrTest
|
||||
version: 13.37
|
||||
author: Nemes
|
||||
68
test.cmd
68
test.cmd
@@ -1,35 +1,35 @@
|
||||
|
||||
command home {
|
||||
|
||||
set [string:name] {
|
||||
[int:x] [int:y] [int:z] {
|
||||
run home_set_coords name x y z;
|
||||
perm home.set.xyz;
|
||||
help Sets a new home at coordinates XYZ;
|
||||
}
|
||||
run home_set name;
|
||||
perm home.set;
|
||||
help Sets a new home;
|
||||
type none;
|
||||
}
|
||||
del [optional:-a] [string:name] {
|
||||
run home_del name -a;
|
||||
help Deletes a home\n&cCannot be undone!;
|
||||
perm home.del;
|
||||
}
|
||||
list {
|
||||
help Shows all homes;
|
||||
run home_list;
|
||||
perm home.list;
|
||||
}
|
||||
[string:name] {
|
||||
perm home.tp;
|
||||
help Teleports to a home;
|
||||
run home_tp name;
|
||||
}
|
||||
yolo swag {
|
||||
perm yo.mamma;
|
||||
help Reks you;
|
||||
run noskope;
|
||||
}
|
||||
|
||||
command home {
|
||||
|
||||
set [string:name] {
|
||||
[int:x] [int:y] [int:z] {
|
||||
run home_set_coords name x y z;
|
||||
perm home.set.xyz;
|
||||
help Sets a new home at coordinates XYZ;
|
||||
}
|
||||
run home_set name;
|
||||
perm home.set;
|
||||
help Sets a new home;
|
||||
type none;
|
||||
}
|
||||
del [optional:-a] [string:name] {
|
||||
run home_del name -a;
|
||||
help Deletes a home\n&cCannot be undone!;
|
||||
perm home.del;
|
||||
}
|
||||
list {
|
||||
help Shows all homes;
|
||||
run home_list;
|
||||
perm home.list;
|
||||
}
|
||||
[string:name] {
|
||||
perm home.tp;
|
||||
help Teleports to a home;
|
||||
run home_tp name;
|
||||
}
|
||||
yolo swag {
|
||||
perm yo.mamma;
|
||||
help Reks you;
|
||||
run noskope;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user