1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-29 06:34:17 +02:00

Upgrade Paper to 1.21, use Brigadier command system

This commit is contained in:
Shy
2025-05-01 19:55:55 +02:00
parent fbaaa6ec89
commit 361f66f645
19 changed files with 786 additions and 714 deletions
@@ -1,59 +1,53 @@
package de.shiewk.smoderation.paper.command;
import de.shiewk.smoderation.paper.util.PlayerUtil;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static de.shiewk.smoderation.paper.SModerationPaper.*;
import static io.papermc.paper.command.brigadier.Commands.argument;
import static io.papermc.paper.command.brigadier.Commands.literal;
public class EnderchestSeeCommand implements TabExecutor {
public final class EnderchestSeeCommand implements CommandProvider {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length < 1) {
return false;
}
if (sender instanceof HumanEntity human){
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
if (player != null) {
human.sendMessage(CHAT_PREFIX.append(
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
.append(Component.text("."))
));
human.openInventory(player.getEnderChest());
} else {
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
}
} else {
sender.sendMessage(Component.text("Only an entity that can open inventories can execute this command!").color(FAIL_COLOR));
}
return true;
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("enderchestsee")
.requires(CommandUtil.requirePermission("smod.enderchestsee"))
.then(argument("player", ArgumentTypes.player())
.executes(this::openEnderChest)
)
.build();
}
private int openEnderChest(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
Player sender = CommandUtil.getExecutingPlayer(context.getSource());
Player target = CommandUtil.getPlayerSingle(context, "player");
sender.sendMessage(CHAT_PREFIX.append(
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
.append(target.teamDisplayName().colorIfAbsent(SECONDARY_COLOR))
.append(Component.text("."))
));
sender.openInventory(target.getEnderChest());
return Command.SINGLE_SUCCESS;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length > 1){
return List.of();
}
List<String> available = new ArrayList<>();
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
available.add(onlinePlayer.getName());
}
List<String> completions = new ArrayList<>();
StringUtil.copyPartialMatches(args.length > 0 ? args[0] : "", available, completions);
return completions;
public String getCommandDescription() {
return "Views the ender chest of a player.";
}
@Override
public Collection<String> getAliases() {
return List.of("ecsee");
}
}