Added commandbuilder.then() and argumentbuilder
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
package net.minecraft.commands.arguments;
|
||||||
|
|
||||||
|
public interface CommandArgumentType {
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.minecraft.commands.arguments;
|
||||||
|
|
||||||
|
public class IntegerArgumentType implements CommandArgumentType {
|
||||||
|
private final int minimum;
|
||||||
|
private final int maximum;
|
||||||
|
|
||||||
|
protected IntegerArgumentType(int minimum, int maximum) {
|
||||||
|
this.minimum = minimum;
|
||||||
|
this.maximum = maximum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntegerArgumentType integer() {
|
||||||
|
return integer(Integer.MIN_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntegerArgumentType integer(int min) {
|
||||||
|
return integer(min, Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IntegerArgumentType integer(int min, int max) {
|
||||||
|
return new IntegerArgumentType(min, max);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
@ParametersAreNonnullByDefault
|
||||||
|
package net.minecraft.commands.arguments;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.minecraft.commands.builder;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class ArgumentBuilder {
|
||||||
|
private final List<ArgumentBuilder> arguments = Lists.newArrayList();
|
||||||
|
|
||||||
|
public ArgumentBuilder then(ArgumentBuilder argument) {
|
||||||
|
arguments.add(argument);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ArgumentBuilder> getArguments() {
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
package net.minecraft.commands.builder;
|
package net.minecraft.commands.builder;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandBuilder {
|
public class CommandBuilder {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private final List<ArgumentBuilder> arguments = Lists.newArrayList();
|
||||||
private Runnable executor;
|
private Runnable executor;
|
||||||
|
|
||||||
protected CommandBuilder(String name) {
|
protected CommandBuilder(String name) {
|
||||||
@@ -24,4 +29,13 @@ public class CommandBuilder {
|
|||||||
public Runnable getExecutor() {
|
public Runnable getExecutor() {
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommandBuilder then(ArgumentBuilder argument) {
|
||||||
|
arguments.add(argument);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ArgumentBuilder> getArguments() {
|
||||||
|
return arguments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.minecraft.commands.builder;
|
||||||
|
|
||||||
|
import net.minecraft.commands.arguments.CommandArgumentType;
|
||||||
|
|
||||||
|
public class RequiredArgumentBuilder extends ArgumentBuilder {
|
||||||
|
private final String name;
|
||||||
|
private final CommandArgumentType type;
|
||||||
|
|
||||||
|
protected RequiredArgumentBuilder(String name, CommandArgumentType type) {
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RequiredArgumentBuilder argument(String name, CommandArgumentType type) {
|
||||||
|
return new RequiredArgumentBuilder(name, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package net.minecraft.commands.builder;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||||
|
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||||
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
public class ArgumentBuilderTest {
|
||||||
|
ArgumentBuilder builder;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
builder = new ArgumentBuilder() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testArguments() throws Exception {
|
||||||
|
RequiredArgumentBuilder argument = argument("bar", integer());
|
||||||
|
|
||||||
|
builder.then(argument);
|
||||||
|
|
||||||
|
assertThat(builder.getArguments(), hasSize(1));
|
||||||
|
assertThat(builder.getArguments(), hasItems((ArgumentBuilder) argument));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package net.minecraft.commands.builder;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||||
|
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||||
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
public class CommandBuilderTest {
|
||||||
|
CommandBuilder builder;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
builder = new CommandBuilder("foo");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testArguments() throws Exception {
|
||||||
|
RequiredArgumentBuilder argument = argument("bar", integer());
|
||||||
|
|
||||||
|
builder.then(argument);
|
||||||
|
|
||||||
|
assertThat(builder.getArguments(), hasSize(1));
|
||||||
|
assertThat(builder.getArguments(), hasItems((ArgumentBuilder) argument));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user