Attempt to improve the tab completion for Plex

This commit is contained in:
Telesphoreo 2024-01-20 01:48:17 -06:00
parent c9d954d1c0
commit 8710b478c1
33 changed files with 231 additions and 102 deletions

View File

@ -1,5 +1,6 @@
package dev.plex.command;
import com.google.common.collect.Lists;
import dev.plex.Plex;
import dev.plex.cache.DataUtils;
import dev.plex.command.annotation.CommandParameters;
@ -14,14 +15,16 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
/**
@ -61,6 +64,7 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
setName(this.params.name());
setLabel(this.params.name());
setDescription(params.description());
setPermission(this.perms.permission());
setUsage(params.usage().replace("<command>", this.params.name()));
if (params.aliases().split(",").length > 0)
{
@ -74,7 +78,8 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
{
getMap().getKnownCommands().remove(this.getName().toLowerCase());
}
this.getAliases().forEach(s -> {
this.getAliases().forEach(s ->
{
if (getMap().getKnownCommands().containsKey(s.toLowerCase()))
{
getMap().getKnownCommands().remove(s.toLowerCase());
@ -166,6 +171,17 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return true;
}
/*@NotNull
public abstract List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException;
*/
@NotNull
public List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
List<String> list = tabComplete(sender, alias, args);
return StringUtil.copyPartialMatches(args[args.length - 1], list, Lists.newArrayList());
}
/**
* Checks if the String given is a matching command
*
@ -283,47 +299,6 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
return !permission.isEmpty() && player.hasPermission(permission);
}
/* *//**
* Checks whether a sender has enough permissions or is high enough a rank
*
* @param sender The player object
* @param rank The rank to check (if the server is using ranks)
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions
* @see Rank
*//*
protected boolean silentCheckPermission(CommandSender sender, Rank rank, String permission)
{
if (!isConsole(sender))
{
return silentCheckPermission((Player) sender, rank, permission);
}
return true;
}
*//**
* Checks whether a player has enough permissions or is high enough a rank
*
* @param player The player object
* @param rank The rank to check (if the server is using ranks)
* @param permission The permission to check (if the server is using permissions)
* @return true if the sender has enough permissions
* @see Rank
*//*
protected boolean silentCheckPermission(Player player, Rank rank, String permission)
{
PlexPlayer plexPlayer = getPlexPlayer(player);
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
return rank.isAtLeast(Rank.ADMIN) ? plexPlayer.isAdminActive() && plexPlayer.getRankFromString().isAtLeast(rank) : plexPlayer.getRankFromString().isAtLeast(rank);
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
return !permission.isEmpty() && player.hasPermission(permission);
}
return true;
}*/
/**
* Gets the UUID of the sender
*

View File

@ -1,6 +1,5 @@
package dev.plex.command.impl;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
@ -12,8 +11,6 @@ import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import dev.plex.util.redis.MessageUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.CommandSender;
@ -21,6 +18,8 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@CommandPermissions(permission = "plex.adminchat", source = RequiredCommandSource.ANY)
@ -58,4 +57,10 @@ public class AdminChatCMD extends PlexCommand
MessageUtil.sendStaffChat(sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), prefix, message).toArray(UUID[]::new));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
public class AdminworldCMD extends PlexCommand
@ -29,4 +32,10 @@ public class AdminworldCMD extends PlexCommand
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -11,10 +11,10 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.*;
//import me.botsko.prism.api.PrismParameters;
//import me.botsko.prism.api.Result;
//import me.botsko.prism.api.actions.PrismProcessType;
import dev.plex.util.BungeeUtil;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
@ -23,13 +23,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@CommandParameters(name = "ban", usage = "/<command> <player> [-nrb] [reason] [-nrb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
@ -134,6 +131,6 @@ public class BanCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, "plex.ban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -12,6 +12,11 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.blockedit")
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
public class BlockEditCMD extends PlexCommand
@ -94,4 +99,20 @@ public class BlockEditCMD extends PlexCommand
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (silentCheckPermission(sender, this.getPermission()))
{
List<String> options = new ArrayList<>();
if (args.length == 1)
{
options.addAll(Arrays.asList("list", "purge", "all"));
options.addAll(PlexUtils.getPlayerNameList());
return options;
}
}
return Collections.emptyList();
}
}

View File

@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
public class CommandSpyCMD extends PlexCommand
@ -30,4 +33,10 @@ public class CommandSpyCMD extends PlexCommand
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
public class ConsoleSayCMD extends PlexCommand
@ -27,4 +30,10 @@ public class ConsoleSayCMD extends PlexCommand
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -108,18 +108,22 @@ public class EntityWipeCMD extends PlexCommand
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
List<String> entities = new ArrayList<>();
for (World world : Bukkit.getWorlds())
if (silentCheckPermission(sender, this.getPermission()))
{
for (Entity entity : world.getEntities())
List<String> entities = new ArrayList<>();
for (World world : Bukkit.getWorlds())
{
if (entity.getType() != EntityType.PLAYER)
for (Entity entity : world.getEntities())
{
entities.add(entity.getType().name());
if (entity.getType() != EntityType.PLAYER)
{
entities.add(entity.getType().name());
}
}
}
return entities.stream().toList();
}
return entities.stream().toList();
return Collections.emptyList();
}
private Integer parseInt(CommandSender sender, String string)

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -13,6 +12,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
public class FlatlandsCMD extends PlexCommand
@ -29,4 +31,10 @@ public class FlatlandsCMD extends PlexCommand
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import net.kyori.adventure.text.Component;
@ -56,6 +55,6 @@ public class FreezeCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, "plex.freeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -96,7 +96,10 @@ public class GamemodeCMD extends PlexCommand
}
if (args.length == 2)
{
return PlexUtils.getPlayerNameList();
if (silentCheckPermission(sender, "plex.gamemode.others"))
{
return PlexUtils.getPlayerNameList();
}
}
return Collections.emptyList();
}

View File

@ -1,5 +1,6 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
@ -9,7 +10,6 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.BungeeUtil;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
@CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY)
@ -67,4 +68,10 @@ public class KickCMD extends PlexCommand
BungeeUtil.kickPlayer(player, Punishment.generateKickMessage(punishment));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -67,7 +67,7 @@ public class ListCMD extends PlexCommand
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{
return Collections.singletonList("-d");
}

View File

@ -11,6 +11,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandParameters(name = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
@CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
public class LocalSpawnCMD extends PlexCommand
@ -22,4 +25,10 @@ public class LocalSpawnCMD extends PlexCommand
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
return messageComponent("teleportedToWorldSpawn");
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -5,7 +5,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
@ -41,6 +40,6 @@ public class LockupCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, "plex.lockup") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -13,6 +13,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
public class MasterbuilderworldCMD extends PlexCommand
@ -30,4 +33,10 @@ public class MasterbuilderworldCMD extends PlexCommand
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -113,7 +113,7 @@ public class MobPurgeCMD extends PlexCommand
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{
return getAllMobs();
}

View File

@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import net.kyori.adventure.text.Component;
@ -39,7 +38,7 @@ public class MuteCMD extends PlexCommand
return messageComponent("playerMuted");
}
if (silentCheckPermission(player,"plex.mute"))
if (silentCheckPermission(player, "plex.mute"))
{
send(sender, messageComponent("higherRankThanYou"));
return null;
@ -62,6 +61,6 @@ public class MuteCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender,"plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.extra.Note;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import net.kyori.adventure.text.Component;
@ -139,13 +138,17 @@ public class NotesCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
if (silentCheckPermission(sender, this.getPermission()))
{
return PlexUtils.getPlayerNameList();
}
if (args.length == 2)
{
return Arrays.asList("list", "add", "remove", "clear");
if (args.length == 1)
{
return PlexUtils.getPlayerNameList();
}
if (args.length == 2)
{
return Arrays.asList("list", "add", "remove", "clear");
}
return Collections.emptyList();
}
return Collections.emptyList();
}

View File

@ -7,7 +7,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.menu.impl.PunishedPlayerMenu;
import dev.plex.menu.impl.PunishmentMenu;
import dev.plex.player.PlexPlayer;
@ -52,6 +51,6 @@ public class PunishmentsCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -13,6 +13,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.rawsay", source = RequiredCommandSource.ANY)
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
public class RawSayCMD extends PlexCommand
@ -28,4 +31,10 @@ public class RawSayCMD extends PlexCommand
PlexUtils.broadcast(StringUtils.join(args, " "));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -1,17 +1,21 @@
package dev.plex.command.impl;
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.source.RequiredCommandSource;
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;
@CommandPermissions(permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
public class RemoveLoginMessageCMD extends PlexCommand
@ -51,4 +55,17 @@ public class RemoveLoginMessageCMD extends PlexCommand
}
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
if (silentCheckPermission(sender, "plex.removeloginmessage"))
{
return List.of("-o");
}
}
return args.length == 2 && silentCheckPermission(sender, "plex.removeloginmessage") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -4,7 +4,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang3.StringUtils;
@ -13,6 +12,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.say", source = RequiredCommandSource.ANY)
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
public class SayCMD extends PlexCommand
@ -28,4 +30,10 @@ public class SayCMD extends PlexCommand
PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
return null;
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return Collections.emptyList();
}
}

View File

@ -1,5 +1,6 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.cache.DataUtils;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
@ -16,6 +17,8 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@CommandPermissions(permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
public class SetLoginMessageCMD extends PlexCommand
@ -79,4 +82,17 @@ public class SetLoginMessageCMD extends PlexCommand
throw new CommandFailException(messageString("nameRequired"));
}
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
if (silentCheckPermission(sender, "plex.setloginmessage"))
{
return List.of("-o");
}
}
return args.length == 2 && args[0].equalsIgnoreCase("-o") && silentCheckPermission(sender, "plex.setloginmessage") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -7,7 +7,6 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import net.kyori.adventure.text.Component;
@ -138,7 +137,7 @@ public class SmiteCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (silentCheckPermission(sender,"plex.smite") && args.length == 1)
if (silentCheckPermission(sender, this.getPermission()) && args.length == 1)
{
return PlexUtils.getPlayerNameList();
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
import dev.plex.util.minimessage.SafeMiniMessage;
import net.kyori.adventure.text.Component;
@ -19,6 +18,10 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@CommandPermissions(permission = "plex.tag", source = RequiredCommandSource.ANY)
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
public class TagCMD extends PlexCommand
@ -80,7 +83,7 @@ public class TagCMD extends PlexCommand
DataUtils.update(player);
return messageComponent("prefixCleared");
}
checkPermission(sender,"plex.tag.clear.others");
checkPermission(sender, "plex.tag.clear.others");
Player target = getNonNullPlayer(args[1]);
PlexPlayer plexTarget = DataUtils.getPlayer(target.getUniqueId());
plexTarget.setPrefix(null);
@ -89,6 +92,26 @@ public class TagCMD extends PlexCommand
}
return usage();
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
if (args.length == 1)
{
return Arrays.asList("set", "clear");
}
if (args.length == 2)
{
if (args[0].equalsIgnoreCase("clear"))
{
if (silentCheckPermission(sender, "plex.tag.clear.others"))
{
return PlexUtils.getPlayerNameList();
}
}
}
return Collections.emptyList();
}
}

View File

@ -10,7 +10,6 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.BungeeUtil;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
@ -120,6 +119,6 @@ public class TempbanCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender,"plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.menu.impl.ToggleMenu;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
@ -66,7 +65,7 @@ public class ToggleCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
private String status(String toggle)

View File

@ -9,7 +9,6 @@ import dev.plex.command.exception.PlayerNotBannedException;
import dev.plex.command.exception.PlayerNotFoundException;
import dev.plex.command.source.RequiredCommandSource;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
@ -58,6 +57,6 @@ public class UnbanCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender,"plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
@ -41,6 +40,6 @@ public class UnfreezeCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender,"plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.exception.CommandFailException;
import dev.plex.player.PlexPlayer;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
@ -41,6 +40,6 @@ public class UnmuteCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender,"plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
}
}

View File

@ -47,6 +47,6 @@ public class WhoHasCMD extends PlexCommand
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
return args.length == 1 && silentCheckPermission(sender, "plex.whohas") ? Arrays.stream(Material.values()).map(Enum::name).toList() : ImmutableList.of();
return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? Arrays.stream(Material.values()).map(Enum::name).toList() : ImmutableList.of();
}
}

View File

@ -6,7 +6,6 @@ import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -38,19 +37,18 @@ public class WorldCMD extends PlexCommand
boolean playerWorld = args[0].matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
if (playerWorld && Plex.get().getModuleManager().getModules().stream().anyMatch(plexModule -> plexModule.getPlexModuleFile().getName().equalsIgnoreCase("Module-TFMExtras")))
{
checkPermission(playerSender,"plex.world.playerworlds");
checkPermission(playerSender, "plex.world.playerworlds");
}
playerSender.teleportAsync(world.getSpawnLocation());
return messageComponent("playerWorldTeleport", world.getName());
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
{
final List<String> completions = Lists.newArrayList();
final Player player = (Player) sender;
if (args.length == 1)
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
{
@NotNull List<World> worlds = Bukkit.getWorlds();
for (World world : worlds)
@ -60,7 +58,7 @@ public class WorldCMD extends PlexCommand
try
{
final UUID uuid = UUID.fromString(worldName);
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player,"plex.world.playerworlds"))
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player, "plex.world.playerworlds"))
{
completions.add(worldName);
}