mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 18:32:28 +01:00
Remove deprecated DynamicWords
This commit is contained in:
parent
d1babd25dc
commit
b8c1e72e4a
@ -226,7 +226,6 @@ public abstract class Argument<T> {
|
||||
* @param suggestionCallback The suggestion callback to set.
|
||||
* @return 'this' for chaining
|
||||
*/
|
||||
@Beta
|
||||
public Argument<T> setSuggestionCallback(@NotNull SuggestionCallback suggestionCallback) {
|
||||
this.suggestionCallback = suggestionCallback;
|
||||
return this;
|
||||
|
@ -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<String[]> {
|
||||
|
||||
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.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<String> {
|
||||
|
||||
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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user