Skip to content

Commit

Permalink
Allow admins to change a player's selected block type via command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofpu committed Mar 12, 2024
1 parent 3e1225a commit f7f1e74
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<BridgePlayer> {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "<hover:show_text:'" + hoverContent + "'>" + content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<hover:show_text:'<yellow>Click to run " +
Expand Down

0 comments on commit f7f1e74

Please sign in to comment.