diff --git a/spigot/src/main/java/io/tofpu/speedbridge2/command/parser/BridgePlayerParser.java b/spigot/src/main/java/io/tofpu/speedbridge2/command/parser/BridgePlayerParser.java new file mode 100644 index 00000000..c75fdd60 --- /dev/null +++ b/spigot/src/main/java/io/tofpu/speedbridge2/command/parser/BridgePlayerParser.java @@ -0,0 +1,33 @@ +package io.tofpu.speedbridge2.command.parser; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import revxrsal.commands.exception.CommandErrorException; +import revxrsal.commands.process.ValueResolver; + +import static io.tofpu.speedbridge2.model.common.Message.INSTANCE; + +@AutoRegister +public class BridgePlayerParser extends AbstractLampParser { + private final PlayerService playerService; + + public BridgePlayerParser(PlayerService playerService, LampParseRegistry registry) { + super(BridgePlayer.class, registry); + this.playerService = playerService; + } + + @Override + BridgePlayer parse(ValueResolver.ValueResolverContext context) { + final String input = context.pop(); + Player player = Bukkit.getPlayer(input); + BridgePlayer bridgePlayer = player == null ? null : playerService.getIfPresent(player.getUniqueId()); + if (bridgePlayer == null) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(String.format(INSTANCE.mustBeOnline, input))); + } + return bridgePlayer; + } +} diff --git a/spigot/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java b/spigot/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java index a5101ab5..2b755162 100644 --- a/spigot/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java +++ b/spigot/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java @@ -25,12 +25,12 @@ import io.tofpu.speedbridge2.plugin.SpeedBridgePlugin; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import revxrsal.commands.annotation.*; import revxrsal.commands.bukkit.annotation.CommandPermission; -import revxrsal.commands.bukkit.exception.MalformedEntitySelectorException; import java.util.ArrayList; import java.util.List; @@ -435,6 +435,18 @@ public String cancelSetup(final BridgePlayer bridgePlayer) { return INSTANCE.setupCancelled; } + @Subcommand("admin set selectedBlockType") + @Description("Changes the selected block type for a specified player") + @CommandPermission("speedbridge.admin.set.selectedBlockType") + @AutoComplete("* @players") + public String setSelectedBlockType(final Material material, final BridgePlayer target) { + if (!material.isSolid()) { + return String.format(INSTANCE.blockTypeMustBeSolid, material); + } + target.setChosenMaterial(material); + return String.format(INSTANCE.setChosenType, target.getName(), material); + } + private String hover(final String hoverContent, final String content) { return "" + content; } diff --git a/spigot/src/main/java/io/tofpu/speedbridge2/model/common/Message.java b/spigot/src/main/java/io/tofpu/speedbridge2/model/common/Message.java index 1ecc9e09..6f955dbb 100644 --- a/spigot/src/main/java/io/tofpu/speedbridge2/model/common/Message.java +++ b/spigot/src/main/java/io/tofpu/speedbridge2/model/common/Message.java @@ -119,6 +119,9 @@ public final class Message { "for %s seconds."; public final String invalidUuid = error + "%s is not a valid uuid format. Please try again"; + public final String mustBeOnline = error + "%s must be available to modify their data"; + public final String setChosenType = SUCCESS + "Changed %s's selected block type to %s"; + public final String blockTypeMustBeSolid = error + "%s must be a solid block to be selectable!"; private static String runCommand(final String command) { return "Click to run " +