Changed the Runnable to a Command
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package net.minecraft.commands;
|
||||
|
||||
import net.minecraft.commands.context.CommandContext;
|
||||
|
||||
public interface Command {
|
||||
void run(CommandContext context);
|
||||
}
|
||||
@@ -2,10 +2,13 @@ package net.minecraft.commands;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.commands.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.commands.context.CommandContext;
|
||||
import net.minecraft.commands.context.ParsedArgument;
|
||||
import net.minecraft.commands.exceptions.CommandException;
|
||||
import net.minecraft.commands.exceptions.UnknownCommandException;
|
||||
import net.minecraft.commands.tree.LiteralCommandNode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandDispatcher {
|
||||
@@ -24,6 +27,6 @@ public class CommandDispatcher {
|
||||
throw new UnknownCommandException();
|
||||
}
|
||||
|
||||
node.getExecutor().run();
|
||||
node.getCommand().run(new CommandContext(new HashMap<String, ParsedArgument<?>>()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package net.minecraft.commands.builder;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.tree.CommandNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ArgumentBuilder<T extends ArgumentBuilder<?>> {
|
||||
private final List<ArgumentBuilder> arguments = Lists.newArrayList();
|
||||
private Runnable executor;
|
||||
private Command command;
|
||||
|
||||
protected abstract T getThis();
|
||||
|
||||
@@ -20,13 +21,13 @@ public abstract class ArgumentBuilder<T extends ArgumentBuilder<?>> {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public T executes(Runnable executor) {
|
||||
this.executor = executor;
|
||||
public T executes(Command command) {
|
||||
this.command = command;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public Runnable getExecutor() {
|
||||
return executor;
|
||||
public Command getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public abstract CommandNode build();
|
||||
|
||||
@@ -24,7 +24,7 @@ public class LiteralArgumentBuilder extends ArgumentBuilder<LiteralArgumentBuild
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode build() {
|
||||
LiteralCommandNode result = new LiteralCommandNode(getLiteral(), getExecutor());
|
||||
LiteralCommandNode result = new LiteralCommandNode(getLiteral(), getCommand());
|
||||
|
||||
for (ArgumentBuilder argument : getArguments()) {
|
||||
result.addChild(argument.build());
|
||||
|
||||
@@ -30,7 +30,7 @@ public class RequiredArgumentBuilder<T> extends ArgumentBuilder<RequiredArgument
|
||||
}
|
||||
|
||||
public ArgumentCommandNode<T> build() {
|
||||
ArgumentCommandNode<T> result = new ArgumentCommandNode<T>(getName(), getType(), getExecutor());
|
||||
ArgumentCommandNode<T> result = new ArgumentCommandNode<T>(getName(), getType(), getCommand());
|
||||
|
||||
for (ArgumentBuilder argument : getArguments()) {
|
||||
result.addChild(argument.build());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.arguments.CommandArgumentType;
|
||||
import net.minecraft.commands.context.ParsedArgument;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
@@ -9,8 +10,8 @@ public class ArgumentCommandNode<T> extends CommandNode {
|
||||
private final String name;
|
||||
private final CommandArgumentType<T> type;
|
||||
|
||||
public ArgumentCommandNode(String name, CommandArgumentType<T> type, Runnable executor) {
|
||||
super(executor);
|
||||
public ArgumentCommandNode(String name, CommandArgumentType<T> type, Command command) {
|
||||
super(command);
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CommandNode {
|
||||
private final Runnable executor;
|
||||
private final Command command;
|
||||
private final List<CommandNode> children = Lists.newArrayList();
|
||||
|
||||
protected CommandNode(Runnable executor) {
|
||||
this.executor = executor;
|
||||
protected CommandNode(Command command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public Runnable getExecutor() {
|
||||
return executor;
|
||||
public Command getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public List<CommandNode> getChildren() {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.Command;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
|
||||
public class LiteralCommandNode extends CommandNode {
|
||||
private final String literal;
|
||||
|
||||
public LiteralCommandNode(String literal, Runnable executor) {
|
||||
super(executor);
|
||||
public LiteralCommandNode(String literal, Command command) {
|
||||
super(command);
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user