diff --git a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java index 2b32ffa00..6f67e767a 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java @@ -226,7 +226,6 @@ public abstract class Argument { * @param suggestionCallback The suggestion callback to set. * @return 'this' for chaining */ - @Beta public Argument setSuggestionCallback(@NotNull SuggestionCallback suggestionCallback) { this.suggestionCallback = suggestionCallback; return this; diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java deleted file mode 100644 index c9084f849..000000000 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java +++ /dev/null @@ -1,72 +0,0 @@ -package net.minestom.server.command.builder.arguments; - -import net.minestom.server.command.CommandSender; -import net.minestom.server.command.builder.NodeMaker; -import net.minestom.server.command.builder.exception.ArgumentSyntaxException; -import net.minestom.server.command.builder.suggestion.SuggestionCallback; -import net.minestom.server.network.packet.server.play.DeclareCommandsPacket; -import net.minestom.server.utils.binary.BinaryWriter; -import net.minestom.server.utils.callback.validator.StringArrayValidator; -import net.minestom.server.utils.StringUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Same as {@link ArgumentStringArray} with the exception - * that this argument can trigger {@link net.minestom.server.command.builder.Command#onDynamicWrite(CommandSender, String)}. - * - * @deprecated Use {@link Argument#setSuggestionCallback(SuggestionCallback)} with any argument type you want - */ -@Deprecated -public class ArgumentDynamicStringArray extends Argument { - - public static final int RESTRICTION_ERROR = 1; - - private StringArrayValidator dynamicRestriction; - - public ArgumentDynamicStringArray(String id) { - super(id, true, true); - } - - @NotNull - @Override - public String[] parse(@NotNull String input) throws ArgumentSyntaxException { - final String[] value = input.split(StringUtils.SPACE); - - // true if 'value' is valid based on the dynamic restriction - final boolean restrictionCheck = dynamicRestriction == null || dynamicRestriction.isValid(value); - - if (!restrictionCheck) { - throw new ArgumentSyntaxException("Argument does not respect the dynamic restriction", input, RESTRICTION_ERROR); - } - - return value; - } - - @Override - public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) { - DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, true); - - argumentNode.parser = "brigadier:string"; - argumentNode.properties = BinaryWriter.makeArray(packetWriter -> { - packetWriter.writeVarInt(2); // Greedy phrase - }); - argumentNode.suggestionsType = "minecraft:ask_server"; - - nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode}); - } - - /** - * Sets the dynamic restriction of this dynamic argument. - *

- * Will be called once the argument condition is checked. - * - * @param dynamicRestriction the dynamic restriction, can be null to disable - * @return 'this' for chaining - */ - public ArgumentDynamicStringArray fromRestrictions(@Nullable StringArrayValidator dynamicRestriction) { - this.dynamicRestriction = dynamicRestriction; - return this; - } - -} diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java deleted file mode 100644 index 2143e83e5..000000000 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java +++ /dev/null @@ -1,93 +0,0 @@ -package net.minestom.server.command.builder.arguments; - -import net.minestom.server.command.CommandSender; -import net.minestom.server.command.builder.NodeMaker; -import net.minestom.server.command.builder.arguments.minecraft.SuggestionType; -import net.minestom.server.command.builder.exception.ArgumentSyntaxException; -import net.minestom.server.command.builder.suggestion.SuggestionCallback; -import net.minestom.server.network.packet.server.play.DeclareCommandsPacket; -import net.minestom.server.utils.StringUtils; -import net.minestom.server.utils.binary.BinaryWriter; -import net.minestom.server.utils.callback.validator.StringValidator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Same as {@link ArgumentWord} with the exception - * that this argument can trigger {@link net.minestom.server.command.builder.Command#onDynamicWrite(CommandSender, String)} - * when the suggestion type is {@link SuggestionType#ASK_SERVER}, or any other suggestions available in the enum. - * - * @deprecated Use {@link Argument#setSuggestionCallback(SuggestionCallback)} with any argument type you want - */ -@Deprecated -public class ArgumentDynamicWord extends Argument { - - public static final int SPACE_ERROR = 1; - public static final int RESTRICTION_ERROR = 2; - - private final SuggestionType suggestionType; - - private StringValidator dynamicRestriction; - - public ArgumentDynamicWord(@NotNull String id, @NotNull SuggestionType suggestionType) { - super(id); - this.suggestionType = suggestionType; - } - - @NotNull - @Override - public String parse(@NotNull String input) throws ArgumentSyntaxException { - if (input.contains(StringUtils.SPACE)) - throw new ArgumentSyntaxException("Word cannot contain space characters", input, SPACE_ERROR); - - // true if 'value' is valid based on the dynamic restriction - final boolean restrictionCheck = dynamicRestriction == null || dynamicRestriction.isValid(input); - - if (!restrictionCheck) { - throw new ArgumentSyntaxException("Word does not respect the dynamic restriction", input, RESTRICTION_ERROR); - } - - return input; - } - - @Override - public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) { - DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, true); - - final SuggestionType suggestionType = this.getSuggestionType(); - - argumentNode.parser = "brigadier:string"; - argumentNode.properties = BinaryWriter.makeArray(packetWriter -> { - packetWriter.writeVarInt(0); // Single word - }); - argumentNode.suggestionsType = suggestionType.getIdentifier(); - - nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode}); - } - - /** - * Gets the suggestion type of this argument. - *

- * Suggestions are only suggestion, this means that the end value could not be the expected one. - * - * @return this argument suggestion type - */ - @NotNull - public SuggestionType getSuggestionType() { - return suggestionType; - } - - /** - * Sets the dynamic restriction of this dynamic argument. - *

- * Will be called once the argument condition is checked. - * - * @param dynamicRestriction the dynamic restriction, can be null to disable - * @return 'this' for chaining - */ - @NotNull - public ArgumentDynamicWord fromRestrictions(@Nullable StringValidator dynamicRestriction) { - this.dynamicRestriction = dynamicRestriction; - return this; - } -} diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java index ef04d815e..16eaf03f3 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java @@ -270,31 +270,4 @@ public class ArgumentType { public static ArgumentEntity Entities(@NotNull String id) { return new ArgumentEntity(id); } - - /** - * @see ArgumentDynamicWord - * @deprecated will be replaced soon - */ - @Deprecated - public static ArgumentDynamicWord DynamicWord(@NotNull String id, @NotNull SuggestionType suggestionType) { - return new ArgumentDynamicWord(id, suggestionType); - } - - /** - * @see ArgumentDynamicWord - * @deprecated will be replaced soon - */ - @Deprecated - public static ArgumentDynamicWord DynamicWord(@NotNull String id) { - return DynamicWord(id, SuggestionType.ASK_SERVER); - } - - /** - * @see ArgumentDynamicStringArray - * @deprecated will be replaced soon - */ - @Deprecated - public static ArgumentDynamicStringArray DynamicStringArray(@NotNull String id) { - return new ArgumentDynamicStringArray(id); - } }