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