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:
@@ -1,27 +1,43 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
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.SModerationPaper;
|
||||
import de.shiewk.smoderation.paper.inventory.SModMenu;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SModCommand implements TabExecutor {
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
|
||||
public final class SModCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
if (commandSender instanceof Player player){
|
||||
new SModMenu(player, SModerationPaper.container).open();
|
||||
}
|
||||
return true;
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("smod")
|
||||
.requires(CommandUtil.requirePermission("smod.menu"))
|
||||
.executes(this::openMenu)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int openMenu(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
Player player = CommandUtil.getExecutingPlayer(context.getSource());
|
||||
new SModMenu(player, SModerationPaper.container).open();
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
return List.of();
|
||||
public String getCommandDescription() {
|
||||
return "Shows the SModeration menu.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodmenu", "smoderation");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user