mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	No more errors made my me, they're all yours :)
This commit is contained in:
		@@ -11,7 +11,7 @@ import java.util.List;
 | 
			
		||||
public class CommandManager {
 | 
			
		||||
 | 
			
		||||
    protected final List<Command> commands;
 | 
			
		||||
    private final Character initialCharacter;
 | 
			
		||||
    protected final Character initialCharacter;
 | 
			
		||||
 | 
			
		||||
    public CommandManager() {
 | 
			
		||||
        this('/', new ArrayList<Command>());
 | 
			
		||||
@@ -44,7 +44,7 @@ public class CommandManager {
 | 
			
		||||
        return this.commands;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    final public int handle(CommandCaller caller, String input) {
 | 
			
		||||
    public int handle(CommandCaller caller, String input) {
 | 
			
		||||
        if (initialCharacter != null && !StringUtil.startsWith(initialCharacter, input)) {
 | 
			
		||||
            return CommandHandlingOutput.NOT_COMMAND;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +0,0 @@
 | 
			
		||||
package com.intellectualsites.commands.callers;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.config.C;
 | 
			
		||||
import com.intellectualsites.commands.Argument;
 | 
			
		||||
import com.intellectualsites.commands.Command;
 | 
			
		||||
import com.intellectualsites.commands.CommandManager;
 | 
			
		||||
 | 
			
		||||
public interface CommandCaller<T> {
 | 
			
		||||
 | 
			
		||||
    boolean hasPermission(String permission);
 | 
			
		||||
 | 
			
		||||
    void message(String message);
 | 
			
		||||
 | 
			
		||||
    T getSuperCaller();
 | 
			
		||||
 | 
			
		||||
    void message(C c, String ... args);
 | 
			
		||||
 | 
			
		||||
    void sendRequiredArgumentsList(CommandManager manager, Command cmd, Argument[] required);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,29 +0,0 @@
 | 
			
		||||
package com.intellectualsites.commands.callers;
 | 
			
		||||
 | 
			
		||||
import com.intellectualsites.commands.Argument;
 | 
			
		||||
import com.intellectualsites.commands.Command;
 | 
			
		||||
import com.intellectualsites.commands.CommandManager;
 | 
			
		||||
 | 
			
		||||
public class SystemCaller implements CommandCaller {
 | 
			
		||||
 | 
			
		||||
    public boolean hasPermission(String permission) {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void message(String message) {
 | 
			
		||||
        System.out.println(message);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Object getSuperCaller() {
 | 
			
		||||
        return new Object();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void sendRequiredArgumentsList(CommandManager manager, Command cmd, Argument[] required) {
 | 
			
		||||
        StringBuilder builder = new StringBuilder();
 | 
			
		||||
        builder.append(manager.getInitialCharacter()).append(cmd.getCommand()).append(" requires ");
 | 
			
		||||
        for (Argument argument : required) {
 | 
			
		||||
            builder.append(argument.getName()).append(" (").append(argument.getExample()).append("), ");
 | 
			
		||||
        }
 | 
			
		||||
        message(builder.substring(0, builder.length() - 2));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,48 +0,0 @@
 | 
			
		||||
package com.intellectualsites.commands.test;
 | 
			
		||||
 | 
			
		||||
import com.intellectualsites.commands.*;
 | 
			
		||||
import com.intellectualsites.commands.callers.CommandCaller;
 | 
			
		||||
import com.intellectualsites.commands.callers.SystemCaller;
 | 
			
		||||
 | 
			
		||||
public class CommandTest {
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        CommandCaller caller = new SystemCaller();
 | 
			
		||||
        CommandManager manager = new CommandManager();
 | 
			
		||||
        if(!manager.createCommand(new TestCommand())) {
 | 
			
		||||
            System.out.println("Failed to create command :(");
 | 
			
		||||
        }
 | 
			
		||||
        manager.handle(caller, "/test banana cow grass");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @CommandDeclaration(command = "test", usage = "/test [word]")
 | 
			
		||||
    public static class TestCommand extends Command {
 | 
			
		||||
        TestCommand() {
 | 
			
		||||
            requiredArguments = new Argument[] {
 | 
			
		||||
                    Argument.String, Argument.String, Argument.String
 | 
			
		||||
            };
 | 
			
		||||
            addCommand(new Command("banana", new String[0]) {
 | 
			
		||||
                @Override
 | 
			
		||||
                public boolean onCommand(CommandCaller caller, String[] arguments) {
 | 
			
		||||
                    if (getCommands().isEmpty()) {
 | 
			
		||||
                        addCommand(new Command("cow") {
 | 
			
		||||
                            @Override
 | 
			
		||||
                            public boolean onCommand(CommandCaller caller, String[] arguments) {
 | 
			
		||||
                                caller.message("I eat " + arguments[0]);
 | 
			
		||||
                                return true;
 | 
			
		||||
                            }
 | 
			
		||||
                        });
 | 
			
		||||
                    }
 | 
			
		||||
                    handle(caller, arguments);
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public boolean onCommand(CommandCaller caller, String[] arguments) {
 | 
			
		||||
            handle(caller, arguments);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user