diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java index 3a50a140..f000526c 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/ServerBot.java @@ -84,7 +84,7 @@ import java.util.function.Predicate; public class ServerBot extends ServerPlayer { private final List> actions; - private final Map> configs; + private final Map> configs; public boolean resume = false; public BotCreateState createState; @@ -106,8 +106,8 @@ public class ServerBot extends ServerPlayer { this.gameMode = new ServerBotGameMode(this); this.actions = new ArrayList<>(); - ImmutableMap.Builder> configBuilder = ImmutableMap.builder(); - for (AbstractBotConfig config : Configs.getConfigs()) { + ImmutableMap.Builder> configBuilder = ImmutableMap.builder(); + for (AbstractBotConfig config : Configs.getConfigs()) { configBuilder.put(config.getName(), config.create().setBot(this)); } this.configs = configBuilder.build(); @@ -395,7 +395,7 @@ public class ServerBot extends ServerPlayer { if (!this.configs.isEmpty()) { ValueOutput.TypedOutputList configNbt = nbt.list("configs", CompoundTag.CODEC); - for (AbstractBotConfig config : this.configs.values()) { + for (AbstractBotConfig config : this.configs.values()) { configNbt.add(config.save(new CompoundTag())); } } @@ -440,7 +440,7 @@ public class ServerBot extends ServerPlayer { if (nbt.list("configs", CompoundTag.CODEC).isPresent()) { ValueInput.TypedInputList configNbt = nbt.list("configs", CompoundTag.CODEC).orElseThrow(); for (CompoundTag configTag : configNbt) { - AbstractBotConfig config = Configs.getConfig(configTag.getString("configName").orElseThrow()); + AbstractBotConfig config = Configs.getConfig(configTag.getString("configName").orElseThrow()); if (config != null) { config.load(configTag); } @@ -669,15 +669,15 @@ public class ServerBot extends ServerPlayer { } @SuppressWarnings("unchecked") - public > AbstractBotConfig getConfig(@NotNull AbstractBotConfig config) { - return (AbstractBotConfig) Objects.requireNonNull(this.configs.get(config.getName())); + public > AbstractBotConfig getConfig(@NotNull AbstractBotConfig config) { + return (AbstractBotConfig) Objects.requireNonNull(this.configs.get(config.getName())); } - public Collection> getAllConfigs() { + public Collection> getAllConfigs() { return configs.values(); } - public > O getConfigValue(@NotNull AbstractBotConfig config) { + public > T getConfigValue(@NotNull AbstractBotConfig config) { return this.getConfig(config).getValue(); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Configs.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Configs.java index 056c1cbf..602aff02 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Configs.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Configs.java @@ -17,7 +17,7 @@ import java.util.Map; @SuppressWarnings({"unused"}) public class Configs { - private static final Map, AbstractBotConfig> configs = new HashMap<>(); + private static final Map, AbstractBotConfig> configs = new HashMap<>(); public static final SkipSleepConfig SKIP_SLEEP = register(new SkipSleepConfig()); public static final AlwaysSendDataConfig ALWAYS_SEND_DATA = register(new AlwaysSendDataConfig()); @@ -27,7 +27,7 @@ public class Configs { public static final LocatorBarConfig ENABLE_LOCATOR_BAR = register(new LocatorBarConfig()); @Nullable - public static AbstractBotConfig getConfig(String name) { + public static AbstractBotConfig getConfig(String name) { return configs.values().stream() .filter(config -> config.getName().equals(name)) .findFirst() @@ -36,12 +36,12 @@ public class Configs { @NotNull @Contract(pure = true) - public static Collection> getConfigs() { + public static Collection> getConfigs() { return configs.values(); } @SuppressWarnings("unchecked") - private static > @NotNull E register(AbstractBotConfig instance) { + private static > @NotNull E register(AbstractBotConfig instance) { configs.put(instance.getClass(), instance); return (E) instance; } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerLookAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerLookAction.java index a003bd51..8333826d 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerLookAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerLookAction.java @@ -1,15 +1,15 @@ package org.leavesmc.leaves.bot.agent.actions; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.commands.arguments.coordinates.Coordinates; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; -import net.minecraft.commands.arguments.selector.EntitySelector; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver; +import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.phys.Vec3; +import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.Entity; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.bot.ServerBot; @@ -25,25 +25,28 @@ public class ServerLookAction extends AbstractBotAction { public ServerLookAction() { super("look", ServerLookAction::new); - this.addArgument("player", EntityArgument.player()).setOptional(true); + this.addArgument("player", ArgumentTypes.player()).setOptional(true); this.fork(1); - this.addArgument("location", Vec3Argument.vec3(false)); + this.addArgument("location", ArgumentTypes.finePosition()); } @Override public void loadCommand(@NotNull CommandContext context) throws CommandSyntaxException { - EntitySelector selector = context.getArgumentOrDefault("player", EntitySelector.class, null); - Coordinates location = context.getArgumentOrDefault("location", Coordinates.class, null); + PlayerSelectorArgumentResolver playerSelectorResolver = context.getArgumentOrDefault("player", PlayerSelectorArgumentResolver.class, null); + FinePositionResolver positionResolver = context.getArgumentOrDefault("location", FinePositionResolver.class, null); CommandSourceStack source = context.getSource(); - if (selector == null && location == null) { - Entity sender = source.getEntityOrException(); - this.setPos(new Vector(sender.getX(), sender.getY(), sender.getZ())); - } else if (selector != null) { - ServerPlayer player = selector.findSinglePlayer(source); - this.setTarget(player); + if (playerSelectorResolver == null && positionResolver == null) { + CommandSender sender = context.getSender(); + if (sender instanceof Entity entity) { + this.setPos(entity.getLocation().toVector()); + } else { + throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().create(); + } + } else if (playerSelectorResolver != null) { + CraftPlayer player = (CraftPlayer) playerSelectorResolver.resolve(source).getFirst(); + this.setTarget(player.getHandle()); } else { - Vec3 vector = location.getPosition(source); - this.setPos(new Vector(vector.x, vector.y, vector.z)); + this.setPos(positionResolver.resolve(source).toVector()); } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerMoveAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerMoveAction.java index 8da91cff..4023b469 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerMoveAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerMoveAction.java @@ -1,42 +1,25 @@ package org.leavesmc.leaves.bot.agent.actions; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.bot.agent.ExtraData; import org.leavesmc.leaves.command.CommandContext; +import org.leavesmc.leaves.command.arguments.EnumArgumentType; import org.leavesmc.leaves.entity.bot.action.MoveAction.MoveDirection; import org.leavesmc.leaves.entity.bot.actions.CraftMoveAction; import org.leavesmc.leaves.event.bot.BotActionStopEvent; -import java.util.Arrays; -import java.util.Map; - -import static java.util.stream.Collectors.toMap; -import static org.leavesmc.leaves.command.ArgumentNode.ArgumentSuggestions.strings; - public class ServerMoveAction extends AbstractStateBotAction { - private static final Map NAME_TO_DIRECTION = Arrays.stream(MoveDirection.values()).collect(toMap( - it -> it.name, - it -> it - )); private MoveDirection direction = MoveDirection.FORWARD; public ServerMoveAction() { super("move", ServerMoveAction::new); - this.addArgument("direction", StringArgumentType.word()) - .suggests(strings(Arrays.stream(MoveDirection.values()).map((it) -> it.name).toList())); + this.addArgument("direction", EnumArgumentType.fromEnum(MoveDirection.class)); } @Override - public void loadCommand(@NotNull CommandContext context) throws CommandSyntaxException { - String raw = context.getArgument("direction", String.class); - MoveDirection direction = NAME_TO_DIRECTION.get(raw); - if (direction == null) { - throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().create(); - } - this.direction = direction; + public void loadCommand(@NotNull CommandContext context) { + this.direction = context.getArgument("direction", MoveDirection.class); } @Override diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerRotationAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerRotationAction.java index 04dc0d6f..85f51064 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerRotationAction.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerRotationAction.java @@ -1,9 +1,10 @@ package org.leavesmc.leaves.bot.agent.actions; import com.mojang.brigadier.arguments.FloatArgumentType; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.bot.agent.ExtraData; @@ -19,16 +20,26 @@ public class ServerRotationAction extends AbstractBotAction builder.suggest( - DF.format(context.getSource().getEntityOrException().getYRot()), - Component.literal("current player yaw") - )) + .suggests((context, builder) -> { + CommandSender sender = context.getSender(); + if (sender instanceof Entity entity) { + builder.suggest( + DF.format(entity.getYaw()), + Component.literal("current player yaw") + ); + } + }) .setOptional(true); this.addArgument("pitch", FloatArgumentType.floatArg(-90, 90)) - .suggests((context, builder) -> builder.suggest( - DF.format(context.getSource().getEntityOrException().getXRot()), - Component.literal("current player pitch") - )) + .suggests((context, builder) -> { + CommandSender sender = context.getSender(); + if (sender instanceof Entity entity) { + builder.suggest( + DF.format(entity.getPitch()), + Component.literal("current player pitch") + ); + } + }) .setOptional(true); } @@ -36,9 +47,14 @@ public class ServerRotationAction extends AbstractBotAction> { +public abstract class AbstractBotConfig> { private final String name; - private final WrappedArgument argument; + private final WrappedArgument argument; private final Supplier creator; protected ServerBot bot; - public AbstractBotConfig(String name, ArgumentType type, Supplier creator) { + public AbstractBotConfig(String name, ArgumentType type, Supplier creator) { this.name = name; this.argument = new WrappedArgument<>(name, type); if (shouldApplySuggestions()) { @@ -37,7 +37,7 @@ public abstract class AbstractBotConfig setBot(ServerBot bot) { + public AbstractBotConfig setBot(ServerBot bot) { this.bot = bot; return this; } @@ -46,11 +46,11 @@ public abstract class AbstractBotConfig getArgument() { + public WrappedArgument getArgument() { return argument; } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java index 01c2ac71..59ba3583 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/AlwaysSendDataConfig.java @@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.command.CommandContext; -public class AlwaysSendDataConfig extends AbstractBotConfig { +public class AlwaysSendDataConfig extends AbstractBotConfig { private boolean value; public AlwaysSendDataConfig() { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/LocatorBarConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/LocatorBarConfig.java index 2a81bad7..cfb94613 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/LocatorBarConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/LocatorBarConfig.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.command.CommandContext; -public class LocatorBarConfig extends AbstractBotConfig { +public class LocatorBarConfig extends AbstractBotConfig { private boolean value; public LocatorBarConfig() { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SimulationDistanceConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SimulationDistanceConfig.java index 75d3f481..042064c7 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SimulationDistanceConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SimulationDistanceConfig.java @@ -9,7 +9,7 @@ import org.leavesmc.leaves.command.CommandContext; import static net.minecraft.network.chat.Component.literal; -public class SimulationDistanceConfig extends AbstractBotConfig { +public class SimulationDistanceConfig extends AbstractBotConfig { public SimulationDistanceConfig() { super("simulation_distance", IntegerArgumentType.integer(2, 32), SimulationDistanceConfig::new); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java index 5577ce2d..9580313a 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SkipSleepConfig.java @@ -6,7 +6,7 @@ import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.command.CommandContext; -public class SkipSleepConfig extends AbstractBotConfig { +public class SkipSleepConfig extends AbstractBotConfig { public SkipSleepConfig() { super("skip_sleep", BoolArgumentType.bool(), SkipSleepConfig::new); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java index 49257361..f155beda 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/SpawnPhantomConfig.java @@ -7,7 +7,7 @@ import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.bot.agent.ExtraData; import org.leavesmc.leaves.command.CommandContext; -public class SpawnPhantomConfig extends AbstractBotConfig { +public class SpawnPhantomConfig extends AbstractBotConfig { private boolean value; public SpawnPhantomConfig() { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/TickTypeConfig.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/TickTypeConfig.java index 109d9930..f3fb34a7 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/TickTypeConfig.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/configs/TickTypeConfig.java @@ -1,36 +1,23 @@ package org.leavesmc.leaves.bot.agent.configs; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.nbt.CompoundTag; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.command.CommandContext; +import org.leavesmc.leaves.command.arguments.EnumArgumentType; -public class TickTypeConfig extends AbstractBotConfig { +public class TickTypeConfig extends AbstractBotConfig { private ServerBot.TickType value; public TickTypeConfig() { - super("tick_type", StringArgumentType.word(), TickTypeConfig::new); + super("tick_type", EnumArgumentType.fromEnum(ServerBot.TickType.class), TickTypeConfig::new); this.value = LeavesConfig.modify.fakeplayer.inGame.tickType; } @Override - public void applySuggestions(CommandContext context, @NotNull SuggestionsBuilder builder) { - builder.suggest("network"); - builder.suggest("entity_list"); - } - - @Override - public ServerBot.TickType loadFromCommand(@NotNull CommandContext context) throws CommandSyntaxException { - String raw = context.getString(getName()); - return switch (raw) { - case "network" -> ServerBot.TickType.NETWORK; - case "entity_list" -> ServerBot.TickType.ENTITY_LIST; - default -> throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().create(); - }; + public ServerBot.TickType loadFromCommand(@NotNull CommandContext context) { + return context.getArgument("tick_type", ServerBot.TickType.class); } @Override diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/ArgumentNode.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/ArgumentNode.java index c0e73f8c..dc134eed 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/ArgumentNode.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/ArgumentNode.java @@ -6,8 +6,8 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandContext.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandContext.java index 8d572553..21dee9f9 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandContext.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandContext.java @@ -4,9 +4,8 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.RedirectModifier; import com.mojang.brigadier.context.ParsedCommandNode; import com.mojang.brigadier.context.StringRange; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -64,13 +63,6 @@ public class CommandContext { return (V) source.getArgument(name, Object.class); } - @SuppressWarnings("unchecked") - public @NotNull V getCustomArgument(final Class> nodeClass) throws CommandSyntaxException { - String name = getNameForNode(nodeClass); - T raw = (T) source.getArgument(name, Object.class); - return CustomArgumentNode.transform(nodeClass, raw); - } - public V getArgumentOrDefault(final Class> nodeClass, final V defaultValue) { try { return getArgument(nodeClass); @@ -87,14 +79,6 @@ public class CommandContext { } } - public V getCustomArgumentOrDefault(final Class> nodeClass, final V defaultValue) throws CommandSyntaxException { - try { - return getCustomArgument(nodeClass); - } catch (IllegalArgumentException e) { - return defaultValue; - } - } - public String getStringOrDefault(final String name, final String defaultValue) { return getArgumentOrDefault(name, String.class, defaultValue); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandNode.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandNode.java index 033dcc97..3a640364 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandNode.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandNode.java @@ -2,7 +2,7 @@ package org.leavesmc.leaves.command; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandUtils.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandUtils.java index a270312f..bdf3d41c 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandUtils.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/CommandUtils.java @@ -40,7 +40,7 @@ public class CommandUtils { } @DefaultQualifier(NonNull.class) - public static @NotNull List getListClosestMatchingLast(final String last, final Collection collection) { + public static List getListClosestMatchingLast(final String last, final Collection collection) { if (collection.isEmpty()) { return Collections.emptyList(); } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/CustomArgumentNode.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/CustomArgumentNode.java deleted file mode 100644 index 75188f65..00000000 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/CustomArgumentNode.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.leavesmc.leaves.command; - -import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandSourceStack; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; - -public class CustomArgumentNode extends ArgumentNode { - @SuppressWarnings("rawtypes") - private static final Map, CustomArgumentType> TYPES = new HashMap<>(); - - protected CustomArgumentNode(String name, @NotNull CustomArgumentType argumentType) { - super(name, argumentType.getBaseArgumentType()); - TYPES.put(getClass(), argumentType); - } - - public static T transform(Class> nodeClass, B base) throws CommandSyntaxException { - @SuppressWarnings("unchecked") - CustomArgumentType type = (CustomArgumentType) TYPES.get(nodeClass); - if (type == null) { - throw new IllegalArgumentException("No custom argument type registered for " + nodeClass.getName()); - } - return type.transform(base); - } - - @Override - @SuppressWarnings("unchecked") - protected ArgumentBuilder compileBase() { - RequiredArgumentBuilder argumentBuilder = (RequiredArgumentBuilder) super.compileBase(); - - if (!overrideSuggestions()) { - CustomArgumentType customArgumentType = (CustomArgumentType) TYPES.get(getClass()); - argumentBuilder.suggests( - (context, builder) -> customArgumentType.getSuggestions(new CommandContext(context), builder) - ); - } - - return argumentBuilder; - } -} diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/CustomArgumentType.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/CustomArgumentType.java deleted file mode 100644 index 86d3c5f6..00000000 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/CustomArgumentType.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.leavesmc.leaves.command; - -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; - -import java.util.concurrent.CompletableFuture; - -public interface CustomArgumentType { - ArgumentType getBaseArgumentType(); - - T transform(B value) throws CommandSyntaxException; - - CompletableFuture getSuggestions(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException; -} diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/LiteralNode.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/LiteralNode.java index 57f8fd9d..340f389c 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/LiteralNode.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/LiteralNode.java @@ -1,8 +1,8 @@ package org.leavesmc.leaves.command; import com.mojang.brigadier.builder.ArgumentBuilder; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; public class LiteralNode extends CommandNode { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/RootNode.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/RootNode.java index 22d2b1e6..b2805c6e 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/RootNode.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/RootNode.java @@ -1,10 +1,9 @@ package org.leavesmc.leaves.command; -import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.server.MinecraftServer; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.PaperCommands; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -36,18 +35,16 @@ public abstract class RootNode extends LiteralNode { @SuppressWarnings("unchecked") public void register() { - MinecraftServer.getServer() - .getCommands() - .getDispatcher() - .register((LiteralArgumentBuilder) compile()); + PaperCommands.INSTANCE.setValid(); + PaperCommands.INSTANCE.getDispatcher().register((LiteralArgumentBuilder) compile()); + PaperCommands.INSTANCE.invalidate(); Bukkit.getOnlinePlayers().forEach(org.bukkit.entity.Player::updateCommands); } public void unregister() { - CommandDispatcher dispatcher = MinecraftServer.getServer() - .getCommands() - .getDispatcher(); - dispatcher.getRoot().removeCommand(name); + PaperCommands.INSTANCE.setValid(); + PaperCommands.INSTANCE.getDispatcher().getRoot().removeCommand(name); + PaperCommands.INSTANCE.invalidate(); Bukkit.getOnlinePlayers().forEach(org.bukkit.entity.Player::updateCommands); } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/WrappedArgument.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/WrappedArgument.java index e41eb5c8..0c3326fb 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/WrappedArgument.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/WrappedArgument.java @@ -5,8 +5,8 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.Commands; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; import java.util.concurrent.CompletableFuture; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotArgument.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/arguments/BotArgumentType.java similarity index 62% rename from leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotArgument.java rename to leaves-server/src/main/java/org/leavesmc/leaves/command/arguments/BotArgumentType.java index ea55e25a..dff8c5ea 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotArgument.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/arguments/BotArgumentType.java @@ -1,39 +1,23 @@ -package org.leavesmc.leaves.command.bot; +package org.leavesmc.leaves.command.arguments; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.bot.BotList; import org.leavesmc.leaves.bot.ServerBot; -import org.leavesmc.leaves.command.CommandContext; -import org.leavesmc.leaves.command.CustomArgumentType; import java.util.Collection; import java.util.concurrent.CompletableFuture; -public class BotArgument implements CustomArgumentType { - @Override - public ArgumentType getBaseArgumentType() { - return StringArgumentType.word(); - } +public class BotArgumentType implements CustomArgumentType.Converted<@NotNull ServerBot, @NotNull String> { @Override - public ServerBot transform(String value) throws CommandSyntaxException { - ServerBot bot = BotList.INSTANCE.getBotByName(value); - if (bot == null) { - throw new CommandSyntaxException( - CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument(), - Component.literal("Bot with name '" + value + "' does not exist") - ); - } - return bot; - } - - @Override - public CompletableFuture getSuggestions(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { + public @NotNull CompletableFuture listSuggestions(com.mojang.brigadier.context.@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) { Collection bots = BotList.INSTANCE.bots; if (bots.isEmpty()) { return builder @@ -43,4 +27,21 @@ public class BotArgument implements CustomArgumentType { bots.stream().map(ServerBot::getScoreboardName).forEach(builder::suggest); return builder.buildFuture(); } + + @Override + public ServerBot convert(String nativeType) throws CommandSyntaxException { + ServerBot bot = BotList.INSTANCE.getBotByName(nativeType); + if (bot == null) { + throw new CommandSyntaxException( + CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument(), + Component.literal("Bot with name '" + nativeType + "' does not exist") + ); + } + return bot; + } + + @Override + public @NotNull ArgumentType<@NotNull String> getNativeType() { + return StringArgumentType.word(); + } } diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/arguments/EnumArgumentType.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/arguments/EnumArgumentType.java new file mode 100644 index 00000000..ef90de03 --- /dev/null +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/arguments/EnumArgumentType.java @@ -0,0 +1,81 @@ +package org.leavesmc.leaves.command.arguments; + +import com.mojang.brigadier.arguments.ArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + +@SuppressWarnings("ClassCanBeRecord") +public final class EnumArgumentType> implements CustomArgumentType.Converted<@NotNull T, @NotNull String> { + private final Class enumClass; + + @Contract(value = "_ -> new", pure = true) + public static > @NotNull EnumArgumentType fromEnum(Class enumClass) { + return new EnumArgumentType<>(enumClass); + } + + private EnumArgumentType(Class enumClass) { + this.enumClass = enumClass; + } + + @Override + public @NotNull T convert(@NotNull String nativeType) throws CommandSyntaxException { + try { + return Enum.valueOf(enumClass, nativeType.toUpperCase()); + } catch (IllegalArgumentException e) { + throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().create(); + } + } + + @Override + public @NotNull CompletableFuture listSuggestions(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) { + for (Enum value : enumClass.getEnumConstants()) { + String name = value.name().toLowerCase(); + if (name.startsWith(builder.getRemainingLowerCase())) { + builder.suggest(name); + } + } + return builder.buildFuture(); + } + + @Override + public @NotNull ArgumentType<@NotNull String> getNativeType() { + return StringArgumentType.word(); + } + + public Class enumClass() { + return enumClass; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj == null || obj.getClass() != this.getClass()) { + return false; + } + EnumArgumentType that = (EnumArgumentType) obj; + return Objects.equals(this.enumClass, that.enumClass); + } + + @Override + public int hashCode() { + return Objects.hash(enumClass); + } + + @Override + public String toString() { + return "EnumArgumentType[" + + "enumClass=" + enumClass + ']'; + } + +} diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotCommand.java index d187e864..758fb015 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotCommand.java @@ -1,7 +1,7 @@ package org.leavesmc.leaves.command.bot; import com.mojang.brigadier.builder.ArgumentBuilder; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.command.RootNode; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotSubcommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotSubcommand.java index 0adae7a1..a46dfcc9 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotSubcommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/BotSubcommand.java @@ -1,6 +1,6 @@ package org.leavesmc.leaves.command.bot; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.command.LiteralNode; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ActionCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ActionCommand.java index 227fbf11..af2c3afd 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ActionCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ActionCommand.java @@ -1,12 +1,12 @@ package org.leavesmc.leaves.command.bot.subcommands; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.bot.ServerBot; +import org.leavesmc.leaves.command.ArgumentNode; import org.leavesmc.leaves.command.CommandContext; -import org.leavesmc.leaves.command.CustomArgumentNode; +import org.leavesmc.leaves.command.arguments.BotArgumentType; import org.leavesmc.leaves.command.bot.BotSubcommand; import org.leavesmc.leaves.command.bot.subcommands.action.ListCommand; import org.leavesmc.leaves.command.bot.subcommands.action.StartCommand; @@ -24,10 +24,10 @@ public class ActionCommand extends BotSubcommand { return LeavesConfig.modify.fakeplayer.canUseAction && super.requires(source); } - public static class BotArgument extends CustomArgumentNode { + public static class BotArgument extends ArgumentNode { private BotArgument() { - super("bot", new org.leavesmc.leaves.command.bot.BotArgument()); + super("bot", new BotArgumentType()); children( StartCommand::new, StopCommand::new, @@ -35,8 +35,8 @@ public class ActionCommand extends BotSubcommand { ); } - public static @NotNull ServerBot getBot(@NotNull CommandContext context) throws CommandSyntaxException { - return context.getCustomArgument(BotArgument.class); + public static @NotNull ServerBot getBot(@NotNull CommandContext context) { + return context.getArgument(BotArgument.class); } } } \ No newline at end of file diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ConfigCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ConfigCommand.java index 10dc2e56..779b2b50 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ConfigCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ConfigCommand.java @@ -3,7 +3,7 @@ package org.leavesmc.leaves.command.bot.subcommands; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -11,9 +11,10 @@ import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.bot.agent.Configs; import org.leavesmc.leaves.bot.agent.configs.AbstractBotConfig; +import org.leavesmc.leaves.command.ArgumentNode; import org.leavesmc.leaves.command.CommandContext; -import org.leavesmc.leaves.command.CustomArgumentNode; import org.leavesmc.leaves.command.LiteralNode; +import org.leavesmc.leaves.command.arguments.BotArgumentType; import org.leavesmc.leaves.command.bot.BotSubcommand; import java.util.Collection; @@ -38,33 +39,33 @@ public class ConfigCommand extends BotSubcommand { return LeavesConfig.modify.fakeplayer.canModifyConfig && super.requires(source); } - private static class BotArgument extends CustomArgumentNode { + private static class BotArgument extends ArgumentNode { private BotArgument() { - super("bot", new org.leavesmc.leaves.command.bot.BotArgument()); + super("bot", new BotArgumentType()); Configs.getConfigs().stream().map(this::configNodeCreator).forEach(this::children); } @Contract(pure = true) - private @NotNull Supplier configNodeCreator(AbstractBotConfig config) { + private @NotNull Supplier configNodeCreator(AbstractBotConfig config) { return () -> new ConfigNode<>(config); } - public static @NotNull ServerBot getBot(@NotNull CommandContext context) throws CommandSyntaxException { - return context.getCustomArgument(BotArgument.class); + public static @NotNull ServerBot getBot(@NotNull CommandContext context) { + return context.getArgument(BotArgument.class); } @Override - protected boolean execute(CommandContext context) throws CommandSyntaxException { + protected boolean execute(CommandContext context) { ServerBot bot = BotArgument.getBot(context); CommandSender sender = context.getSender(); - Collection> botConfigs = bot.getAllConfigs(); + Collection> botConfigs = bot.getAllConfigs(); sender.sendMessage(join(spaces(), text("Bot", GRAY), asAdventure(bot.getDisplayName()).append(text("'s", GRAY)), text("configs:", GRAY) )); - for (AbstractBotConfig botConfig : botConfigs) { + for (AbstractBotConfig botConfig : botConfigs) { sender.sendMessage(join(spaces(), botConfig.getNameComponent(), text("=", GRAY), @@ -75,10 +76,10 @@ public class ConfigCommand extends BotSubcommand { } } - private static class ConfigNode extends LiteralNode { - private final AbstractBotConfig config; + private static class ConfigNode extends LiteralNode { + private final AbstractBotConfig config; - private ConfigNode(@NotNull AbstractBotConfig config) { + private ConfigNode(@NotNull AbstractBotConfig config) { super(config.getName()); this.config = config; } @@ -95,9 +96,9 @@ public class ConfigCommand extends BotSubcommand { } @Override - protected boolean execute(@NotNull CommandContext context) throws CommandSyntaxException { + protected boolean execute(@NotNull CommandContext context) { ServerBot bot = BotArgument.getBot(context); - AbstractBotConfig botConfig = bot.getConfig(config); + AbstractBotConfig botConfig = bot.getConfig(config); context.getSender().sendMessage(join(spaces(), text("Bot", GRAY), asAdventure(bot.getDisplayName()).append(text("'s", GRAY)), @@ -111,7 +112,7 @@ public class ConfigCommand extends BotSubcommand { private boolean executeSet(CommandContext context) throws CommandSyntaxException { ServerBot bot = BotArgument.getBot(context); - AbstractBotConfig botConfig = bot.getConfig(config); + AbstractBotConfig botConfig = bot.getConfig(config); try { botConfig.setValue(botConfig.loadFromCommand(context)); } catch (ClassCastException e) { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/CreateCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/CreateCommand.java index df406a58..3b0ae0cf 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/CreateCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/CreateCommand.java @@ -2,19 +2,17 @@ package org.leavesmc.leaves.command.bot.subcommands; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.resolvers.FinePositionResolver; import net.kyori.adventure.text.format.NamedTextColor; -import net.minecraft.commands.CommandSourceStack; -import net.minecraft.commands.arguments.DimensionArgument; -import net.minecraft.commands.arguments.coordinates.Coordinates; -import net.minecraft.commands.arguments.coordinates.Vec3Argument; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.bot.BotCreateState; @@ -25,7 +23,6 @@ import org.leavesmc.leaves.command.bot.BotSubcommand; import org.leavesmc.leaves.event.bot.BotCreateEvent; import static net.kyori.adventure.text.Component.text; -import static net.minecraft.commands.arguments.DimensionArgument.getDimension; public class CreateCommand extends BotSubcommand { @@ -45,7 +42,7 @@ public class CreateCommand extends BotSubcommand { World world; try { - world = getDimension(context.getMojangContext(), "world").getWorld(); + world = context.getArgument(WorldArgument.class); } catch (IllegalArgumentException e) { if (!(sender instanceof Entity entity)) { sender.sendMessage(text("Must specify world and location when executed by console", NamedTextColor.RED)); @@ -55,10 +52,10 @@ public class CreateCommand extends BotSubcommand { } Location location = Bukkit.getWorlds().getFirst().getSpawnLocation(); - Coordinates coords = context.getArgumentOrDefault(LocationArgument.class, null); - if (coords != null) { - Vec3 vec3 = coords.getPosition(context.getSource()); - location = new Location(world, vec3.x, vec3.y, vec3.z); + FinePositionResolver positionResolver = context.getArgumentOrDefault(LocationArgument.class, null); + if (positionResolver != null) { + Vector vec3 = positionResolver.resolve(context.getSource()).toVector(); + location = new Location(world, vec3.getX(), vec3.getY(), vec3.getZ()); } else if (sender instanceof Entity entity) { location = entity.getLocation(); } @@ -122,9 +119,9 @@ public class CreateCommand extends BotSubcommand { } } - private static class WorldArgument extends ArgumentNode { + private static class WorldArgument extends ArgumentNode { private WorldArgument() { - super("world", DimensionArgument.dimension()); + super("world", ArgumentTypes.world()); children(LocationArgument::new); } @@ -134,9 +131,9 @@ public class CreateCommand extends BotSubcommand { } } - private static class LocationArgument extends ArgumentNode { + private static class LocationArgument extends ArgumentNode { private LocationArgument() { - super("location", Vec3Argument.vec3(true)); + super("location", ArgumentTypes.finePosition()); } @Override diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ListCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ListCommand.java index 3033a84f..3464717d 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ListCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/ListCommand.java @@ -2,10 +2,8 @@ package org.leavesmc.leaves.command.bot.subcommands; import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; import net.kyori.adventure.text.Component; -import net.minecraft.commands.arguments.DimensionArgument; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.player.Player; import org.bukkit.Bukkit; import org.bukkit.World; @@ -28,8 +26,6 @@ import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.JoinConfiguration.noSeparators; import static net.kyori.adventure.text.event.HoverEvent.showText; import static net.kyori.adventure.text.format.NamedTextColor.*; -import static net.minecraft.commands.arguments.DimensionArgument.getDimension; - public class ListCommand extends BotSubcommand { @@ -76,16 +72,16 @@ public class ListCommand extends BotSubcommand { ); } - private static class WorldArgument extends ArgumentNode { + private static class WorldArgument extends ArgumentNode { private WorldArgument() { - super("world", DimensionArgument.dimension()); + super("world", ArgumentTypes.world()); } @Override - protected boolean execute(@NotNull CommandContext context) throws CommandSyntaxException { - ServerLevel dimension = getDimension(context.getMojangContext(), "world"); - Component botListMessage = getBotListMessage(dimension.getWorld()); + protected boolean execute(@NotNull CommandContext context) { + World world = context.getArgument(WorldArgument.class); + Component botListMessage = getBotListMessage(world); CommandSender sender = context.getSender(); if (botListMessage == null) { sender.sendMessage(text("No bots in that world", RED)); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/LoadCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/LoadCommand.java index 699848f6..7a5e3481 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/LoadCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/LoadCommand.java @@ -4,8 +4,8 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import io.papermc.paper.command.brigadier.CommandSourceStack; import net.kyori.adventure.text.format.NamedTextColor; -import net.minecraft.commands.CommandSourceStack; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/RemoveCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/RemoveCommand.java index 09df5362..01225a57 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/RemoveCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/RemoveCommand.java @@ -11,7 +11,7 @@ import org.leavesmc.leaves.bot.BotList; import org.leavesmc.leaves.bot.ServerBot; import org.leavesmc.leaves.command.ArgumentNode; import org.leavesmc.leaves.command.CommandContext; -import org.leavesmc.leaves.command.CustomArgumentNode; +import org.leavesmc.leaves.command.arguments.BotArgumentType; import org.leavesmc.leaves.command.bot.BotSubcommand; import org.leavesmc.leaves.event.bot.BotRemoveEvent; import org.leavesmc.leaves.plugin.MinecraftInternalPlugin; @@ -41,15 +41,15 @@ public class RemoveCommand extends BotSubcommand { return success; } - private static class BotArgument extends CustomArgumentNode { + private static class BotArgument extends ArgumentNode { private BotArgument() { - super("bot", new org.leavesmc.leaves.command.bot.BotArgument()); + super("bot", new BotArgumentType()); children(RemoveTimeArgument::new); } @Override - protected boolean execute(@NotNull CommandContext context) throws CommandSyntaxException { - ServerBot bot = context.getCustomArgument(BotArgument.class); + protected boolean execute(@NotNull CommandContext context) { + ServerBot bot = context.getArgument(BotArgument.class); return removeBot(bot, context.getSender()); } } @@ -64,7 +64,7 @@ public class RemoveCommand extends BotSubcommand { protected boolean execute(@NotNull CommandContext context) throws CommandSyntaxException { String removeTimeStr = context.getArgument("remove_time", String.class); int removeTimeSeconds = parseRemoveTime(removeTimeStr); - ServerBot bot = context.getCustomArgument(BotArgument.class); + ServerBot bot = context.getArgument(BotArgument.class); CommandSender sender = context.getSender(); boolean isReschedule = bot.removeTaskId != -1; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/SaveCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/SaveCommand.java index 218c06da..2d243cb5 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/SaveCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/SaveCommand.java @@ -1,15 +1,15 @@ package org.leavesmc.leaves.command.bot.subcommands; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.papermc.paper.command.brigadier.CommandSourceStack; import net.kyori.adventure.text.format.NamedTextColor; -import net.minecraft.commands.CommandSourceStack; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.LeavesConfig; import org.leavesmc.leaves.bot.BotList; import org.leavesmc.leaves.bot.ServerBot; +import org.leavesmc.leaves.command.ArgumentNode; import org.leavesmc.leaves.command.CommandContext; -import org.leavesmc.leaves.command.CustomArgumentNode; +import org.leavesmc.leaves.command.arguments.BotArgumentType; import org.leavesmc.leaves.command.bot.BotSubcommand; import org.leavesmc.leaves.event.bot.BotRemoveEvent; @@ -30,15 +30,15 @@ public class SaveCommand extends BotSubcommand { return LeavesConfig.modify.fakeplayer.canManualSaveAndLoad && super.requires(source); } - private static class BotArgument extends CustomArgumentNode { + private static class BotArgument extends ArgumentNode { private BotArgument() { - super("bot", new org.leavesmc.leaves.command.bot.BotArgument()); + super("bot", new BotArgumentType()); } @Override - protected boolean execute(@NotNull CommandContext context) throws CommandSyntaxException { - ServerBot bot = context.getCustomArgument(BotArgument.class); + protected boolean execute(@NotNull CommandContext context) { + ServerBot bot = context.getArgument(BotArgument.class); CommandSender sender = context.getSender(); BotList botList = BotList.INSTANCE; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/action/StartCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/action/StartCommand.java index 8a7b0a18..126c8ea2 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/action/StartCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/bot/subcommands/action/StartCommand.java @@ -3,7 +3,7 @@ package org.leavesmc.leaves.command.bot.subcommands.action; import com.mojang.brigadier.Command; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.apache.commons.lang3.tuple.Pair; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.Contract; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/LeavesSubcommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/LeavesSubcommand.java index fa20c4c8..006b0f19 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/LeavesSubcommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/LeavesSubcommand.java @@ -1,6 +1,6 @@ package org.leavesmc.leaves.command.leaves; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.leavesmc.leaves.command.LiteralNode; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/BlockUpdateCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/BlockUpdateCommand.java index 9c91bb93..86aa3a54 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/BlockUpdateCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/BlockUpdateCommand.java @@ -1,7 +1,7 @@ package org.leavesmc.leaves.command.leaves.subcommands; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.commands.CommandSourceStack; +import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/ConfigCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/ConfigCommand.java index 5d32cbc4..2d7505b2 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/ConfigCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/ConfigCommand.java @@ -31,7 +31,7 @@ public class ConfigCommand extends LeavesSubcommand { private PathArgument() { super("path", StringArgumentType.string()); - children(ConfigCommand.ValueArgument::new); + children(ValueArgument::new); } @Override diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/CounterCommand.java b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/CounterCommand.java index 4329415d..5c14da8e 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/CounterCommand.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/command/leaves/subcommands/CounterCommand.java @@ -1,8 +1,8 @@ package org.leavesmc.leaves.command.leaves.subcommands; +import io.papermc.paper.command.brigadier.CommandSourceStack; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextColor; -import net.minecraft.commands.CommandSourceStack; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.DyeColor; import org.bukkit.command.CommandSender;