From 6e9adb2b9b2bea41bd72661219fb1db858a3ac7e Mon Sep 17 00:00:00 2001 From: TheMode Date: Sat, 1 May 2021 20:20:23 +0200 Subject: [PATCH] Removed longely deprecated Arguments.class --- .../server/command/builder/Arguments.java | 314 ------------------ .../command/builder/CommandContext.java | 73 +++- 2 files changed, 63 insertions(+), 324 deletions(-) delete mode 100644 src/main/java/net/minestom/server/command/builder/Arguments.java diff --git a/src/main/java/net/minestom/server/command/builder/Arguments.java b/src/main/java/net/minestom/server/command/builder/Arguments.java deleted file mode 100644 index e10f26ddc..000000000 --- a/src/main/java/net/minestom/server/command/builder/Arguments.java +++ /dev/null @@ -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 args = new HashMap<>(); - - private CommandData returnData; - - @NotNull - public T get(@NotNull Argument argument) { - return get(argument.getId()); - } - - public 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 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> defaultValuesMap) { - if (defaultValuesMap == null) - return; - - for (Map.Entry> entry : defaultValuesMap.entrySet()) { - final String key = entry.getKey(); - if (!args.containsKey(key)) { - final var supplier = entry.getValue(); - this.args.put(key, supplier.get()); - - } - } - - } -} diff --git a/src/main/java/net/minestom/server/command/builder/CommandContext.java b/src/main/java/net/minestom/server/command/builder/CommandContext.java index 1e1207c23..4eedfef6b 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandContext.java +++ b/src/main/java/net/minestom/server/command/builder/CommandContext.java @@ -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 rawArgs = new HashMap<>(); + protected Map args = new HashMap<>(); + protected Map 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 getRaw(@NotNull Argument argument) { + public T get(@NotNull Argument argument) { return get(argument.getId()); } - public T getRaw(@NotNull String identifier) { - return (T) rawArgs.computeIfAbsent(identifier, s -> { + public 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 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> defaultValuesMap) { + if (defaultValuesMap == null) + return; + + for (Map.Entry> entry : defaultValuesMap.entrySet()) { + final String key = entry.getKey(); + if (!args.containsKey(key)) { + final var supplier = entry.getValue(); + this.args.put(key, supplier.get()); + + } + } + } }