From 5908c96cf4b7b457b4483aee71712ad7cc5f00cc Mon Sep 17 00:00:00 2001 From: james <75051061+notsceptor@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:16:20 +0000 Subject: [PATCH] Made restrict a subcommand of /clownfish rather than a standnalone command --- .../plex/extras/command/ClownfishCommand.java | 49 +++++++++++++++ .../command/RestrictClownfishCommand.java | 62 ------------------- 2 files changed, 49 insertions(+), 62 deletions(-) delete mode 100644 src/main/java/dev/plex/extras/command/RestrictClownfishCommand.java diff --git a/src/main/java/dev/plex/extras/command/ClownfishCommand.java b/src/main/java/dev/plex/extras/command/ClownfishCommand.java index ae8eaf8..ff026db 100644 --- a/src/main/java/dev/plex/extras/command/ClownfishCommand.java +++ b/src/main/java/dev/plex/extras/command/ClownfishCommand.java @@ -1,9 +1,13 @@ package dev.plex.extras.command; +import dev.plex.cache.DataUtils; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; +import dev.plex.command.exception.PlayerNotFoundException; import dev.plex.extras.TFMExtras; +import dev.plex.player.PlexPlayer; +import dev.plex.util.PlexUtils; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Material; @@ -14,6 +18,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -54,6 +59,38 @@ public class ClownfishCommand extends PlexCommand return messageComponent("toggleClownfish", isToggled ? "now" : "no longer"); } + else if (args[0].equals("restrict") && args.length == 2) + { + if (silentCheckPermission(commandSender, "plex.tfmextras.restrictclownfish")) + { + PlexPlayer target = DataUtils.getPlayer(args[1]); + if (target == null) + { + throw new PlayerNotFoundException(); + } + + List restrictedPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.restricted"); + + boolean isRestricted = restrictedPlayers.contains(target.getUuid().toString()); + if (isRestricted) + { + restrictedPlayers.remove(target.getUuid().toString()); + } + else + { + restrictedPlayers.add(target.getUuid().toString()); + } + + TFMExtras.getModule().getConfig().set("server.clownfish.restricted", restrictedPlayers); + TFMExtras.getModule().getConfig().save(); + + return messageComponent("restrictClownfish", target.getName(), isRestricted ? "now" : "no longer"); + } + else + { + return MiniMessage.miniMessage().deserialize("You do not have permission to use this command."); + } + } else { return usage(); @@ -62,6 +99,18 @@ public class ClownfishCommand extends PlexCommand @Override public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { + if (silentCheckPermission(sender, "plex.tfmextras.restrictclownfish")) + { + if (args.length == 1) + { + return Arrays.asList("toggle", "restrict"); + } + else if (args.length == 2 && args[0].equals("restrict")) + { + return PlexUtils.getPlayerNameList(); + } + } + if (args.length == 1) { return List.of("toggle"); diff --git a/src/main/java/dev/plex/extras/command/RestrictClownfishCommand.java b/src/main/java/dev/plex/extras/command/RestrictClownfishCommand.java deleted file mode 100644 index c8c574b..0000000 --- a/src/main/java/dev/plex/extras/command/RestrictClownfishCommand.java +++ /dev/null @@ -1,62 +0,0 @@ -package dev.plex.extras.command; - -import com.google.common.collect.ImmutableList; -import dev.plex.cache.DataUtils; -import dev.plex.command.PlexCommand; -import dev.plex.command.annotation.CommandParameters; -import dev.plex.command.annotation.CommandPermissions; -import dev.plex.command.exception.PlayerNotFoundException; -import dev.plex.extras.TFMExtras; -import dev.plex.player.PlexPlayer; -import dev.plex.util.PlexUtils; - -import net.kyori.adventure.text.Component; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -@CommandParameters(name = "toggleclownfish", description = "Toggles the ability to use the clownfish for a specified player", usage = "/ ") -@CommandPermissions(permission = "plex.tfmextras.toggleclownfish") -public class RestrictClownfishCommand extends PlexCommand -{ - @Override - protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) - { - if (args.length == 0) - { - return usage(); - } - - PlexPlayer target = DataUtils.getPlayer(args[0]); - if (target == null) - { - throw new PlayerNotFoundException(); - } - - List restrictedPlayers = TFMExtras.getModule().getConfig().getStringList("server.clownfish.restricted"); - - boolean isRestricted = restrictedPlayers.contains(target.getUuid().toString()); - if (isRestricted) - { - restrictedPlayers.remove(target.getUuid().toString()); - } - else - { - restrictedPlayers.add(target.getUuid().toString()); - } - - TFMExtras.getModule().getConfig().set("server.clownfish.restricted", restrictedPlayers); - TFMExtras.getModule().getConfig().save(); - - return messageComponent("restrictClownfish", target.getName(), isRestricted ? "now" : "no longer"); - } - - @Override - public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { - return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of(); - } -}