Added proper print outs
This commit is contained in:
@@ -3,9 +3,12 @@ package com.nemez.cmdmgr;
|
|||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@@ -81,6 +84,7 @@ import com.nemez.cmdmgr.util.Property;
|
|||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
public static boolean debugOutput = false;
|
public static boolean debugOutput = false;
|
||||||
|
public static boolean errors = false;
|
||||||
|
|
||||||
public static boolean registerCommand(String cmdSourceCode, Object commandHandler, JavaPlugin plugin) {
|
public static boolean registerCommand(String cmdSourceCode, Object commandHandler, JavaPlugin plugin) {
|
||||||
if (cmdSourceCode == null || commandHandler == null || plugin == null) {
|
if (cmdSourceCode == null || commandHandler == null || plugin == null) {
|
||||||
@@ -107,7 +111,27 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO log this crap into the console...
|
plugin.getLogger().log(Level.WARNING, "Error while loading command file. (" + sourceFile.getAbsolutePath() + ")");
|
||||||
|
plugin.getLogger().log(Level.WARNING, e.getCause().toString());
|
||||||
|
errors = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return registerCommand(src.toString(), commandHandler, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean registerCommand(InputStream sourceStream, Object commandHandler, JavaPlugin plugin) {
|
||||||
|
StringBuilder src = new StringBuilder();
|
||||||
|
String buf = "";
|
||||||
|
try {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(sourceStream));
|
||||||
|
while ((buf = reader.readLine()) != null) {
|
||||||
|
src.append(buf);
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return registerCommand(src.toString(), commandHandler, plugin);
|
return registerCommand(src.toString(), commandHandler, plugin);
|
||||||
@@ -137,30 +161,28 @@ public class CommandManager {
|
|||||||
if (current == ':') {
|
if (current == ':') {
|
||||||
if (insideType) {
|
if (insideType) {
|
||||||
if (currentArgComp != null) {
|
if (currentArgComp != null) {
|
||||||
// error
|
plugin.getLogger().log(Level.WARNING, "Syntax error at line " + line + ": Already defining a type.");
|
||||||
System.err.println("already processing a type");
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
currentArgComp = resolveComponentType(buffer.toString());
|
currentArgComp = resolveComponentType(buffer.toString());
|
||||||
buffer = new StringBuilder();
|
buffer = new StringBuilder();
|
||||||
if (currentArgComp == null) {
|
if (currentArgComp == null) {
|
||||||
// error - invalid type
|
plugin.getLogger().log(Level.WARNING, "Type error at line " + line + ": Invalid type.");
|
||||||
System.err.println("invalid type");
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
// error
|
buffer.append(':');
|
||||||
System.err.println("where do you think a colon belongs...");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}else if (current == ';') {
|
}else if (current == ';') {
|
||||||
if (previous == '\\') {
|
if (previous == '\\') {
|
||||||
buffer.append(';');
|
buffer.append(';');
|
||||||
}else{
|
}else{
|
||||||
if (stack.get() == null) {
|
if (stack.get() == null) {
|
||||||
// error
|
plugin.getLogger().log(Level.WARNING, "Syntax error at line " + line + ": Not in code section.");
|
||||||
System.err.println("stack is empty...");
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (currentProp == Property.HELP) {
|
if (currentProp == Property.HELP) {
|
||||||
@@ -170,8 +192,8 @@ public class CommandManager {
|
|||||||
}else if (currentProp == Property.PERMISSION) {
|
}else if (currentProp == Property.PERMISSION) {
|
||||||
stack.get().permission = buffer.toString().trim();
|
stack.get().permission = buffer.toString().trim();
|
||||||
}else{
|
}else{
|
||||||
// what?
|
plugin.getLogger().log(Level.WARNING, "Attribute error at line " + line + ": Invalid attribute type.");
|
||||||
System.err.println("okay, this is my fault");
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
currentProp = Property.NONE;
|
currentProp = Property.NONE;
|
||||||
@@ -202,8 +224,8 @@ public class CommandManager {
|
|||||||
bracketCounter--;
|
bracketCounter--;
|
||||||
ChainComponent popped = stack.pop();
|
ChainComponent popped = stack.pop();
|
||||||
if (popped == null) {
|
if (popped == null) {
|
||||||
// error
|
plugin.getLogger().log(Level.WARNING, "Syntax error at line " + line + ": Too many closing brackets.");
|
||||||
System.err.println("outta stacks!");
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (bracketCounter == 0) {
|
if (bracketCounter == 0) {
|
||||||
@@ -252,8 +274,8 @@ public class CommandManager {
|
|||||||
if (currentProp != Property.NONE) {
|
if (currentProp != Property.NONE) {
|
||||||
buffer.append('[');
|
buffer.append('[');
|
||||||
}else if (insideType) {
|
}else if (insideType) {
|
||||||
// error
|
plugin.getLogger().log(Level.WARNING, "Syntax error at line " + line + ": Invalid type declaration.");
|
||||||
System.err.println("dont declare a type inside of a type please");
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
insideType = true;
|
insideType = true;
|
||||||
@@ -264,16 +286,17 @@ public class CommandManager {
|
|||||||
}else if (insideType) {
|
}else if (insideType) {
|
||||||
insideType = false;
|
insideType = false;
|
||||||
if (currentArgComp == null) {
|
if (currentArgComp == null) {
|
||||||
// error
|
// this should never happen though, it should error out at the top when the type is ""
|
||||||
System.err.println("type without a type?");
|
plugin.getLogger().log(Level.WARNING, "Type error at line " + line + ": Type has to type?");
|
||||||
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
currentArgComp.argName = buffer.toString();
|
currentArgComp.argName = buffer.toString();
|
||||||
buffer = new StringBuilder();
|
buffer = new StringBuilder();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
// error
|
plugin.getLogger().log(Level.WARNING, "Syntax error at line " + line + ": Not in type declaration.");
|
||||||
System.err.println("a square bracket doesnt belong here");
|
errors = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}else if (current == '&' && currentProp == Property.HELP) {
|
}else if (current == '&' && currentProp == Property.HELP) {
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package com.nemez.cmdmgr.util;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.nemez.cmdmgr.Command;
|
import com.nemez.cmdmgr.Command;
|
||||||
|
import com.nemez.cmdmgr.CommandManager;
|
||||||
import com.nemez.cmdmgr.component.ByteComponent;
|
import com.nemez.cmdmgr.component.ByteComponent;
|
||||||
import com.nemez.cmdmgr.component.ConstantComponent;
|
import com.nemez.cmdmgr.component.ConstantComponent;
|
||||||
import com.nemez.cmdmgr.component.DoubleComponent;
|
import com.nemez.cmdmgr.component.DoubleComponent;
|
||||||
@@ -36,20 +37,20 @@ public class Executable implements CommandExecutor {
|
|||||||
for (HelpPageCommand[] page : help) {
|
for (HelpPageCommand[] page : help) {
|
||||||
for (HelpPageCommand cmd : page) {
|
for (HelpPageCommand cmd : page) {
|
||||||
if (cmd != null) {
|
if (cmd != null) {
|
||||||
processLine(cmd.usage.split("\\ "), cmd.permission, cmd.method, methods, methodContainer);
|
processLine(cmd.usage.split("\\ "), cmd.permission, cmd.method, methods, methodContainer, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginCommand plcmd = plugin.getCommand(name);
|
plugin.getCommand(name).setExecutor(this);
|
||||||
if (plcmd == null) {
|
|
||||||
System.out.println("the fuck");
|
if (CommandManager.errors) {
|
||||||
}else{
|
plugin.getLogger().log(Level.WARNING, "There were parser errors, some commands may not function properly!");
|
||||||
plcmd.setExecutor(this);
|
CommandManager.errors = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processLine(String[] line, String permission, String method, ArrayList<Method> methods, Object methodContainer) {
|
private void processLine(String[] line, String permission, String method, ArrayList<Method> methods, Object methodContainer, JavaPlugin plugin) {
|
||||||
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"));
|
||||||
@@ -116,7 +117,6 @@ public class Executable implements CommandExecutor {
|
|||||||
command.add(comp7);
|
command.add(comp7);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.err.println("impossible just happened!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -136,6 +136,8 @@ public class Executable implements CommandExecutor {
|
|||||||
for (Method m : methods) {
|
for (Method m : methods) {
|
||||||
Command[] annotations = m.getAnnotationsByType(Command.class);
|
Command[] annotations = m.getAnnotationsByType(Command.class);
|
||||||
if (annotations == null || annotations.length != 1) {
|
if (annotations == null || annotations.length != 1) {
|
||||||
|
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + ")");
|
||||||
|
CommandManager.errors = true;
|
||||||
System.err.println("Method not found! (" + methodArray[0] + ")");
|
System.err.println("Method not found! (" + methodArray[0] + ")");
|
||||||
return;
|
return;
|
||||||
}else{
|
}else{
|
||||||
@@ -148,7 +150,8 @@ public class Executable implements CommandExecutor {
|
|||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
if (params[0] != CommandSender.class) {
|
if (params[0] != CommandSender.class) {
|
||||||
System.err.println("you're missing the 'CommandSender' argument... it must be first btw");
|
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): First argument is not CommandSender");
|
||||||
|
CommandManager.errors = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@@ -168,7 +171,8 @@ public class Executable implements CommandExecutor {
|
|||||||
}else if (comp instanceof StringComponent && params[i] == String.class) {
|
}else if (comp instanceof StringComponent && params[i] == String.class) {
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
System.err.println("error yet again, this time you messed up the method inputs");
|
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Invalid method arguments");
|
||||||
|
CommandManager.errors = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +184,8 @@ public class Executable implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
System.err.println("Method not found! (" + methodArray[0] + ")");
|
plugin.getLogger().log(Level.WARNING, "Invalid method (" + methodArray[0] + "): Method not found");
|
||||||
|
CommandManager.errors = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ExecutableDefinition def = new ExecutableDefinition(command, permission, target, methodContainer);
|
ExecutableDefinition def = new ExecutableDefinition(command, permission, target, methodContainer);
|
||||||
|
|||||||
Reference in New Issue
Block a user