Made restrict a subcommand of /clownfish rather than a standnalone command

This commit is contained in:
james 2024-03-27 15:16:20 +00:00
parent 7e40a9ebd7
commit 5908c96cf4
2 changed files with 49 additions and 62 deletions

View File

@ -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<String> 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("<red>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<String> 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");

View File

@ -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 = "/<command> <player>")
@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<String> 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<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}