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,32 +1,49 @@
|
||||
package de.shiewk.smoderation.paper.command;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.shiewk.smoderation.paper.listener.SocialSpyListener;
|
||||
import de.shiewk.smoderation.paper.util.CommandUtil;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.paper.SModerationPaper.CHAT_PREFIX;
|
||||
import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class SocialSpyCommand implements TabExecutor {
|
||||
public final class SocialSpyCommand implements CommandProvider {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("socialspy")
|
||||
.requires(CommandUtil.requirePermission("smod.socialspy"))
|
||||
.executes(this::toggleSocialSpy)
|
||||
.build();
|
||||
}
|
||||
|
||||
private int toggleSocialSpy(CommandContext<CommandSourceStack> context) {
|
||||
CommandSender sender = context.getSource().getSender();
|
||||
final boolean enabled = SocialSpyListener.toggle(sender);
|
||||
sender.sendMessage(CHAT_PREFIX.append(text("SocialSpy ").append(
|
||||
enabled ?
|
||||
text("enabled").color(NamedTextColor.GREEN) :
|
||||
text("disabled").color(NamedTextColor.RED)
|
||||
enabled ?
|
||||
text("enabled").color(NamedTextColor.GREEN) :
|
||||
text("disabled").color(NamedTextColor.RED)
|
||||
).append(text("."))));
|
||||
return true;
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return List.of();
|
||||
public String getCommandDescription() {
|
||||
return "Enables socialspy mode (you can see private messages of other players)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getAliases() {
|
||||
return List.of("smodsocialspy");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user