mirror of
https://github.com/plexusorg/Plex.git
synced 2026-06-04 05:26:55 +00:00
Brigadier
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package dev.plex.api.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import dev.plex.command.PlexCommand;
|
||||
|
||||
public interface CommandApi
|
||||
{
|
||||
void register(Command command);
|
||||
void register(PlexCommand command);
|
||||
|
||||
void unregister(Command command);
|
||||
void unregister(PlexCommand command);
|
||||
}
|
||||
|
||||
@@ -1,307 +1,75 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
import dev.plex.command.exception.PlayerNotBannedException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
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.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/** Public base class for module commands. */
|
||||
public abstract class PlexCommand extends Command
|
||||
/**
|
||||
* Public Brigadier command contract for Plex and Plex modules.
|
||||
*/
|
||||
public interface PlexCommand
|
||||
{
|
||||
private static Runtime runtime;
|
||||
private final CommandParameters params;
|
||||
private final CommandPermissions perms;
|
||||
private final RequiredCommandSource commandSource;
|
||||
LiteralCommandNode<CommandSourceStack> buildCommand();
|
||||
|
||||
public static void setRuntime(Runtime runtime)
|
||||
default CommandParameters parameters()
|
||||
{
|
||||
PlexCommand.runtime = runtime;
|
||||
}
|
||||
|
||||
public PlexCommand(boolean register)
|
||||
{
|
||||
super("");
|
||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||
if (params == null || perms == null)
|
||||
CommandParameters parameters = getClass().getAnnotation(CommandParameters.class);
|
||||
if (parameters == null)
|
||||
{
|
||||
throw new IllegalStateException("PlexCommand requires CommandParameters and CommandPermissions annotations");
|
||||
throw new IllegalStateException(getClass().getName() + " requires a CommandParameters annotation");
|
||||
}
|
||||
setName(params.name());
|
||||
setLabel(params.name());
|
||||
setDescription(params.description());
|
||||
setPermission(perms.permission());
|
||||
setUsage(params.usage().replace("<command>", params.name()));
|
||||
if (!params.aliases().isEmpty())
|
||||
return parameters;
|
||||
}
|
||||
|
||||
default CommandPermissions permissions()
|
||||
{
|
||||
CommandPermissions permissions = getClass().getAnnotation(CommandPermissions.class);
|
||||
if (permissions == null)
|
||||
{
|
||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
throw new IllegalStateException(getClass().getName() + " requires a CommandPermissions annotation");
|
||||
}
|
||||
this.commandSource = perms.source();
|
||||
if (register)
|
||||
return permissions;
|
||||
}
|
||||
|
||||
default String getName()
|
||||
{
|
||||
return parameters().name();
|
||||
}
|
||||
|
||||
default String getDescription()
|
||||
{
|
||||
return parameters().description();
|
||||
}
|
||||
|
||||
default String getUsage()
|
||||
{
|
||||
return parameters().usage().replace("<command>", getName());
|
||||
}
|
||||
|
||||
default String getPermission()
|
||||
{
|
||||
return permissions().permission();
|
||||
}
|
||||
|
||||
default RequiredCommandSource getRequiredSource()
|
||||
{
|
||||
return permissions().source();
|
||||
}
|
||||
|
||||
default List<String> getAliases()
|
||||
{
|
||||
String aliases = parameters().aliases();
|
||||
if (aliases.isBlank())
|
||||
{
|
||||
requireRuntime().register(this);
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
public PlexCommand()
|
||||
{
|
||||
this(true);
|
||||
}
|
||||
|
||||
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String label, String[] args)
|
||||
{
|
||||
if (!matches(label))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionInGame"));
|
||||
return true;
|
||||
}
|
||||
if (commandSource == RequiredCommandSource.IN_GAME && sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionConsole"));
|
||||
return true;
|
||||
}
|
||||
if (!perms.permission().isEmpty() && sender instanceof Player player && !player.hasPermission(perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
Component component = execute(sender, isConsole(sender) ? null : (Player)sender, args);
|
||||
if (component != null)
|
||||
{
|
||||
send(sender, component);
|
||||
}
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException |
|
||||
ConsoleMustDefinePlayerException | PlayerNotBannedException | NumberFormatException ex)
|
||||
{
|
||||
send(sender, exceptionComponent(ex));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return StringUtil.copyPartialMatches(args[args.length - 1], smartTabComplete(sender, alias, args), new ArrayList<>());
|
||||
}
|
||||
|
||||
private boolean matches(String label)
|
||||
{
|
||||
return getName().equalsIgnoreCase(label) || getAliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(label));
|
||||
}
|
||||
|
||||
protected void send(Audience audience, String s)
|
||||
{
|
||||
audience.sendMessage(componentFromString(s));
|
||||
}
|
||||
|
||||
protected void send(Audience audience, Component component)
|
||||
{
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
protected boolean checkPermission(CommandSender sender, String permission)
|
||||
{
|
||||
return isConsole(sender) || checkPermission((Player)sender, permission);
|
||||
}
|
||||
|
||||
protected boolean silentCheckPermission(CommandSender sender, String permission)
|
||||
{
|
||||
return isConsole(sender) || silentCheckPermission((Player)sender, permission);
|
||||
}
|
||||
|
||||
protected boolean checkPermission(Player player, String permission)
|
||||
{
|
||||
if (!permission.isEmpty() && !player.hasPermission(permission))
|
||||
{
|
||||
throw new CommandFailException(messageString("noPermissionNode", permission));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean silentCheckPermission(Player player, String permission)
|
||||
{
|
||||
return permission.isEmpty() || player.hasPermission(permission);
|
||||
}
|
||||
|
||||
protected UUID getUUID(CommandSender sender)
|
||||
{
|
||||
return sender instanceof Player player ? player.getUniqueId() : null;
|
||||
}
|
||||
|
||||
protected boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
protected Component messageComponent(String s, Object... objects)
|
||||
{
|
||||
return requireRuntime().messageComponent(s, objects);
|
||||
}
|
||||
|
||||
protected Component messageComponent(String s, Component... objects)
|
||||
{
|
||||
return requireRuntime().messageComponent(s, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component permissionMessage()
|
||||
{
|
||||
return messageComponent("noPermissionNode", getPermission());
|
||||
}
|
||||
|
||||
protected String messageString(String s, Object... objects)
|
||||
{
|
||||
return requireRuntime().messageString(s, objects);
|
||||
}
|
||||
|
||||
protected Component usage()
|
||||
{
|
||||
return messageComponent("correctUsagePrefix").append(componentFromString(getUsage()).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
protected Component usage(String s)
|
||||
{
|
||||
return messageComponent("correctUsagePrefix").append(componentFromString(s).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
private Component exceptionComponent(RuntimeException ex)
|
||||
{
|
||||
if (ex instanceof PlayerNotFoundException && "PlayerNotFoundException".equals(ex.getMessage()))
|
||||
{
|
||||
return messageComponent("playerNotFound");
|
||||
}
|
||||
if (ex instanceof PlayerNotBannedException && "PlayerNotBannedException".equals(ex.getMessage()))
|
||||
{
|
||||
return messageComponent("playerNotBanned");
|
||||
}
|
||||
if (ex instanceof ConsoleOnlyException && "ConsoleOnlyException".equals(ex.getMessage()))
|
||||
{
|
||||
return messageComponent("consoleOnly");
|
||||
}
|
||||
if (ex instanceof ConsoleMustDefinePlayerException && "ConsoleMustDefinePlayerException".equals(ex.getMessage()))
|
||||
{
|
||||
return messageComponent("consoleMustDefinePlayer");
|
||||
}
|
||||
return mmString(ex.getMessage());
|
||||
}
|
||||
|
||||
protected Player getNonNullPlayer(String name)
|
||||
{
|
||||
Player player;
|
||||
try
|
||||
{
|
||||
player = Bukkit.getPlayer(UUID.fromString(name));
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
player = Bukkit.getPlayer(name);
|
||||
}
|
||||
if (player == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
protected World getNonNullWorld(String name)
|
||||
{
|
||||
World world = Bukkit.getWorld(name);
|
||||
if (world == null)
|
||||
{
|
||||
throw new CommandFailException(messageString("worldNotFound"));
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
protected Component componentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY);
|
||||
}
|
||||
|
||||
protected Component noColorComponentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
||||
}
|
||||
|
||||
protected Component mmString(String s)
|
||||
{
|
||||
return requireRuntime().miniMessage(s);
|
||||
}
|
||||
|
||||
protected void broadcast(String miniMessage)
|
||||
{
|
||||
requireRuntime().broadcast(miniMessage);
|
||||
}
|
||||
|
||||
protected void broadcast(Component component)
|
||||
{
|
||||
requireRuntime().broadcast(component);
|
||||
}
|
||||
|
||||
protected List<String> onlinePlayerNames()
|
||||
{
|
||||
return requireRuntime().onlinePlayerNames();
|
||||
}
|
||||
|
||||
public CommandMap getMap()
|
||||
{
|
||||
return Bukkit.getCommandMap();
|
||||
}
|
||||
|
||||
private static Runtime requireRuntime()
|
||||
{
|
||||
if (runtime == null)
|
||||
{
|
||||
throw new IllegalStateException("PlexCommand runtime has not been installed by Plex");
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public interface Runtime
|
||||
{
|
||||
void register(Command command);
|
||||
Component messageComponent(String entry, Object... objects);
|
||||
Component messageComponent(String entry, Component... objects);
|
||||
String messageString(String entry, Object... objects);
|
||||
Component miniMessage(String input);
|
||||
void broadcast(String miniMessage);
|
||||
void broadcast(Component component);
|
||||
List<String> onlinePlayerNames();
|
||||
return Arrays.stream(aliases.split(","))
|
||||
.map(String::trim)
|
||||
.filter(alias -> !alias.isBlank())
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.plex.module;
|
||||
|
||||
import dev.plex.api.PlexApi;
|
||||
import dev.plex.command.PlexCommand;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -13,7 +14,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public abstract class PlexModule
|
||||
{
|
||||
private final List<Command> commands = new ArrayList<>();
|
||||
private final List<PlexCommand> commands = new ArrayList<>();
|
||||
private final List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
private PlexApi api;
|
||||
@@ -72,7 +72,7 @@ public abstract class PlexModule
|
||||
HandlerList.unregisterAll(listener);
|
||||
}
|
||||
|
||||
public void registerCommand(Command command)
|
||||
public void registerCommand(PlexCommand command)
|
||||
{
|
||||
commands.add(command);
|
||||
if (api != null)
|
||||
@@ -81,7 +81,7 @@ public abstract class PlexModule
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterCommand(Command command)
|
||||
public void unregisterCommand(PlexCommand command)
|
||||
{
|
||||
commands.remove(command);
|
||||
if (api != null)
|
||||
@@ -91,7 +91,7 @@ public abstract class PlexModule
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Command getCommand(String name)
|
||||
public PlexCommand getCommand(String name)
|
||||
{
|
||||
return commands.stream()
|
||||
.filter(command -> command.getName().equalsIgnoreCase(name) || command.getAliases().stream().map(String::toLowerCase).toList().contains(name.toLowerCase(Locale.ROOT)))
|
||||
@@ -142,7 +142,7 @@ public abstract class PlexModule
|
||||
}
|
||||
}
|
||||
|
||||
public List<Command> getCommands()
|
||||
public List<PlexCommand> getCommands()
|
||||
{
|
||||
return commands;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ import dev.plex.util.redis.MessageUtil;
|
||||
import dev.plex.world.CustomWorld;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -69,6 +71,8 @@ public class Plex extends JavaPlugin
|
||||
private NoteRepository noteRepository;
|
||||
|
||||
private ModuleManager moduleManager;
|
||||
private CommandHandler commandHandler;
|
||||
private final List<PlexCommand> pendingCommands = new ArrayList<>();
|
||||
private ServiceManager serviceManager;
|
||||
private PunishmentManager punishmentManager;
|
||||
private UpdateChecker updateChecker;
|
||||
@@ -121,62 +125,6 @@ public class Plex extends JavaPlugin
|
||||
{
|
||||
return Plex.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(org.bukkit.command.Command command)
|
||||
{
|
||||
api.commands().register(command);
|
||||
}
|
||||
});
|
||||
PlexCommand.setRuntime(new PlexCommand.Runtime()
|
||||
{
|
||||
@Override
|
||||
public void register(org.bukkit.command.Command command)
|
||||
{
|
||||
api.commands().register(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component messageComponent(String entry, Object... objects)
|
||||
{
|
||||
return api.messages().messageComponent(entry, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component messageComponent(String entry, net.kyori.adventure.text.Component... objects)
|
||||
{
|
||||
return api.messages().messageComponent(entry, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String messageString(String entry, Object... objects)
|
||||
{
|
||||
return api.messages().messageString(entry, objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component miniMessage(String input)
|
||||
{
|
||||
return api.messages().miniMessage(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(String miniMessage)
|
||||
{
|
||||
api.messages().broadcast(miniMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(net.kyori.adventure.text.Component component)
|
||||
{
|
||||
api.messages().broadcast(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<String> onlinePlayerNames()
|
||||
{
|
||||
return api.players().onlineNames();
|
||||
}
|
||||
});
|
||||
ModuleConfig.setFactory((module, from, to) -> api.moduleConfigs().create(module, from, to));
|
||||
}
|
||||
@@ -273,7 +221,7 @@ public class Plex extends JavaPlugin
|
||||
playerService = new PlayerService(playerCache, playerRepository);
|
||||
|
||||
new ListenerHandler(this);
|
||||
new CommandHandler(this);
|
||||
commandHandler = new CommandHandler(this);
|
||||
|
||||
punishmentManager = new PunishmentManager(this);
|
||||
punishmentManager.mergeIndefiniteBans();
|
||||
|
||||
@@ -2,7 +2,8 @@ package dev.plex.api.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.api.command.CommandApi;
|
||||
import org.bukkit.command.Command;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.util.PlexLog;
|
||||
|
||||
final class DefaultCommandApi implements CommandApi
|
||||
{
|
||||
@@ -11,18 +12,23 @@ final class DefaultCommandApi implements CommandApi
|
||||
DefaultCommandApi(Plex plugin) { this.plugin = plugin; }
|
||||
|
||||
@Override
|
||||
public void register(Command command)
|
||||
public void register(PlexCommand command)
|
||||
{
|
||||
plugin.getServer().getCommandMap().getKnownCommands().remove(command.getName().toLowerCase());
|
||||
command.getAliases().forEach(alias -> plugin.getServer().getCommandMap().getKnownCommands().remove(alias.toLowerCase()));
|
||||
plugin.getServer().getCommandMap().register("plex", command);
|
||||
if (plugin.getCommandHandler() == null)
|
||||
{
|
||||
plugin.getPendingCommands().add(command);
|
||||
PlexLog.warn("Command {0} was registered before the command handler initialized; queueing it for Brigadier registration.", command.getName());
|
||||
return;
|
||||
}
|
||||
plugin.getCommandHandler().registerCommand(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(Command command)
|
||||
public void unregister(PlexCommand command)
|
||||
{
|
||||
plugin.getServer().getCommandMap().getKnownCommands().remove(command.getName().toLowerCase());
|
||||
command.getAliases().forEach(alias -> plugin.getServer().getCommandMap().getKnownCommands().remove(alias.toLowerCase()));
|
||||
command.unregister(plugin.getServer().getCommandMap());
|
||||
if (plugin.getCommandHandler() != null)
|
||||
{
|
||||
plugin.getCommandHandler().unregisterCommand(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.ConsoleMustDefinePlayerException;
|
||||
import dev.plex.command.exception.ConsoleOnlyException;
|
||||
@@ -13,52 +20,34 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
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.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Superclass for all server commands.
|
||||
* Brigadier-backed superclass for Plex's built-in server commands.
|
||||
*/
|
||||
public abstract class ServerCommand extends Command implements PluginIdentifiableCommand
|
||||
public abstract class ServerCommand implements PlexCommand
|
||||
{
|
||||
private static Runtime runtime;
|
||||
|
||||
/**
|
||||
* Returns the instance of the plugin
|
||||
*/
|
||||
protected final Plex plugin;
|
||||
|
||||
/**
|
||||
* The parameters for the command
|
||||
*/
|
||||
private final CommandParameters params;
|
||||
|
||||
/**
|
||||
* The permissions for the command
|
||||
*/
|
||||
private final CommandPermissions perms;
|
||||
|
||||
/**
|
||||
* Required command source fetched from the permissions
|
||||
*/
|
||||
private final RequiredCommandSource commandSource;
|
||||
|
||||
public static void setRuntime(Runtime runtime)
|
||||
@@ -66,102 +55,233 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
ServerCommand.runtime = runtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the command
|
||||
*/
|
||||
public ServerCommand(boolean register)
|
||||
protected ServerCommand()
|
||||
{
|
||||
super("");
|
||||
this.plugin = requireRuntime().plugin();
|
||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||
|
||||
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)
|
||||
{
|
||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
}
|
||||
this.commandSource = perms.source();
|
||||
|
||||
if (register)
|
||||
{
|
||||
requireRuntime().register(this);
|
||||
}
|
||||
this.commandSource = permissions().source();
|
||||
}
|
||||
|
||||
public ServerCommand()
|
||||
{
|
||||
this(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the command
|
||||
*
|
||||
* @param sender The sender of the command
|
||||
* @param playerSender The player who executed the command (null if CommandSource is console or if CommandSource is any but console executed)
|
||||
* @param args A Kyori Component to send to the sender (can be null)
|
||||
*/
|
||||
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String label, String[] args)
|
||||
public final LiteralCommandNode<CommandSourceStack> buildCommand()
|
||||
{
|
||||
if (!matches(label))
|
||||
LiteralArgumentBuilder<CommandSourceStack> command = Commands.literal(getName())
|
||||
.requires(this::canUse);
|
||||
buildCommand(command);
|
||||
return command.build();
|
||||
}
|
||||
|
||||
protected abstract void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command);
|
||||
|
||||
protected LiteralArgumentBuilder<CommandSourceStack> literal(String literal)
|
||||
{
|
||||
return Commands.literal(literal);
|
||||
}
|
||||
|
||||
protected RequiredArgumentBuilder<CommandSourceStack, String> word(String name)
|
||||
{
|
||||
return Commands.argument(name, StringArgumentType.word());
|
||||
}
|
||||
|
||||
protected RequiredArgumentBuilder<CommandSourceStack, String> playerArgument(String name)
|
||||
{
|
||||
return word(name).suggests(suggestPlayers());
|
||||
}
|
||||
|
||||
protected RequiredArgumentBuilder<CommandSourceStack, String> greedyString(String name)
|
||||
{
|
||||
return Commands.argument(name, StringArgumentType.greedyString());
|
||||
}
|
||||
|
||||
protected RequiredArgumentBuilder<CommandSourceStack, Integer> nonNegativeInteger(String name)
|
||||
{
|
||||
return Commands.argument(name, IntegerArgumentType.integer(0));
|
||||
}
|
||||
|
||||
protected int executeCommand(CommandContext<CommandSourceStack> context, String... args)
|
||||
{
|
||||
return dispatchCommand(context, args);
|
||||
}
|
||||
|
||||
protected String string(CommandContext<CommandSourceStack> context, String name)
|
||||
{
|
||||
return StringArgumentType.getString(context, name);
|
||||
}
|
||||
|
||||
protected int integer(CommandContext<CommandSourceStack> context, String name)
|
||||
{
|
||||
return IntegerArgumentType.getInteger(context, name);
|
||||
}
|
||||
|
||||
protected String[] argsWithGreedy(String greedy)
|
||||
{
|
||||
return splitExecutionArgs(greedy);
|
||||
}
|
||||
|
||||
protected String[] argsWithGreedy(String first, String greedy)
|
||||
{
|
||||
String[] greedyArgs = argsWithGreedy(greedy);
|
||||
String[] args = new String[greedyArgs.length + 1];
|
||||
args[0] = first;
|
||||
System.arraycopy(greedyArgs, 0, args, 1, greedyArgs.length);
|
||||
return args;
|
||||
}
|
||||
|
||||
protected String[] argsWithGreedy(String first, String second, String greedy)
|
||||
{
|
||||
String[] greedyArgs = argsWithGreedy(greedy);
|
||||
String[] args = new String[greedyArgs.length + 2];
|
||||
args[0] = first;
|
||||
args[1] = second;
|
||||
System.arraycopy(greedyArgs, 0, args, 2, greedyArgs.length);
|
||||
return args;
|
||||
}
|
||||
|
||||
protected SuggestionProvider<CommandSourceStack> suggest(Supplier<Collection<String>> suggestions)
|
||||
{
|
||||
return (context, builder) -> suggestMatching(builder, suggestions.get());
|
||||
}
|
||||
|
||||
protected SuggestionProvider<CommandSourceStack> suggest(Collection<String> suggestions)
|
||||
{
|
||||
return (context, builder) -> suggestMatching(builder, suggestions);
|
||||
}
|
||||
|
||||
protected SuggestionProvider<CommandSourceStack> suggestGreedyWords(Supplier<Collection<String>> suggestions)
|
||||
{
|
||||
return (context, builder) -> suggestLastGreedyToken(builder, suggestions.get());
|
||||
}
|
||||
|
||||
protected SuggestionProvider<CommandSourceStack> suggestGreedyWords(Collection<String> suggestions)
|
||||
{
|
||||
return (context, builder) -> suggestLastGreedyToken(builder, suggestions);
|
||||
}
|
||||
|
||||
protected CompletableFuture<Suggestions> suggestMatching(SuggestionsBuilder builder, Collection<String> suggestions)
|
||||
{
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (String suggestion : suggestions)
|
||||
{
|
||||
if (suggestion.toLowerCase(Locale.ROOT).startsWith(remaining))
|
||||
{
|
||||
builder.suggest(suggestion);
|
||||
}
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
protected CompletableFuture<Suggestions> suggestLastGreedyToken(SuggestionsBuilder builder, Collection<String> suggestions)
|
||||
{
|
||||
String remaining = builder.getRemaining();
|
||||
int tokenStart = remaining.lastIndexOf(' ') + 1;
|
||||
SuggestionsBuilder tokenBuilder = tokenStart == 0 ? builder : builder.createOffset(builder.getStart() + tokenStart);
|
||||
return suggestMatching(tokenBuilder, suggestions);
|
||||
}
|
||||
|
||||
protected CompletableFuture<Suggestions> suggestOptionalFlags(SuggestionsBuilder builder, Collection<String> flags)
|
||||
{
|
||||
String remaining = builder.getRemaining();
|
||||
if (remaining.isBlank())
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
List<String> availableFlags = Lists.newArrayList(flags);
|
||||
for (String token : remaining.split("\\s+"))
|
||||
{
|
||||
if (token.isBlank())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (flags.stream().anyMatch(flag -> flag.equalsIgnoreCase(token)))
|
||||
{
|
||||
availableFlags.removeIf(flag -> flag.equalsIgnoreCase(token));
|
||||
}
|
||||
}
|
||||
|
||||
String currentToken = remaining.substring(remaining.lastIndexOf(' ') + 1);
|
||||
if (!currentToken.startsWith("-"))
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
return suggestLastGreedyToken(builder, availableFlags);
|
||||
}
|
||||
|
||||
protected SuggestionProvider<CommandSourceStack> suggestPlayers()
|
||||
{
|
||||
return suggest(PlexUtils::getPlayerNameList);
|
||||
}
|
||||
|
||||
protected SuggestionProvider<CommandSourceStack> suggestPlayersAndAll()
|
||||
{
|
||||
return suggest(() ->
|
||||
{
|
||||
List<String> suggestions = Lists.newArrayList(PlexUtils.getPlayerNameList());
|
||||
suggestions.add("-a");
|
||||
return suggestions;
|
||||
});
|
||||
}
|
||||
|
||||
protected SuggestionProvider<CommandSourceStack> suggestPlayersAndAll(String permission)
|
||||
{
|
||||
return (context, builder) ->
|
||||
{
|
||||
if (!silentCheckPermission(context.getSource().getSender(), permission))
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
List<String> suggestions = Lists.newArrayList(PlexUtils.getPlayerNameList());
|
||||
suggestions.add("-a");
|
||||
return suggestMatching(builder, suggestions);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean canUse(CommandSourceStack source)
|
||||
{
|
||||
CommandSender sender = source.getSender();
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
if (commandSource == RequiredCommandSource.IN_GAME && sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
sender.sendMessage(messageComponent("noPermissionInGame"));
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (commandSource == RequiredCommandSource.IN_GAME)
|
||||
String permission = getPermission();
|
||||
if (permission.isEmpty())
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionConsole"));
|
||||
return true;
|
||||
}
|
||||
return !(sender instanceof Player player) || hasCachedPlexPlayer(player);
|
||||
}
|
||||
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
|
||||
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!perms.permission().isEmpty() && !player.hasPermission(perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
return hasCachedPlexPlayer(player) && player.hasPermission(permission);
|
||||
}
|
||||
|
||||
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console")) //telnet
|
||||
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console"))
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(sender.getName());
|
||||
|
||||
if (!perms.permission().isEmpty() && !plugin.getPermissions().playerHas(null, Bukkit.getPlayer(plexPlayer.getName()), perms.permission()))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", perms.permission()));
|
||||
return true;
|
||||
}
|
||||
Player player = plexPlayer == null ? null : Bukkit.getPlayer(plexPlayer.getName());
|
||||
return player != null && plugin.getPermissions().playerHas(null, player, permission);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int dispatchCommand(CommandContext<CommandSourceStack> context, String[] args)
|
||||
{
|
||||
CommandSender sender = context.getSource().getSender();
|
||||
if (!validateSourceAndPermission(sender))
|
||||
{
|
||||
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player) sender, args);
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
|
||||
if (component != null)
|
||||
{
|
||||
send(sender, component);
|
||||
@@ -172,125 +292,107 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
{
|
||||
send(sender, exceptionComponent(ex));
|
||||
}
|
||||
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private boolean validateSourceAndPermission(CommandSender sender)
|
||||
{
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionInGame"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (commandSource == RequiredCommandSource.IN_GAME && sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionConsole"));
|
||||
return false;
|
||||
}
|
||||
|
||||
String permission = getPermission();
|
||||
if (permission.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender instanceof Player player)
|
||||
{
|
||||
if (!hasCachedPlexPlayer(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!player.hasPermission(permission))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", permission));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender instanceof ConsoleCommandSender && !sender.getName().equalsIgnoreCase("console"))
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(sender.getName());
|
||||
Player player = plexPlayer == null ? null : Bukkit.getPlayer(plexPlayer.getName());
|
||||
if (player == null || !plugin.getPermissions().playerHas(null, player, permission))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", permission));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
private boolean hasCachedPlexPlayer(Player player)
|
||||
{
|
||||
List<String> list = smartTabComplete(sender, alias, args);
|
||||
return StringUtil.copyPartialMatches(args[args.length - 1], list, Lists.newArrayList());
|
||||
return plugin.getPlayerCache().getPlexPlayerMap().containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the String given is a matching command
|
||||
*
|
||||
* @param label The String to check
|
||||
* @return true if the string is a command name or alias
|
||||
*/
|
||||
private boolean matches(String label)
|
||||
private String[] splitExecutionArgs(String rawArgs)
|
||||
{
|
||||
if (params.aliases().split(",").length > 0)
|
||||
if (rawArgs.isBlank())
|
||||
{
|
||||
for (String alias : params.aliases().split(","))
|
||||
{
|
||||
if (alias.equalsIgnoreCase(label) || getName().equalsIgnoreCase(label))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
else if (params.aliases().split(",").length < 1)
|
||||
{
|
||||
return getName().equalsIgnoreCase(label);
|
||||
}
|
||||
return false;
|
||||
return rawArgs.trim().split("\\s+");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a PlexPlayer from Player object
|
||||
*
|
||||
* @param player The player object
|
||||
* @return PlexPlayer Object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
protected PlexPlayer getPlexPlayer(@NotNull Player player)
|
||||
{
|
||||
return plugin.getPlayerService().getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to an Audience
|
||||
*
|
||||
* @param audience The Audience to send the message to
|
||||
* @param s The message to send
|
||||
*/
|
||||
protected void send(Audience audience, String s)
|
||||
{
|
||||
audience.sendMessage(componentFromString(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to an Audience
|
||||
*
|
||||
* @param audience The Audience to send the message to
|
||||
* @param component The Component to send
|
||||
*/
|
||||
protected void send(Audience audience, Component component)
|
||||
{
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a sender has enough permissions or is high enough a rank
|
||||
*
|
||||
* @param sender A CommandSender
|
||||
* @param permission The permission to check
|
||||
* @return true if the sender has enough permissions
|
||||
*/
|
||||
protected boolean checkPermission(CommandSender sender, String permission)
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkPermission((Player) sender, permission);
|
||||
return checkPermission((Player)sender, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a sender has enough permissions or is high enough a rank
|
||||
*
|
||||
* @param sender A CommandSender
|
||||
* @param permission The permission to check
|
||||
* @return true if the sender has enough permissions
|
||||
*/
|
||||
protected boolean silentCheckPermission(CommandSender sender, String permission)
|
||||
{
|
||||
PlexLog.debug("Checking {0} with {1}", sender.getName(), permission);
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return silentCheckPermission((Player) sender, permission);
|
||||
return silentCheckPermission((Player)sender, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a player has enough permissions or is high enough a rank
|
||||
*
|
||||
* @param player The player object
|
||||
* @param permission The permission to check
|
||||
* @return true if the sender has enough permissions
|
||||
*/
|
||||
protected boolean checkPermission(Player player, String permission)
|
||||
{
|
||||
if (player instanceof ConsoleCommandSender)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!permission.isEmpty() && !player.hasPermission(permission))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
@@ -300,16 +402,9 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
|
||||
protected boolean silentCheckPermission(Player player, String permission)
|
||||
{
|
||||
return !permission.isEmpty() && player.hasPermission(permission);
|
||||
return permission.isEmpty() || player.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the UUID of the sender
|
||||
*
|
||||
* @param sender A command sender
|
||||
* @return A unique ID or null if the sender is console
|
||||
* @see UUID
|
||||
*/
|
||||
protected UUID getUUID(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player))
|
||||
@@ -319,82 +414,36 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin
|
||||
*
|
||||
* @return The instance of the plugin
|
||||
* @see Plex
|
||||
*/
|
||||
@Override
|
||||
public @NotNull Plex getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a sender is console
|
||||
*
|
||||
* @param sender A command sender
|
||||
* @return true if the sender is console
|
||||
*/
|
||||
protected boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a message entry from the "messages.yml" to a Component
|
||||
*
|
||||
* @param s The message entry
|
||||
* @param objects Any objects to replace in order
|
||||
* @return A Kyori Component
|
||||
*/
|
||||
protected Component messageComponent(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageComponent(s, objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a message entry from the "messages.yml" to a Component
|
||||
*
|
||||
* @param s The message entry
|
||||
* @param objects Any objects to replace in order
|
||||
* @return A Kyori Component
|
||||
*/
|
||||
protected Component messageComponent(String s, Component... objects)
|
||||
{
|
||||
return PlexUtils.messageComponent(s, objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a message entry from the "messages.yml" to a String
|
||||
*
|
||||
* @param s The message entry
|
||||
* @param objects Any objects to replace in order
|
||||
* @return A String
|
||||
*/
|
||||
protected String messageString(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageString(s, objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts usage to a Component
|
||||
*
|
||||
* @return A Kyori Component stating the usage
|
||||
*/
|
||||
protected Component usage()
|
||||
{
|
||||
return messageComponent("correctUsagePrefix").append(componentFromString(this.getUsage()).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts usage to a Component
|
||||
* <p>
|
||||
* s The usage to convert
|
||||
*
|
||||
* @return A Kyori Component stating the usage
|
||||
*/
|
||||
protected Component usage(String s)
|
||||
{
|
||||
return messageComponent("correctUsagePrefix").append(componentFromString(s).color(NamedTextColor.GRAY));
|
||||
@@ -418,7 +467,8 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
{
|
||||
return messageComponent("consoleMustDefinePlayer");
|
||||
}
|
||||
return PlexUtils.mmDeserialize(ex.getMessage());
|
||||
String message = ex.getMessage();
|
||||
return message == null ? componentFromString(ex.getClass().getSimpleName()) : PlexUtils.mmDeserialize(message);
|
||||
}
|
||||
|
||||
protected Player getNonNullPlayer(String name)
|
||||
@@ -430,7 +480,6 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
@@ -472,12 +521,6 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a legacy Kyori Component
|
||||
*
|
||||
* @param s The String to convert
|
||||
* @return A Kyori component
|
||||
*/
|
||||
protected Component componentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY);
|
||||
@@ -488,47 +531,16 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a String to a MiniMessage Component
|
||||
*
|
||||
* @param s The String to convert
|
||||
* @return A Kyori Component
|
||||
*/
|
||||
protected Component mmString(String s)
|
||||
{
|
||||
return PlexUtils.mmDeserialize(s);
|
||||
}
|
||||
|
||||
public CommandMap getMap()
|
||||
{
|
||||
return plugin.getServer().getCommandMap();
|
||||
}
|
||||
|
||||
private static Runtime requireRuntime()
|
||||
{
|
||||
if (runtime == null)
|
||||
{
|
||||
Plex plex = Plex.get();
|
||||
if (plex == null)
|
||||
{
|
||||
throw new IllegalStateException("ServerCommand runtime has not been installed by Plex");
|
||||
}
|
||||
return new Runtime()
|
||||
{
|
||||
@Override
|
||||
public Plex plugin()
|
||||
{
|
||||
return plex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Command command)
|
||||
{
|
||||
plex.getServer().getCommandMap().getKnownCommands().remove(command.getName().toLowerCase());
|
||||
command.getAliases().forEach(alias -> plex.getServer().getCommandMap().getKnownCommands().remove(alias.toLowerCase()));
|
||||
plex.getServer().getCommandMap().register("plex", command);
|
||||
}
|
||||
};
|
||||
throw new IllegalStateException("ServerCommand runtime has not been installed by Plex");
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
@@ -536,7 +548,5 @@ public abstract class ServerCommand extends Command implements PluginIdentifiabl
|
||||
public interface Runtime
|
||||
{
|
||||
Plex plugin();
|
||||
|
||||
void register(Command command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -11,10 +12,9 @@ import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import dev.plex.util.redis.MessageUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -26,6 +26,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
|
||||
public class AdminChatCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(greedyString("message")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "message")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -58,9 +66,4 @@ public class AdminChatCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -20,6 +20,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
|
||||
public class AdminworldCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -34,9 +40,4 @@ public class AdminworldCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -9,8 +9,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -23,6 +23,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "adventure", aliases = "gma,egma,eadventure,adventuremode,eadventuremode", description = "Set your own or another player's gamemode to adventure mode")
|
||||
public class AdventureCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(word("target")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.gamemode.adventure.others"))
|
||||
.suggests(suggestPlayersAndAll("plex.gamemode.adventure.others"))
|
||||
.executes(context -> executeCommand(context, string(context, "target"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -53,13 +63,4 @@ public class AdventureCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, "plex.gamemode.adventure.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -16,9 +17,9 @@ import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -27,11 +28,22 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "ban", usage = "/<command> <player> [reason] [-rb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||
@CommandParameters(name = "ban", usage = "/<command> <player> [message] [-rb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class BanCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player")))
|
||||
.then(greedyString("message")
|
||||
.suggests((context, builder) -> suggestOptionalFlags(builder, List.of("-rb")))
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "player"), string(context, "message"))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -102,17 +114,4 @@ public class BanCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
if (args.length > 1 && silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
return Collections.singletonList("-rb");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.punishment.Punishment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -20,6 +20,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.banlist")
|
||||
public class BanListCommand extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("purge")
|
||||
.executes(context -> executeCommand(context, "purge")));
|
||||
command.then(literal("clear")
|
||||
.executes(context -> executeCommand(context, "clear")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
@@ -53,9 +63,4 @@ public class BanListCommand extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return args.length == 1 && silentCheckPermission(sender, "plex.banlist.clear") ? List.of("purge", "clear") : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -11,8 +11,8 @@ import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -23,6 +23,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "bcastloginmessage", usage = "/<command> <player>", description = "Broadcast your login message (for vanish support)", aliases = "bcastlm")
|
||||
public class BcastLoginMessageCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -52,9 +60,4 @@ public class BcastLoginMessageCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.listener.impl.BlockListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -24,6 +23,20 @@ public class BlockEditCMD extends ServerCommand
|
||||
{
|
||||
private final BlockListener bl = new BlockListener();
|
||||
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("list")
|
||||
.executes(context -> executeCommand(context, "list")));
|
||||
command.then(literal("purge")
|
||||
.executes(context -> executeCommand(context, "purge")));
|
||||
command.then(literal("all")
|
||||
.executes(context -> executeCommand(context, "all")));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
@@ -101,19 +114,4 @@ public class BlockEditCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -20,6 +20,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
|
||||
public class CommandSpyCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
@@ -35,9 +41,4 @@ public class CommandSpyCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -20,6 +20,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||
public class ConsoleSayCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(greedyString("message")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "message")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -32,9 +40,4 @@ public class ConsoleSayCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -9,8 +9,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -23,6 +23,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "creative", aliases = "gmc,egmc,ecreative,eecreative,creativemode,ecreativemode", description = "Set your own or another player's gamemode to creative mode")
|
||||
public class CreativeCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(word("target")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.gamemode.creative.others"))
|
||||
.suggests(suggestPlayersAndAll("plex.gamemode.creative.others"))
|
||||
.executes(context -> executeCommand(context, string(context, "target"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -56,13 +66,4 @@ public class CreativeCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, "plex.gamemode.creative.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.menu.impl.MaterialMenu;
|
||||
import dev.plex.util.GameRuleUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@@ -26,6 +26,22 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.debug")
|
||||
public class DebugCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("redis-reset")
|
||||
.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, "redis-reset", string(context, "player")))));
|
||||
command.then(literal("gamerules")
|
||||
.executes(context -> executeCommand(context, "gamerules")));
|
||||
command.then(literal("aliases")
|
||||
.then(word("command")
|
||||
.executes(context -> executeCommand(context, "aliases", string(context, "command")))));
|
||||
command.then(literal("pagination")
|
||||
.executes(context -> executeCommand(context, "pagination")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -69,6 +85,11 @@ public class DebugCMD extends ServerCommand
|
||||
if (args.length == 2)
|
||||
{
|
||||
String commandName = args[1];
|
||||
PlexCommand plexCommand = plugin.getCommandHandler().getCommand(commandName);
|
||||
if (plexCommand != null)
|
||||
{
|
||||
return messageComponent("commandAliases", commandName, Arrays.toString(plexCommand.getAliases().toArray(new String[0])));
|
||||
}
|
||||
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
|
||||
if (command == null)
|
||||
{
|
||||
@@ -89,9 +110,4 @@ public class DebugCMD extends ServerCommand
|
||||
return usage();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -9,11 +10,11 @@ import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@@ -28,6 +29,29 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [entity] [radius]", aliases = "ew,rd")
|
||||
public class EntityWipeCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(greedyString("entities")
|
||||
.suggests(suggestGreedyWords(() ->
|
||||
{
|
||||
List<String> entities = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (Entity entity : world.getEntities())
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
entities.add(entity.getType().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
return entities;
|
||||
}))
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "entities")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
@@ -112,27 +136,7 @@ public class EntityWipeCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
List<String> entities = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
for (Entity entity : world.getEntities())
|
||||
{
|
||||
if (entity.getType() != EntityType.PLAYER)
|
||||
{
|
||||
entities.add(entity.getType().name());
|
||||
}
|
||||
}
|
||||
}
|
||||
return entities.stream().toList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private Integer parseInt(CommandSender sender, String string)
|
||||
private Integer parseInt(CommandSender sender, String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -20,6 +20,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
||||
public class FlatlandsCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -33,9 +39,4 @@ public class FlatlandsCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -12,8 +12,8 @@ import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -24,6 +24,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.freeze")
|
||||
public class FreezeCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -54,9 +62,4 @@ public class FreezeCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -8,10 +9,7 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -24,7 +22,32 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
||||
public class GamemodeCMD extends ServerCommand
|
||||
{
|
||||
private GameMode gamemode;
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
addMode(command, "survival", "s", "0");
|
||||
addMode(command, "creative", "c", "1");
|
||||
addMode(command, "adventure", "a", "2");
|
||||
addMode(command, "default", "d", "5");
|
||||
addMode(command, "spectator", "sp", "3", "6");
|
||||
}
|
||||
|
||||
private void addMode(LiteralArgumentBuilder<CommandSourceStack> command, String mode, String... aliases)
|
||||
{
|
||||
command.then(modeNode(mode));
|
||||
for (String alias : aliases)
|
||||
{
|
||||
command.then(modeNode(alias));
|
||||
}
|
||||
}
|
||||
|
||||
private LiteralArgumentBuilder<CommandSourceStack> modeNode(String mode)
|
||||
{
|
||||
return literal(mode)
|
||||
.executes(context -> executeCommand(context, mode))
|
||||
.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, mode, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
@@ -37,47 +60,43 @@ public class GamemodeCMD extends ServerCommand
|
||||
{
|
||||
case "survival", "s", "0" ->
|
||||
{
|
||||
gamemode = GameMode.SURVIVAL;
|
||||
update(sender, playerSender, GameMode.SURVIVAL);
|
||||
update(sender, playerSender, args, GameMode.SURVIVAL);
|
||||
return null;
|
||||
}
|
||||
case "creative", "c", "1" ->
|
||||
{
|
||||
gamemode = GameMode.CREATIVE;
|
||||
update(sender, playerSender, GameMode.CREATIVE);
|
||||
update(sender, playerSender, args, GameMode.CREATIVE);
|
||||
return null;
|
||||
}
|
||||
case "adventure", "a", "2" ->
|
||||
{
|
||||
gamemode = GameMode.ADVENTURE;
|
||||
update(sender, playerSender, GameMode.ADVENTURE);
|
||||
update(sender, playerSender, args, GameMode.ADVENTURE);
|
||||
return null;
|
||||
}
|
||||
case "default", "d", "5" ->
|
||||
{
|
||||
gamemode = plugin.getServer().getDefaultGameMode();
|
||||
update(sender, playerSender, plugin.getServer().getDefaultGameMode());
|
||||
update(sender, playerSender, args, plugin.getServer().getDefaultGameMode());
|
||||
return null;
|
||||
}
|
||||
case "spectator", "sp", "3", "6" ->
|
||||
{
|
||||
gamemode = GameMode.SPECTATOR;
|
||||
checkPermission(sender, "plex.gamemode.spectator");
|
||||
update(sender, playerSender, GameMode.SPECTATOR);
|
||||
update(sender, playerSender, args, GameMode.SPECTATOR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return usage();
|
||||
}
|
||||
|
||||
private void update(CommandSender sender, Player playerSender, String[] args, GameMode gameMode)
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
checkPermission(sender, "plex.gamemode.others");
|
||||
Player player = getNonNullPlayer(args[1]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gamemode));
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gameMode));
|
||||
return;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void update(CommandSender sender, Player playerSender, GameMode gameMode)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||
@@ -88,20 +107,4 @@ public class GamemodeCMD extends ServerCommand
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("creative", "survival", "adventure", "spectator", "default");
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
if (silentCheckPermission(sender, "plex.gamemode.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -16,8 +16,8 @@ import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -26,10 +26,20 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
||||
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>", aliases = "ekick")
|
||||
@CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||
public class KickCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player")))
|
||||
.then(greedyString("reason")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "player"), string(context, "reason"))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -70,9 +80,4 @@ public class KickCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -8,9 +9,9 @@ import dev.plex.hook.VaultHook;
|
||||
import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -23,6 +24,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.list")
|
||||
public class ListCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("-d")
|
||||
.executes(context -> executeCommand(context, "-d")));
|
||||
command.then(literal("-v")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.list.vanished"))
|
||||
.executes(context -> executeCommand(context, "-v")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -67,12 +79,4 @@ public class ListCMD extends ServerCommand
|
||||
return list;
|
||||
}
|
||||
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
return List.of("-d", "-v");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -18,6 +18,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
|
||||
public class LocalSpawnCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -26,9 +32,4 @@ public class LocalSpawnCMD extends ServerCommand
|
||||
return messageComponent("teleportedToWorldSpawn");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -19,6 +19,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.lockup")
|
||||
public class LockupCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -38,9 +46,4 @@ public class LockupCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -20,6 +20,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||
public class MasterbuilderworldCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -34,9 +40,4 @@ public class MasterbuilderworldCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -7,9 +8,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
@@ -23,6 +23,19 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.moblimit", source = RequiredCommandSource.ANY)
|
||||
public class MobLimitCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("on")
|
||||
.executes(context -> executeCommand(context, "on")));
|
||||
command.then(literal("off")
|
||||
.executes(context -> executeCommand(context, "off")));
|
||||
command.then(literal("setmax")
|
||||
.then(nonNegativeInteger("limit")
|
||||
.executes(context -> executeCommand(context, "setmax", String.valueOf(integer(context, "limit"))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -83,21 +96,4 @@ public class MobLimitCMD extends ServerCommand
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("on", "off", "setmax");
|
||||
}
|
||||
if (args.length == 2 && args[0].equals("setmax"))
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -9,9 +10,9 @@ import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -30,6 +31,15 @@ public class MobPurgeCMD extends ServerCommand
|
||||
{
|
||||
private final List<EntityType> MOB_TYPES = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(word("mob")
|
||||
.suggests(suggest(this::getAllMobs))
|
||||
.executes(context -> executeCommand(context, string(context, "mob"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
@@ -112,12 +122,4 @@ public class MobPurgeCMD extends ServerCommand
|
||||
return mobs;
|
||||
}
|
||||
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
return getAllMobs();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -12,18 +12,26 @@ import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
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;
|
||||
|
||||
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu")
|
||||
@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/<command> <player>", aliases = "stfu,emute,silence,esilence")
|
||||
@CommandPermissions(permission = "plex.mute")
|
||||
public class MuteCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -60,9 +68,4 @@ public class MuteCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
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 java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -28,6 +27,23 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.notes")
|
||||
public class NotesCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.then(literal("list")
|
||||
.executes(context -> executeCommand(context, string(context, "player"), "list")))
|
||||
.then(literal("clear")
|
||||
.executes(context -> executeCommand(context, string(context, "player"), "clear")))
|
||||
.then(literal("add")
|
||||
.then(greedyString("note")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "player"), "add", string(context, "note"))))))
|
||||
.then(literal("remove")
|
||||
.then(nonNegativeInteger("id")
|
||||
.executes(context -> executeCommand(context, string(context, "player"), "remove", String.valueOf(integer(context, "id")))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -135,21 +151,4 @@ public class NotesCMD extends ServerCommand
|
||||
send(sender, noteList.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
return Arrays.asList("list", "add", "remove", "clear");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -12,11 +13,10 @@ import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -31,6 +31,24 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class PlexCMD extends ServerCommand
|
||||
{
|
||||
// Don't modify this command
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("reload")
|
||||
.executes(context -> executeCommand(context, "reload")));
|
||||
command.then(literal("redis")
|
||||
.executes(context -> executeCommand(context, "redis")));
|
||||
command.then(literal("update")
|
||||
.executes(context -> executeCommand(context, "update")));
|
||||
command.then(literal("modules")
|
||||
.executes(context -> executeCommand(context, "modules"))
|
||||
.then(literal("reload")
|
||||
.executes(context -> executeCommand(context, "modules", "reload")))
|
||||
.then(literal("update")
|
||||
.executes(context -> executeCommand(context, "modules", "update"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -127,20 +145,6 @@ public class PlexCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("reload", "redis", "modules", "update");
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("modules"))
|
||||
{
|
||||
return Arrays.asList("reload", "update");
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// Owners and developers only have access
|
||||
private boolean hasUpdateAccess(Player player, CommandSender sender)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -10,10 +10,9 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.impl.PunishedPlayerMenu;
|
||||
import dev.plex.menu.impl.PunishmentMenu;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -26,6 +25,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
|
||||
public class PunishmentsCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -49,9 +56,4 @@ public class PunishmentsCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -20,6 +20,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
|
||||
public class RawSayCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(greedyString("message")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "message")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -32,9 +40,4 @@ public class RawSayCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
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 java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,6 +20,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
|
||||
public class RemoveLoginMessageCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("-o")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.removeloginmessage.others"))
|
||||
.executes(context -> executeCommand(context, "-o"))
|
||||
.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, "-o", string(context, "player")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -57,16 +67,4 @@ public class RemoveLoginMessageCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (silentCheckPermission(sender, "plex.removeloginmessage.others"))
|
||||
{
|
||||
return List.of("-o");
|
||||
}
|
||||
}
|
||||
return args.length == 2 && silentCheckPermission(sender, "plex.removeloginmessage.others") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -20,6 +20,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
|
||||
public class SayCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(greedyString("message")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "message")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -32,9 +40,4 @@ public class SayCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -13,6 +13,7 @@ import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -27,6 +28,38 @@ public class SetLoginMessageCMD extends ServerCommand
|
||||
{
|
||||
private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name");
|
||||
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(greedyString("message")
|
||||
.suggests((context, builder) ->
|
||||
{
|
||||
if (!silentCheckPermission(context.getSource().getSender(), "plex.setloginmessage.others"))
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
String remaining = builder.getRemaining();
|
||||
if (remaining.isBlank())
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
String[] tokens = remaining.split("\\s+", -1);
|
||||
if (tokens.length == 1 && tokens[0].startsWith("-"))
|
||||
{
|
||||
return suggestMatching(builder, List.of("-o"));
|
||||
}
|
||||
if (tokens.length == 2 && tokens[0].equalsIgnoreCase("-o"))
|
||||
{
|
||||
return suggestLastGreedyToken(builder, PlexUtils.getPlayerNameList());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "message")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -83,16 +116,4 @@ public class SetLoginMessageCMD extends ServerCommand
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -12,12 +13,12 @@ import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@@ -31,6 +32,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
|
||||
public class SmiteCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player")))
|
||||
.then(greedyString("reason")
|
||||
.suggests((context, builder) -> suggestOptionalFlags(builder, List.of("-ci", "-q")))
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "player"), string(context, "reason"))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -45,25 +57,25 @@ public class SmiteCMD extends ServerCommand
|
||||
|
||||
if (args.length >= 2)
|
||||
{
|
||||
if (args[args.length - 1].equalsIgnoreCase("-q"))
|
||||
List<String> reasonParts = new ArrayList<>();
|
||||
for (int i = 1; i < args.length; i++)
|
||||
{
|
||||
silent = true;
|
||||
if (args.length >= 3)
|
||||
if (args[i].equalsIgnoreCase("-q"))
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
|
||||
silent = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (args[args.length - 1].equalsIgnoreCase("-ci"))
|
||||
{
|
||||
clearInv = true;
|
||||
if (args.length >= 3)
|
||||
if (args[i].equalsIgnoreCase("-ci"))
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length - 1), " ");
|
||||
clearInv = true;
|
||||
continue;
|
||||
}
|
||||
reasonParts.add(args[i]);
|
||||
}
|
||||
else
|
||||
|
||||
if (!reasonParts.isEmpty())
|
||||
{
|
||||
reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
|
||||
reason = StringUtils.join(reasonParts, " ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,13 +133,4 @@ public class SmiteCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, this.getPermission()) && args.length == 1)
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -9,8 +9,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -23,6 +23,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode")
|
||||
public class SpectatorCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(word("target")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.gamemode.spectator.others"))
|
||||
.suggests(suggestPlayersAndAll("plex.gamemode.spectator.others"))
|
||||
.executes(context -> executeCommand(context, string(context, "target"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -55,13 +65,4 @@ public class SpectatorCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, "plex.gamemode.spectator.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -9,8 +9,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -23,6 +23,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "survival", aliases = "gms,egms,esurvival,survivalmode,esurvivalmode", description = "Set your own or another player's gamemode to survival mode")
|
||||
public class SurvivalCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(word("target")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.gamemode.survival.others"))
|
||||
.suggests(suggestPlayersAndAll("plex.gamemode.survival.others"))
|
||||
.executes(context -> executeCommand(context, string(context, "target"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -56,13 +66,4 @@ public class SurvivalCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (silentCheckPermission(sender, "plex.gamemode.survival.others"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -8,10 +9,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
@@ -26,6 +25,20 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
|
||||
public class TagCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("set")
|
||||
.executes(context -> executeCommand(context, "set"))
|
||||
.then(greedyString("prefix")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy("set", string(context, "prefix"))))));
|
||||
command.then(literal("clear")
|
||||
.executes(context -> executeCommand(context, "clear"))
|
||||
.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, "clear", string(context, "player")))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -92,25 +105,6 @@ public class TagCMD extends ServerCommand
|
||||
return usage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -16,6 +16,7 @@ import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -24,11 +25,23 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason] [-rb]", description = "Temporarily ban a player")
|
||||
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [message] [-rb]", description = "Temporarily ban a player")
|
||||
@CommandPermissions(permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class TempbanCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.then(word("time")
|
||||
.executes(context -> executeCommand(context, string(context, "player"), string(context, "time")))
|
||||
.then(greedyString("message")
|
||||
.suggests((context, builder) -> suggestOptionalFlags(builder, List.of("-rb")))
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "player"), string(context, "time"), string(context, "message")))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -56,7 +69,7 @@ public class TempbanCMD extends ServerCommand
|
||||
if (args.length > 2)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 2, args.length);
|
||||
String newReason = StringUtils.normalizeSpace(reason.replace("-nrb", ""));
|
||||
String newReason = StringUtils.normalizeSpace(reason.replace("-rb", ""));
|
||||
punishment.setReason(newReason.trim().isEmpty() ? messageString("noReasonProvided") : newReason);
|
||||
rollBack = reason.startsWith("-rb") || reason.endsWith("-rb");
|
||||
}
|
||||
@@ -82,9 +95,4 @@ public class TempbanCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -12,8 +12,8 @@ import dev.plex.util.TimeUtils;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -25,6 +25,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.tempmute")
|
||||
public class TempmuteCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.then(word("time")
|
||||
.executes(context -> executeCommand(context, string(context, "player"), string(context, "time")))
|
||||
.then(greedyString("reason")
|
||||
.executes(context -> executeCommand(context, argsWithGreedy(string(context, "player"), string(context, "time"), string(context, "reason")))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -85,9 +96,4 @@ public class TempmuteCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -8,8 +8,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.impl.ToggleMenu;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -20,6 +20,24 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandPermissions(permission = "plex.toggle", source = RequiredCommandSource.ANY)
|
||||
public class ToggleCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("explosions")
|
||||
.executes(context -> executeCommand(context, "explosions")));
|
||||
command.then(literal("fluidspread")
|
||||
.executes(context -> executeCommand(context, "fluidspread")));
|
||||
command.then(literal("drops")
|
||||
.executes(context -> executeCommand(context, "drops")));
|
||||
command.then(literal("redstone")
|
||||
.executes(context -> executeCommand(context, "redstone")));
|
||||
command.then(literal("pvp")
|
||||
.executes(context -> executeCommand(context, "pvp")));
|
||||
command.then(literal("chat")
|
||||
.executes(context -> executeCommand(context, "chat")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -73,12 +91,6 @@ public class ToggleCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
private Component toggleListItem(String nameKey, String toggle)
|
||||
{
|
||||
return messageComponent("toggleListItem", messageString(nameKey), status(toggle));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -10,8 +10,8 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -23,6 +23,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class UnbanCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -54,9 +62,4 @@ public class UnbanCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -11,8 +11,8 @@ import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -23,6 +23,14 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
|
||||
public class UnfreezeCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -50,9 +58,4 @@ public class UnfreezeCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -11,8 +11,8 @@ import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -20,9 +20,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.unmute")
|
||||
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>")
|
||||
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>", aliases = "eunmute")
|
||||
public class UnmuteCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(playerArgument("player")
|
||||
.executes(context -> executeCommand(context, string(context, "player"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -50,9 +58,4 @@ public class UnmuteCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@@ -23,6 +23,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
@CommandParameters(name = "whohas", description = "Returns a list of players with a specific item in their inventory.", usage = "/<command> <material>", aliases = "wh")
|
||||
public class WhoHasCMD extends ServerCommand
|
||||
{
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(word("material")
|
||||
.suggests(suggest(() -> Arrays.stream(Material.values()).map(Enum::name).toList()))
|
||||
.executes(context -> executeCommand(context, string(context, "material")))
|
||||
.then(literal("clear")
|
||||
.executes(context -> executeCommand(context, string(context, "material"), "clear"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
{
|
||||
@@ -65,17 +76,4 @@ public class WhoHasCMD extends ServerCommand
|
||||
Component.join(JoinConfiguration.commas(true), players)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||
{
|
||||
if (args.length == 1 && silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
return Arrays.stream(Material.values()).map(Enum::name).toList();
|
||||
}
|
||||
else if (args.length == 2 && silentCheckPermission(sender, "plex.whohas.clear"))
|
||||
{
|
||||
return Collections.singletonList("clear");
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
@@ -10,6 +11,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@@ -24,6 +26,39 @@ public class WorldCMD extends ServerCommand
|
||||
{
|
||||
private static final Pattern UUID_PATTERN = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
|
||||
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(word("world")
|
||||
.suggests((context, builder) ->
|
||||
{
|
||||
if (!(context.getSource().getSender() instanceof Player player))
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
List<String> completions = Lists.newArrayList();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
String worldName = world.getName();
|
||||
try
|
||||
{
|
||||
UUID uuid = UUID.fromString(worldName);
|
||||
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player, "plex.world.playerworlds"))
|
||||
{
|
||||
completions.add(worldName);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
completions.add(worldName);
|
||||
}
|
||||
}
|
||||
return suggestMatching(builder, completions);
|
||||
})
|
||||
.executes(context -> executeCommand(context, string(context, "world"))));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
{
|
||||
@@ -43,33 +78,4 @@ public class WorldCMD extends ServerCommand
|
||||
return messageComponent("playerWorldTeleport", world.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<String> smartTabComplete(@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 && silentCheckPermission(sender, this.getPermission()))
|
||||
{
|
||||
@NotNull List<World> worlds = Bukkit.getWorlds();
|
||||
for (World world : worlds)
|
||||
{
|
||||
String worldName = world.getName();
|
||||
|
||||
try
|
||||
{
|
||||
final UUID uuid = UUID.fromString(worldName);
|
||||
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player, "plex.world.playerworlds"))
|
||||
{
|
||||
completions.add(worldName);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
completions.add(worldName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,131 @@
|
||||
package dev.plex.handlers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.ServerCommand;
|
||||
import dev.plex.command.impl.DebugCMD;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.impl.*;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.ReflectionsUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Locale;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CommandHandler
|
||||
{
|
||||
private final Plex plugin;
|
||||
private final List<PlexCommand> commands = new ArrayList<>();
|
||||
private boolean lifecycleRegistered;
|
||||
|
||||
public CommandHandler(Plex plugin)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
Set<Class<? extends ServerCommand>> commandSet = ReflectionsUtil.getClassesBySubType("dev.plex.command.impl", ServerCommand.class);
|
||||
List<ServerCommand> commands = Lists.newArrayList();
|
||||
registerBuiltInCommands(plugin.config.getBoolean("debug"));
|
||||
commands.addAll(plugin.getPendingCommands());
|
||||
plugin.getPendingCommands().clear();
|
||||
plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> register(event.registrar()));
|
||||
}
|
||||
|
||||
commandSet.forEach(clazz ->
|
||||
public void registerCommand(PlexCommand command)
|
||||
{
|
||||
commands.add(command);
|
||||
if (lifecycleRegistered)
|
||||
{
|
||||
try
|
||||
PlexLog.warn("Command {0} was registered after the Brigadier command lifecycle event; it will be included on the next command reload.", command.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterCommand(PlexCommand command)
|
||||
{
|
||||
commands.remove(command);
|
||||
}
|
||||
|
||||
public @Nullable PlexCommand getCommand(String name)
|
||||
{
|
||||
String normalized = name.toLowerCase(Locale.ROOT);
|
||||
return commands.stream()
|
||||
.filter(command -> command.getName().equalsIgnoreCase(name) ||
|
||||
command.getAliases().stream().map(alias -> alias.toLowerCase(Locale.ROOT)).toList().contains(normalized))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public boolean isAliasFor(String commandName, String alias)
|
||||
{
|
||||
PlexCommand command = getCommand(commandName);
|
||||
if (command == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
String normalized = alias.toLowerCase(Locale.ROOT);
|
||||
return command.getAliases().stream().map(value -> value.toLowerCase(Locale.ROOT)).toList().contains(normalized);
|
||||
}
|
||||
|
||||
private void register(Commands registrar)
|
||||
{
|
||||
int labels = 0;
|
||||
for (PlexCommand command : commands)
|
||||
{
|
||||
var registeredLabels = registrar.register(command.buildCommand(), command.getDescription(), command.getAliases());
|
||||
labels += registeredLabels.size();
|
||||
for (String alias : command.getAliases())
|
||||
{
|
||||
if (plugin.config.getBoolean("debug") && DebugCMD.class.isAssignableFrom(clazz))
|
||||
if (!registeredLabels.contains(alias) && !registeredLabels.contains("plex:" + alias))
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
}
|
||||
else
|
||||
{
|
||||
commands.add(clazz.getConstructor().newInstance());
|
||||
PlexLog.warn("Command alias {0} for {1} was not registered, likely because another command already owns it.", alias, command.getName());
|
||||
}
|
||||
}
|
||||
catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException ex)
|
||||
{
|
||||
PlexLog.error("Failed to register " + clazz.getSimpleName() + " as a command!");
|
||||
}
|
||||
});
|
||||
PlexLog.log(String.format("Registered %s commands from %s classes!", commands.size(), commandSet.size()));
|
||||
}
|
||||
lifecycleRegistered = true;
|
||||
PlexLog.log("Registered {0} Brigadier commands with {1} root labels.", commands.size(), labels);
|
||||
}
|
||||
|
||||
private void registerBuiltInCommands(boolean debugEnabled)
|
||||
{
|
||||
commands.addAll(List.of(
|
||||
new AdminChatCMD(),
|
||||
new AdminworldCMD(),
|
||||
new AdventureCMD(),
|
||||
new BanCMD(),
|
||||
new BanListCommand(),
|
||||
new BcastLoginMessageCMD(),
|
||||
new BlockEditCMD(),
|
||||
new CommandSpyCMD(),
|
||||
new ConsoleSayCMD(),
|
||||
new CreativeCMD(),
|
||||
new EntityWipeCMD(),
|
||||
new FlatlandsCMD(),
|
||||
new FreezeCMD(),
|
||||
new GamemodeCMD(),
|
||||
new KickCMD(),
|
||||
new ListCMD(),
|
||||
new LocalSpawnCMD(),
|
||||
new LockupCMD(),
|
||||
new MasterbuilderworldCMD(),
|
||||
new MobLimitCMD(),
|
||||
new MobPurgeCMD(),
|
||||
new MuteCMD(),
|
||||
new NotesCMD(),
|
||||
new PlexCMD(),
|
||||
new PunishmentsCMD(),
|
||||
new RawSayCMD(),
|
||||
new RemoveLoginMessageCMD(),
|
||||
new SayCMD(),
|
||||
new SetLoginMessageCMD(),
|
||||
new SmiteCMD(),
|
||||
new SpectatorCMD(),
|
||||
new SurvivalCMD(),
|
||||
new TagCMD(),
|
||||
new TempbanCMD(),
|
||||
new TempmuteCMD(),
|
||||
new ToggleCMD(),
|
||||
new UnbanCMD(),
|
||||
new UnfreezeCMD(),
|
||||
new UnmuteCMD(),
|
||||
new WhoHasCMD(),
|
||||
new WorldCMD()
|
||||
));
|
||||
if (debugEnabled)
|
||||
{
|
||||
commands.add(new DebugCMD());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,13 @@ public class MuteListener extends ServerListenerBase
|
||||
|
||||
for (String command : commands)
|
||||
{
|
||||
if (plugin.getCommandHandler() != null && plugin.getCommandHandler().isAliasFor(command, message))
|
||||
{
|
||||
PlexLog.debug("Matches Brigadier alias");
|
||||
event.getPlayer().sendMessage(PlexUtils.messageComponent("muted"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Command cmd = Bukkit.getCommandMap().getCommand(command);
|
||||
if (cmd == null)
|
||||
{
|
||||
|
||||
@@ -103,6 +103,12 @@ public class TogglesListener extends ServerListenerBase
|
||||
|
||||
for (String command : commands)
|
||||
{
|
||||
if (plugin.getCommandHandler() != null && plugin.getCommandHandler().isAliasFor(command, message))
|
||||
{
|
||||
event.getPlayer().sendMessage(PlexUtils.messageComponent("chatIsOff"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Command cmd = Bukkit.getCommandMap().getCommand(command);
|
||||
if (cmd == null)
|
||||
{
|
||||
|
||||
@@ -154,17 +154,6 @@ public class ModuleManager
|
||||
module.getCommands().stream().toList().forEach(plexCommand ->
|
||||
{
|
||||
module.unregisterCommand(plexCommand);
|
||||
plugin.getServer().getCommandMap().getKnownCommands().remove(plexCommand.getName());
|
||||
plexCommand.unregister(plugin.getServer().getCommandMap());
|
||||
try
|
||||
{
|
||||
plugin.getServer().getCommandMap().getCommand(plexCommand.getName()).unregister(plugin.getServer().getCommandMap());
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
|
||||
}
|
||||
plexCommand.getAliases().forEach(alias -> plugin.getServer().getCommandMap().getKnownCommands().remove(alias));
|
||||
});
|
||||
module.getListeners().stream().toList().forEach(module::unregisterListener);
|
||||
module.disable();
|
||||
|
||||
Reference in New Issue
Block a user