Added commandbuilder.then() and argumentbuilder
This commit is contained in:
parent
dadedbb322
commit
934ba3336f
8 changed files with 138 additions and 0 deletions
|
@ -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;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBuilder {
|
||||
private final String name;
|
||||
private final List<ArgumentBuilder> arguments = Lists.newArrayList();
|
||||
private Runnable executor;
|
||||
|
||||
protected CommandBuilder(String name) {
|
||||
|
@ -24,4 +29,13 @@ public class CommandBuilder {
|
|||
public Runnable getExecutor() {
|
||||
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));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue