Merge remote-tracking branch 'upstream/master' into extension-exposing

This commit is contained in:
LeoDog896 2021-03-24 11:59:01 -04:00
commit d2c1284459
4 changed files with 86 additions and 13 deletions

View File

@ -134,6 +134,13 @@ public class ArgumentType {
return new ArgumentParticle(id);
}
/**
* @see ArgumentResourceLocation
*/
public static ArgumentResourceLocation ResourceLocation(@NotNull String id) {
return new ArgumentResourceLocation(id);
}
/**
* @see ArgumentPotionEffect
*/
@ -190,6 +197,13 @@ public class ArgumentType {
return new ArgumentComponent(id);
}
/**
* @see ArgumentUUID
*/
public static ArgumentUUID UUID(@NotNull String id) {
return new ArgumentUUID(id);
}
/**
* @see ArgumentNbtTag
*/

View File

@ -0,0 +1,34 @@
package net.minestom.server.command.builder.arguments.minecraft;
import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.command.builder.arguments.Argument;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
public class ArgumentResourceLocation extends Argument<String> {
public static final int SPACE_ERROR = 1;
public ArgumentResourceLocation(@NotNull String id) {
super(id);
}
@NotNull
@Override
public String parse(@NotNull String input) throws ArgumentSyntaxException {
if (input.contains(StringUtils.SPACE))
throw new ArgumentSyntaxException("Resource location cannot contain space character", input, SPACE_ERROR);
return input;
}
@Override
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
argumentNode.parser = "minecraft:resource_location";
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
}
}

View File

@ -0,0 +1,36 @@
package net.minestom.server.command.builder.arguments.minecraft;
import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.command.builder.arguments.Argument;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class ArgumentUUID extends Argument<UUID> {
public static final int INVALID_UUID = -1;
public ArgumentUUID(@NotNull String id) {
super(id);
}
@NotNull
@Override
public UUID parse(@NotNull String input) throws ArgumentSyntaxException {
try {
return UUID.fromString(input);
} catch (IllegalArgumentException exception) {
throw new ArgumentSyntaxException("Invalid UUID", input, INVALID_UUID);
}
}
@Override
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
argumentNode.parser = "minecraft:uuid";
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
}
}

View File

@ -14,22 +14,11 @@ public class TestCommand extends Command {
super("testcmd");
setDefaultExecutor(this::usage);
var test1 = Word("msg").setSuggestionCallback((sender, context, suggestion) -> {
suggestion.addEntry(new SuggestionEntry("test"));
});
var test2 = String("msg2").setSuggestionCallback((sender, context, suggestion) -> {
suggestion.addEntry(new SuggestionEntry("greer"));
});
var test = ResourceLocation("msg");
addSyntax((sender, context) -> {
System.out.println("executed");
}, Literal("test"), test1, test2);
addSyntax((sender, context) -> {
System.out.println("cmd syntax");
}, Literal("debug"), Command("cmd").setShortcut("testcmd test"));
},test);
}
private void usage(CommandSender sender, CommandContext context) {