mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Removed longely deprecated Arguments.class
This commit is contained in:
parent
3fa64d6b24
commit
6e9adb2b9b
@ -1,314 +0,0 @@
|
||||
package net.minestom.server.command.builder;
|
||||
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.Enchantment;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.potion.PotionEffect;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
import net.minestom.server.utils.location.RelativeBlockPosition;
|
||||
import net.minestom.server.utils.location.RelativeVec;
|
||||
import net.minestom.server.utils.math.FloatRange;
|
||||
import net.minestom.server.utils.math.IntRange;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @deprecated renamed to {@link CommandContext}
|
||||
*/
|
||||
@Deprecated
|
||||
public class Arguments {
|
||||
|
||||
protected Map<String, Object> args = new HashMap<>();
|
||||
|
||||
private CommandData returnData;
|
||||
|
||||
@NotNull
|
||||
public <T> T get(@NotNull Argument<T> argument) {
|
||||
return get(argument.getId());
|
||||
}
|
||||
|
||||
public <T> T get(@NotNull String identifier) {
|
||||
return (T) args.computeIfAbsent(identifier, s -> {
|
||||
throw new NullPointerException(
|
||||
"The argument with the id '" + identifier + "' has no value assigned, be sure to check your arguments id, your syntax, and that you do not change the argument id dynamically.");
|
||||
});
|
||||
}
|
||||
|
||||
public boolean has(@NotNull Argument<?> argument) {
|
||||
return args.containsKey(argument.getId());
|
||||
}
|
||||
|
||||
public boolean has(@NotNull String identifier) {
|
||||
return args.containsKey(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean getBoolean(@NotNull String id) {
|
||||
return (boolean) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public long getLong(@NotNull String id) {
|
||||
return (long) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getInteger(@NotNull String id) {
|
||||
return (int) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public double getDouble(@NotNull String id) {
|
||||
return (double) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public float getFloat(@NotNull String id) {
|
||||
return (float) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public String getString(@NotNull String id) {
|
||||
return (String) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public String getWord(@NotNull String id) {
|
||||
return getString(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public String[] getStringArray(@NotNull String id) {
|
||||
return (String[]) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public ChatColor getColor(@NotNull String id) {
|
||||
return (ChatColor) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public UpdateOption getTime(@NotNull String id) {
|
||||
return (UpdateOption) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public Enchantment getEnchantment(@NotNull String id) {
|
||||
return (Enchantment) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public Particle getParticle(@NotNull String id) {
|
||||
return (Particle) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public PotionEffect getPotionEffect(@NotNull String id) {
|
||||
return (PotionEffect) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public EntityType getEntityType(@NotNull String id) {
|
||||
return (EntityType) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public Block getBlockState(@NotNull String id) {
|
||||
return (Block) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public IntRange getIntRange(@NotNull String id) {
|
||||
return (IntRange) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public FloatRange getFloatRange(@NotNull String id) {
|
||||
return (FloatRange) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public EntityFinder getEntities(@NotNull String id) {
|
||||
return (EntityFinder) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public ItemStack getItemStack(@NotNull String id) {
|
||||
return (ItemStack) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public NBTCompound getNbtCompound(@NotNull String id) {
|
||||
return (NBTCompound) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public NBT getNBT(@NotNull String id) {
|
||||
return (NBT) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public RelativeBlockPosition getRelativeBlockPosition(@NotNull String id) {
|
||||
return (RelativeBlockPosition) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(Argument)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public RelativeVec getRelativeVector(@NotNull String id) {
|
||||
return (RelativeVec) getObject(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #get(String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public Object getObject(@NotNull String id) {
|
||||
return args.computeIfAbsent(id, s -> {
|
||||
throw new NullPointerException(
|
||||
"The argument with the id '" + id + "' has no value assigned, be sure to check your arguments id, your syntax, and that you do not change the argument id dynamically.");
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CommandData getReturnData() {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public void setReturnData(@Nullable CommandData returnData) {
|
||||
this.returnData = returnData;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Object> getMap() {
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link CommandContext#setArg(String, Object, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setArg(@NotNull String id, Object value) {
|
||||
this.args.put(id, value);
|
||||
}
|
||||
|
||||
public void copy(@NotNull Arguments arguments) {
|
||||
this.args = arguments.args;
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
this.args.clear();
|
||||
}
|
||||
|
||||
protected void retrieveDefaultValues(@Nullable Map<String, Supplier<Object>> defaultValuesMap) {
|
||||
if (defaultValuesMap == null)
|
||||
return;
|
||||
|
||||
for (Map.Entry<String, Supplier<Object>> entry : defaultValuesMap.entrySet()) {
|
||||
final String key = entry.getKey();
|
||||
if (!args.containsKey(key)) {
|
||||
final var supplier = entry.getValue();
|
||||
this.args.put(key, supplier.get());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -3,9 +3,11 @@ package net.minestom.server.command.builder;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Class used to retrieve argument data in a {@link CommandExecutor}.
|
||||
@ -16,34 +18,69 @@ import java.util.Map;
|
||||
* is called, it means that all of its arguments are correct. Be aware that trying to retrieve an argument not present
|
||||
* in the syntax will result in a {@link NullPointerException}.
|
||||
*/
|
||||
public class CommandContext extends Arguments {
|
||||
public class CommandContext {
|
||||
|
||||
private final String input;
|
||||
private final String commandName;
|
||||
private final Map<String, String> rawArgs = new HashMap<>();
|
||||
protected Map<String, Object> args = new HashMap<>();
|
||||
protected Map<String, String> rawArgs = new HashMap<>();
|
||||
private CommandData returnData;
|
||||
|
||||
public CommandContext(@NotNull String input) {
|
||||
this.input = input;
|
||||
this.commandName = input.split(StringUtils.SPACE)[0];
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getInput() {
|
||||
public @NotNull String getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getCommandName() {
|
||||
public @NotNull String getCommandName() {
|
||||
return commandName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public <T> T getRaw(@NotNull Argument<T> argument) {
|
||||
public <T> T get(@NotNull Argument<T> argument) {
|
||||
return get(argument.getId());
|
||||
}
|
||||
|
||||
public <T> T getRaw(@NotNull String identifier) {
|
||||
return (T) rawArgs.computeIfAbsent(identifier, s -> {
|
||||
public <T> T get(@NotNull String identifier) {
|
||||
return (T) args.computeIfAbsent(identifier, s -> {
|
||||
throw new NullPointerException(
|
||||
"The argument with the id '" + identifier + "' has no value assigned, be sure to check your arguments id, your syntax, and that you do not change the argument id dynamically.");
|
||||
});
|
||||
}
|
||||
|
||||
public boolean has(@NotNull Argument<?> argument) {
|
||||
return args.containsKey(argument.getId());
|
||||
}
|
||||
|
||||
public boolean has(@NotNull String identifier) {
|
||||
return args.containsKey(identifier);
|
||||
}
|
||||
|
||||
public @Nullable CommandData getReturnData() {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public void setReturnData(@Nullable CommandData returnData) {
|
||||
this.returnData = returnData;
|
||||
}
|
||||
|
||||
public @NotNull Map<String, Object> getMap() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public void copy(@NotNull CommandContext context) {
|
||||
this.args = context.args;
|
||||
this.rawArgs = context.rawArgs;
|
||||
}
|
||||
|
||||
public String getRaw(@NotNull Argument<?> argument) {
|
||||
return rawArgs.get(argument.getId());
|
||||
}
|
||||
|
||||
public String getRaw(@NotNull String identifier) {
|
||||
return rawArgs.computeIfAbsent(identifier, s -> {
|
||||
throw new NullPointerException(
|
||||
"The argument with the id '" + identifier + "' has no value assigned, be sure to check your arguments id, your syntax, and that you do not change the argument id dynamically.");
|
||||
});
|
||||
@ -54,5 +91,21 @@ public class CommandContext extends Arguments {
|
||||
this.rawArgs.put(id, rawInput);
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
this.args.clear();
|
||||
}
|
||||
|
||||
protected void retrieveDefaultValues(@Nullable Map<String, Supplier<Object>> defaultValuesMap) {
|
||||
if (defaultValuesMap == null)
|
||||
return;
|
||||
|
||||
for (Map.Entry<String, Supplier<Object>> entry : defaultValuesMap.entrySet()) {
|
||||
final String key = entry.getKey();
|
||||
if (!args.containsKey(key)) {
|
||||
final var supplier = entry.getValue();
|
||||
this.args.put(key, supplier.get());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user