Reformatted code.
This commit is contained in:
@@ -7,14 +7,12 @@ import java.lang.annotation.Target;
|
|||||||
|
|
||||||
@Target (ElementType.METHOD)
|
@Target (ElementType.METHOD)
|
||||||
@Retention (RetentionPolicy.RUNTIME)
|
@Retention (RetentionPolicy.RUNTIME)
|
||||||
public @interface Command
|
public @interface Command {
|
||||||
{
|
|
||||||
enum AsyncType
|
|
||||||
{
|
|
||||||
NEVER, ALWAYS;
|
|
||||||
}
|
|
||||||
|
|
||||||
String hook();
|
String hook();
|
||||||
|
|
||||||
AsyncType async() default AsyncType.NEVER;
|
AsyncType async() default AsyncType.NEVER;
|
||||||
|
|
||||||
|
enum AsyncType {
|
||||||
|
NEVER, ALWAYS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
//@noformat
|
//@noformat
|
||||||
package com.nemez.cmdmgr;
|
package com.nemez.cmdmgr;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import com.nemez.cmdmgr.component.*;
|
||||||
import java.io.File;
|
import com.nemez.cmdmgr.util.*;
|
||||||
import java.io.FileReader;
|
import org.bukkit.Bukkit;
|
||||||
import java.io.InputStream;
|
import org.bukkit.command.CommandMap;
|
||||||
import java.io.InputStreamReader;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -15,33 +17,9 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.nemez.cmdmgr.component.ArgumentComponent;
|
|
||||||
import com.nemez.cmdmgr.component.BooleanComponent;
|
|
||||||
import com.nemez.cmdmgr.component.ByteComponent;
|
|
||||||
import com.nemez.cmdmgr.component.ChainComponent;
|
|
||||||
import com.nemez.cmdmgr.component.ConstantComponent;
|
|
||||||
import com.nemez.cmdmgr.component.DoubleComponent;
|
|
||||||
import com.nemez.cmdmgr.component.EmptyComponent;
|
|
||||||
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;
|
|
||||||
import com.nemez.cmdmgr.util.BranchStack;
|
|
||||||
import com.nemez.cmdmgr.util.Executable;
|
|
||||||
import com.nemez.cmdmgr.util.HelpPageCommand;
|
|
||||||
import com.nemez.cmdmgr.util.Property;
|
|
||||||
import com.nemez.cmdmgr.util.Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example command.cmd
|
* Example command.cmd
|
||||||
*
|
* <p>
|
||||||
* command home:
|
* command home:
|
||||||
* set [string:name]:
|
* set [string:name]:
|
||||||
* run home_set name
|
* run home_set name
|
||||||
@@ -59,35 +37,28 @@ import com.nemez.cmdmgr.util.Type;
|
|||||||
* run home_tp name
|
* run home_tp name
|
||||||
* help Teleport to specified home
|
* help Teleport to specified home
|
||||||
* perm home.tp
|
* perm home.tp
|
||||||
*
|
* <p>
|
||||||
* Generated in-game command structure:
|
* Generated in-game command structure:
|
||||||
* (will only show commands the user has permission to execute)
|
* (will only show commands the user has permission to execute)
|
||||||
*
|
* <p>
|
||||||
* /home set <name>
|
* /home set <name>
|
||||||
* /home del <name>
|
* /home del <name>
|
||||||
* /home list
|
* /home list
|
||||||
* /home <name>
|
* /home <name>
|
||||||
* /home help
|
* /home help
|
||||||
*
|
* <p>
|
||||||
* Java code:
|
* Java code:
|
||||||
*
|
*
|
||||||
* @Command(hook="home_set")
|
* @Command(hook="home_set") public void executeHomeSet(String name) {
|
||||||
* public void executeHomeSet(String name) {
|
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*
|
* @Command(hook="home_del") public void executeHomeDelete(String name) {
|
||||||
* @Command(hook="home_del")
|
|
||||||
* public void executeHomeDelete(String name) {
|
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*
|
* @Command(hook="home_list") public void executeHomeList() {
|
||||||
* @Command(hook="home_list")
|
|
||||||
* public void executeHomeList() {
|
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*
|
* @Command(hook="home_tp") public void executeHomeTeleport(String name) {
|
||||||
* @Command(hook="home_tp")
|
|
||||||
* public void executeHomeTeleport(String name) {
|
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
@@ -118,6 +89,7 @@ public class CommandManager {
|
|||||||
* @param cmdSourceCode source code
|
* @param cmdSourceCode source code
|
||||||
* @param commandHandler instance of a class where your java functions are located
|
* @param commandHandler instance of a class where your java functions are located
|
||||||
* @param plugin your plugin class
|
* @param plugin your plugin class
|
||||||
|
*
|
||||||
* @return success - if command was processed and registered successfully
|
* @return success - if command was processed and registered successfully
|
||||||
*/
|
*/
|
||||||
public static boolean registerCommand(String cmdSourceCode, Object commandHandler, JavaPlugin plugin) {
|
public static boolean registerCommand(String cmdSourceCode, Object commandHandler, JavaPlugin plugin) {
|
||||||
@@ -143,6 +115,7 @@ public class CommandManager {
|
|||||||
* @param sourceFile file containing source code
|
* @param sourceFile file containing source code
|
||||||
* @param commandHandler instance of a class where your java functions are located
|
* @param commandHandler instance of a class where your java functions are located
|
||||||
* @param plugin your plugin class
|
* @param plugin your plugin class
|
||||||
|
*
|
||||||
* @return success - if command was processed and registered successfully
|
* @return success - if command was processed and registered successfully
|
||||||
*/
|
*/
|
||||||
public static boolean registerCommand(File sourceFile, Object commandHandler, JavaPlugin plugin) {
|
public static boolean registerCommand(File sourceFile, Object commandHandler, JavaPlugin plugin) {
|
||||||
@@ -170,6 +143,7 @@ public class CommandManager {
|
|||||||
* @param sourceStream input stream containing source code
|
* @param sourceStream input stream containing source code
|
||||||
* @param commandHandler instance of a class where your java functions are located
|
* @param commandHandler instance of a class where your java functions are located
|
||||||
* @param plugin your plugin class
|
* @param plugin your plugin class
|
||||||
|
*
|
||||||
* @return success - if command was processed and registered successfully
|
* @return success - if command was processed and registered successfully
|
||||||
*/
|
*/
|
||||||
public static boolean registerCommand(InputStream sourceStream, Object commandHandler, JavaPlugin plugin) {
|
public static boolean registerCommand(InputStream sourceStream, Object commandHandler, JavaPlugin plugin) {
|
||||||
@@ -213,29 +187,6 @@ public class CommandManager {
|
|||||||
unregisterCommands(src.toString());
|
unregisterCommands(src.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters all commands from an InputStream
|
|
||||||
*
|
|
||||||
* @param sourceStream input stream containing source code
|
|
||||||
* @param plugin your plugin class
|
|
||||||
*/
|
|
||||||
public static void unregisterCommands(InputStream sourceStream, JavaPlugin plugin) {
|
|
||||||
StringBuilder src = new StringBuilder();
|
|
||||||
String buf = "";
|
|
||||||
try {
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(sourceStream));
|
|
||||||
while ((buf = reader.readLine()) != null) {
|
|
||||||
src.append(buf + '\n');
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
plugin.getLogger().log(Level.WARNING, "Error while loading command file. (" + sourceStream.toString() + ")");
|
|
||||||
plugin.getLogger().log(Level.WARNING, e.getCause().toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unregisterCommands(src.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters all commands from a String of source code
|
* Unregisters all commands from a String of source code
|
||||||
*
|
*
|
||||||
@@ -306,10 +257,31 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unregisterAll(String[] commands)
|
/**
|
||||||
{
|
* Unregisters all commands from an InputStream
|
||||||
for (String name : commands)
|
*
|
||||||
{
|
* @param sourceStream input stream containing source code
|
||||||
|
* @param plugin your plugin class
|
||||||
|
*/
|
||||||
|
public static void unregisterCommands(InputStream sourceStream, JavaPlugin plugin) {
|
||||||
|
StringBuilder src = new StringBuilder();
|
||||||
|
String buf = "";
|
||||||
|
try {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(sourceStream));
|
||||||
|
while ((buf = reader.readLine()) != null) {
|
||||||
|
src.append(buf + '\n');
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().log(Level.WARNING, "Error while loading command file. (" + sourceStream.toString() + ")");
|
||||||
|
plugin.getLogger().log(Level.WARNING, e.getCause().toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unregisterCommands(src.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unregisterAll(String[] commands) {
|
||||||
|
for (String name : commands) {
|
||||||
EmptyCommand emptyCommand = new EmptyCommand(name);
|
EmptyCommand emptyCommand = new EmptyCommand(name);
|
||||||
try {
|
try {
|
||||||
final Field cmdMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
final Field cmdMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||||
@@ -367,6 +339,7 @@ public class CommandManager {
|
|||||||
* @param methods ArrayList of methods gathered from the plugin's handler class
|
* @param methods ArrayList of methods gathered from the plugin's handler class
|
||||||
* @param plugin plugin to register commands as
|
* @param plugin plugin to register commands as
|
||||||
* @param methodContainer class containing method handles
|
* @param methodContainer class containing method handles
|
||||||
|
*
|
||||||
* @return success - if command parsing and registration was successful
|
* @return success - if command parsing and registration was successful
|
||||||
*/
|
*/
|
||||||
private static boolean parse(String source, ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer) {
|
private static boolean parse(String source, ArrayList<Method> methods, JavaPlugin plugin, Object methodContainer) {
|
||||||
@@ -467,7 +440,9 @@ public class CommandManager {
|
|||||||
stack.get().type = resolveExecutionType(buffer.toString().trim());
|
stack.get().type = resolveExecutionType(buffer.toString().trim());
|
||||||
/* not a valid type, throw an error */
|
/* not a valid type, throw an error */
|
||||||
if (stack.get().type == null) {
|
if (stack.get().type == null) {
|
||||||
plugin.getLogger().log(Level.WARNING, "Attribute error at line " + line + ": Invalid attribute value. (" + buffer.toString().trim() + ").");
|
plugin
|
||||||
|
.getLogger()
|
||||||
|
.log(Level.WARNING, "Attribute error at line " + line + ": Invalid attribute value. (" + buffer.toString().trim() + ").");
|
||||||
errors = true;
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -692,6 +667,7 @@ public class CommandManager {
|
|||||||
* Resolves the string into a type, or null if invalid
|
* Resolves the string into a type, or null if invalid
|
||||||
*
|
*
|
||||||
* @param type string you want to evaluate
|
* @param type string you want to evaluate
|
||||||
|
*
|
||||||
* @return the type class or null if invalid
|
* @return the type class or null if invalid
|
||||||
*/
|
*/
|
||||||
private static ArgumentComponent resolveComponentType(String type) {
|
private static ArgumentComponent resolveComponentType(String type) {
|
||||||
@@ -729,6 +705,7 @@ public class CommandManager {
|
|||||||
* Resolves the string into a property, or null if invalid
|
* Resolves the string into a property, or null if invalid
|
||||||
*
|
*
|
||||||
* @param type string you want to evaluate
|
* @param type string you want to evaluate
|
||||||
|
*
|
||||||
* @return the property enum or null if invalid
|
* @return the property enum or null if invalid
|
||||||
*/
|
*/
|
||||||
private static Type resolveExecutionType(String type) {
|
private static Type resolveExecutionType(String type) {
|
||||||
@@ -808,7 +785,9 @@ public class CommandManager {
|
|||||||
chain += temp;
|
chain += temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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";
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
package com.nemez.cmdmgr;
|
package com.nemez.cmdmgr;
|
||||||
|
|
||||||
|
import com.nemez.cmdmgr.util.Executable;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.nemez.cmdmgr.util.Executable;
|
public class EmptyCommand extends Executable {
|
||||||
|
public EmptyCommand(String name) {
|
||||||
public class EmptyCommand extends Executable
|
|
||||||
{
|
|
||||||
public EmptyCommand(String name)
|
|
||||||
{
|
|
||||||
super(name, null, "");
|
super(name, null, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender sender, String name, String[] args_)
|
public boolean execute(CommandSender sender, String name, String[] args_) {
|
||||||
{
|
|
||||||
sender.sendMessage("§cCommand no longer Exists. Use §e/help§c, §e/plugins§c or ask a mod.");
|
sender.sendMessage("§cCommand no longer Exists. Use §e/help§c, §e/plugins§c or ask a mod.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ public class BooleanComponent extends ArgumentComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean valid(String input) {
|
public boolean valid(String input) {
|
||||||
if (input.toLowerCase().equals("true") || input.toLowerCase().equals("false") || input.toLowerCase().equals("yes") || input.toLowerCase().equals("no")) {
|
if (input.toLowerCase().equals("true") || input.toLowerCase().equals("false") || input.toLowerCase().equals("yes") || input
|
||||||
|
.toLowerCase()
|
||||||
|
.equals("no")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package com.nemez.cmdmgr.component;
|
package com.nemez.cmdmgr.component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.nemez.cmdmgr.util.Type;
|
import com.nemez.cmdmgr.util.Type;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ChainComponent implements ICommandComponent {
|
public class ChainComponent implements ICommandComponent {
|
||||||
|
|
||||||
private ArrayList<ICommandComponent> components;
|
|
||||||
public String permission;
|
public String permission;
|
||||||
public String help;
|
public String help;
|
||||||
public String execute;
|
public String execute;
|
||||||
public Type type;
|
public Type type;
|
||||||
public ArrayList<String> aliases = new ArrayList<String>();
|
public ArrayList<String> aliases = new ArrayList<String>();
|
||||||
|
private ArrayList<ICommandComponent> components;
|
||||||
|
|
||||||
public ChainComponent() {
|
public ChainComponent() {
|
||||||
components = new ArrayList<ICommandComponent>();
|
components = new ArrayList<ICommandComponent>();
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package com.nemez.cmdmgr.component;
|
|||||||
public interface ICommandComponent {
|
public interface ICommandComponent {
|
||||||
|
|
||||||
public Object get(String input);
|
public Object get(String input);
|
||||||
|
|
||||||
public boolean valid(String input);
|
public boolean valid(String input);
|
||||||
|
|
||||||
public String argName();
|
public String argName();
|
||||||
|
|
||||||
public String getComponentInfo();
|
public String getComponentInfo();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,23 @@
|
|||||||
package com.nemez.cmdmgr.util;
|
package com.nemez.cmdmgr.util;
|
||||||
|
|
||||||
|
import com.nemez.cmdmgr.component.ICommandComponent;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
public class AsyncExecutableDefinition extends ExecutableDefinition {
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.nemez.cmdmgr.component.ICommandComponent;
|
|
||||||
|
|
||||||
public class AsyncExecutableDefinition extends ExecutableDefinition
|
|
||||||
{
|
|
||||||
public AsyncExecutableDefinition(ArrayList<ICommandComponent> cmd, ArrayList<Integer> paramLinks, String perm,
|
public AsyncExecutableDefinition(ArrayList<ICommandComponent> cmd, ArrayList<Integer> paramLinks, String perm,
|
||||||
Method method, Object methodContainer, Type type)
|
Method method, Object methodContainer, Type type) {
|
||||||
{
|
|
||||||
super(cmd, paramLinks, perm, method, methodContainer, type);
|
super(cmd, paramLinks, perm, method, methodContainer, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean invoke(Object[] args, CommandSender sender, JavaPlugin plugin)
|
public boolean invoke(Object[] args, CommandSender sender, JavaPlugin plugin) {
|
||||||
{
|
Thread t = new Thread(new Runnable() {
|
||||||
Thread t = new Thread(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run() {
|
||||||
{
|
|
||||||
invokeFromThread(args, sender, plugin);
|
invokeFromThread(args, sender, plugin);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -32,8 +26,7 @@ public class AsyncExecutableDefinition extends ExecutableDefinition
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void invokeFromThread(Object[] args, CommandSender sender, JavaPlugin plugin)
|
private final void invokeFromThread(Object[] args, CommandSender sender, JavaPlugin plugin) {
|
||||||
{
|
|
||||||
super.invoke(args, sender, plugin);
|
super.invoke(args, sender, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.nemez.cmdmgr.util;
|
package com.nemez.cmdmgr.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import com.nemez.cmdmgr.component.ChainComponent;
|
import com.nemez.cmdmgr.component.ChainComponent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class BranchStack {
|
public class BranchStack {
|
||||||
|
|
||||||
private ArrayList<ChainComponent> components;
|
private ArrayList<ChainComponent> components;
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
//@noformat
|
//@noformat
|
||||||
package com.nemez.cmdmgr.util;
|
package com.nemez.cmdmgr.util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import com.nemez.cmdmgr.Command;
|
||||||
import java.lang.reflect.Method;
|
import com.nemez.cmdmgr.Command.AsyncType;
|
||||||
import java.util.ArrayList;
|
import com.nemez.cmdmgr.CommandManager;
|
||||||
import java.util.HashMap;
|
import com.nemez.cmdmgr.component.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
@@ -15,20 +12,12 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.nemez.cmdmgr.Command;
|
import java.lang.reflect.Field;
|
||||||
import com.nemez.cmdmgr.Command.AsyncType;
|
import java.lang.reflect.Method;
|
||||||
import com.nemez.cmdmgr.CommandManager;
|
import java.util.ArrayList;
|
||||||
import com.nemez.cmdmgr.component.BooleanComponent;
|
import java.util.HashMap;
|
||||||
import com.nemez.cmdmgr.component.ByteComponent;
|
import java.util.Map;
|
||||||
import com.nemez.cmdmgr.component.ConstantComponent;
|
import java.util.logging.Level;
|
||||||
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 {
|
public class Executable extends org.bukkit.command.Command {
|
||||||
|
|
||||||
@@ -120,7 +109,8 @@ public class Executable extends org.bukkit.command.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processLine(String[] line, String permission, String method, ArrayList<Method> methods, Object methodContainer, JavaPlugin plugin, Type etype) {
|
private void processLine(String[] line, String permission, String method, ArrayList<Method> methods, Object methodContainer, JavaPlugin plugin,
|
||||||
|
Type etype) {
|
||||||
ArrayList<ICommandComponent> command = new ArrayList<ICommandComponent>();
|
ArrayList<ICommandComponent> command = new ArrayList<ICommandComponent>();
|
||||||
if (method == null && line[1].equals("help")) {
|
if (method == null && line[1].equals("help")) {
|
||||||
command.add(new ConstantComponent("help"));
|
command.add(new ConstantComponent("help"));
|
||||||
@@ -337,7 +327,8 @@ public class Executable extends org.bukkit.command.Command {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
defs.addAll(commands);
|
defs.addAll(commands);
|
||||||
defLoop: for (int j = 0; j < defs.size(); j++) {
|
defLoop:
|
||||||
|
for (int j = 0; j < defs.size(); j++) {
|
||||||
if (defs.get(j).getLength(args.length) == 0) {
|
if (defs.get(j).getLength(args.length) == 0) {
|
||||||
defs.remove(j);
|
defs.remove(j);
|
||||||
j--;
|
j--;
|
||||||
@@ -378,17 +369,21 @@ public class Executable extends org.bukkit.command.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def.getPermission() != null && !def.getPermission().equals("null") && !sender.hasPermission(def.getPermission())) {
|
if (def.getPermission() != null && !def.getPermission().equals("null") && !sender.hasPermission(def.getPermission())) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandManager.noPermissionFormatting + "You do not have permission to execute this command."));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
CommandManager.noPermissionFormatting + "You do not have permission to execute this command."
|
||||||
|
));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (def.getExecType() == Type.PLAYER) {
|
if (def.getExecType() == Type.PLAYER) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandManager.notAllowedFormatting + "Only players are allowed to run this command."));
|
sender.sendMessage(
|
||||||
|
ChatColor.translateAlternateColorCodes('&', CommandManager.notAllowedFormatting + "Only players are allowed to run this command."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (def.getExecType() == Type.CONSOLE) {
|
} else if (def.getExecType() == Type.CONSOLE) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandManager.notAllowedFormatting + "Only console is allowed to run this command."));
|
sender.sendMessage(
|
||||||
|
ChatColor.translateAlternateColorCodes('&', CommandManager.notAllowedFormatting + "Only console is allowed to run this command."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (def.getExecType() == Type.NOBODY) {
|
} else if (def.getExecType() == Type.NOBODY) {
|
||||||
@@ -425,10 +420,15 @@ public class Executable extends org.bukkit.command.Command {
|
|||||||
private void printPage(CommandSender sender, int page) {
|
private void printPage(CommandSender sender, int page) {
|
||||||
page--;
|
page--;
|
||||||
if (page < 0 || page >= help.size()) {
|
if (page < 0 || page >= help.size()) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandManager.helpInvalidPageFormatting + "Non-existant page (" + (page + 1) + ").\nThere are " + help.size() + " pages."));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
CommandManager.helpInvalidPageFormatting + "Non-existant page (" + (page + 1) + ").\nThere are " + help
|
||||||
|
.size() + " pages."
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
HelpPageCommand[] pageData = help.get(page);
|
HelpPageCommand[] pageData = help.get(page);
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandManager.helpPageHeaderFormatting + "### Help Page " + (page + 1) + "/" + (help.size()) + " ###"));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
CommandManager.helpPageHeaderFormatting + "### Help Page " + (page + 1) + "/" + (help.size()) + " ###"
|
||||||
|
));
|
||||||
for (HelpPageCommand c : pageData) {
|
for (HelpPageCommand c : pageData) {
|
||||||
if (c != null) {
|
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.type == null || c.type == Type.BOTH || (c.type == Type.CONSOLE && !(sender instanceof Player)) || (c.type == Type.PLAYER && sender instanceof Player)) {
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
package com.nemez.cmdmgr.util;
|
package com.nemez.cmdmgr.util;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.nemez.cmdmgr.CommandManager;
|
import com.nemez.cmdmgr.CommandManager;
|
||||||
import com.nemez.cmdmgr.component.ArgumentComponent;
|
import com.nemez.cmdmgr.component.ArgumentComponent;
|
||||||
import com.nemez.cmdmgr.component.ICommandComponent;
|
import com.nemez.cmdmgr.component.ICommandComponent;
|
||||||
import com.nemez.cmdmgr.component.OptionalComponent;
|
import com.nemez.cmdmgr.component.OptionalComponent;
|
||||||
import com.nemez.cmdmgr.component.StringComponent;
|
import com.nemez.cmdmgr.component.StringComponent;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ExecutableDefinition {
|
public class ExecutableDefinition {
|
||||||
|
|
||||||
@@ -23,7 +22,8 @@ public class ExecutableDefinition {
|
|||||||
private Type type;
|
private Type type;
|
||||||
private ArrayList<Integer> paramLinks;
|
private ArrayList<Integer> paramLinks;
|
||||||
|
|
||||||
public ExecutableDefinition(ArrayList<ICommandComponent> cmd, ArrayList<Integer> paramLinks, 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.components = cmd;
|
||||||
this.permission = perm;
|
this.permission = perm;
|
||||||
this.target = method;
|
this.target = method;
|
||||||
@@ -165,7 +165,9 @@ public class ExecutableDefinition {
|
|||||||
return (boolean) target.invoke(methodContainer, args);
|
return (boolean) target.invoke(methodContainer, args);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandManager.helpInvalidPageFormatting + "An internal error occured, please contact the server administrator and/or report a bug."));
|
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||||
|
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");
|
plugin.getLogger().log(Level.WARNING, "Runtime Error: invalid method");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user