mirror of
https://github.com/plexusorg/Plex.git
synced 2026-06-03 21:16:55 +00:00
Finish up Brigadier
This commit is contained in:
@@ -4,6 +4,12 @@ import dev.plex.command.PlexCommand;
|
||||
|
||||
/**
|
||||
* Registers and unregisters Plex commands with the running platform.
|
||||
*
|
||||
* <p>Commands are installed through Paper's Brigadier command lifecycle. A command
|
||||
* registered before that lifecycle event is active in the current server command
|
||||
* tree. A command registered or unregistered after that lifecycle event is staged
|
||||
* in Plex's registry and takes effect the next time Paper rebuilds lifecycle
|
||||
* commands, such as on a full server restart.</p>
|
||||
*/
|
||||
public interface CommandApi
|
||||
{
|
||||
@@ -17,7 +23,20 @@ public interface CommandApi
|
||||
/**
|
||||
* Unregisters a command from Plex.
|
||||
*
|
||||
* <p>If Paper's Brigadier lifecycle has already registered commands for this
|
||||
* server run, the command may remain in the active dispatcher until Paper
|
||||
* rebuilds lifecycle commands.</p>
|
||||
*
|
||||
* @param command command to unregister
|
||||
*/
|
||||
void unregister(PlexCommand command);
|
||||
|
||||
/**
|
||||
* Returns whether command changes are staged for the next Paper command
|
||||
* lifecycle rebuild.
|
||||
*
|
||||
* @return {@code true} when command registration or unregistration changed
|
||||
* after the active command lifecycle was built
|
||||
*/
|
||||
boolean requiresLifecycleReload();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Explicit metadata for a Plex command.
|
||||
*
|
||||
* @param name primary command name
|
||||
* @param description short command description
|
||||
* @param usage command usage text; {@code <command>} is replaced with the command name
|
||||
* @param aliases alternate root labels for the command
|
||||
* @param permission permission node required to use the command
|
||||
* @param requiredSource source restriction for command execution
|
||||
*/
|
||||
public record CommandSpec(
|
||||
String name,
|
||||
String description,
|
||||
String usage,
|
||||
List<String> aliases,
|
||||
String permission,
|
||||
RequiredCommandSource requiredSource)
|
||||
{
|
||||
/**
|
||||
* Creates a command spec builder for the given primary name.
|
||||
*
|
||||
* @param name primary command name
|
||||
* @return command spec builder
|
||||
*/
|
||||
public static Builder builder(String name)
|
||||
{
|
||||
return new Builder(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns usage text with the command placeholder expanded.
|
||||
*
|
||||
* @return command usage text for this command
|
||||
*/
|
||||
public String resolvedUsage()
|
||||
{
|
||||
return usage.replace("<command>", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for command specs.
|
||||
*/
|
||||
public static final class Builder
|
||||
{
|
||||
private final String name;
|
||||
private String description = "";
|
||||
private String usage = "/<command>";
|
||||
private List<String> aliases = List.of();
|
||||
private String permission = "";
|
||||
private RequiredCommandSource requiredSource = RequiredCommandSource.ANY;
|
||||
|
||||
private Builder(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command description.
|
||||
*
|
||||
* @param description command description
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder description(String description)
|
||||
{
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command usage text.
|
||||
*
|
||||
* @param usage command usage text
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder usage(String usage)
|
||||
{
|
||||
this.usage = usage;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets comma-separated command aliases.
|
||||
*
|
||||
* @param aliases comma-separated command aliases
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder aliases(String aliases)
|
||||
{
|
||||
if (aliases == null || aliases.isBlank())
|
||||
{
|
||||
this.aliases = List.of();
|
||||
return this;
|
||||
}
|
||||
this.aliases = Arrays.stream(aliases.split(","))
|
||||
.map(String::trim)
|
||||
.filter(alias -> !alias.isBlank())
|
||||
.toList();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets command aliases.
|
||||
*
|
||||
* @param aliases command aliases
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder aliases(List<String> aliases)
|
||||
{
|
||||
this.aliases = aliases == null ? List.of() : new ArrayList<>(aliases);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the required permission node.
|
||||
*
|
||||
* @param permission permission node
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder permission(String permission)
|
||||
{
|
||||
this.permission = permission == null ? "" : permission;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the required command source.
|
||||
*
|
||||
* @param requiredSource required command source
|
||||
* @return this builder
|
||||
*/
|
||||
public Builder source(RequiredCommandSource requiredSource)
|
||||
{
|
||||
this.requiredSource = requiredSource == null ? RequiredCommandSource.ANY : requiredSource;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the command spec.
|
||||
*
|
||||
* @return command spec
|
||||
*/
|
||||
public CommandSpec build()
|
||||
{
|
||||
return new CommandSpec(name, description, usage, List.copyOf(aliases), permission, requiredSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -13,6 +10,13 @@ import java.util.List;
|
||||
*/
|
||||
public interface PlexCommand
|
||||
{
|
||||
/**
|
||||
* Returns explicit command metadata.
|
||||
*
|
||||
* @return command metadata
|
||||
*/
|
||||
CommandSpec commandSpec();
|
||||
|
||||
/**
|
||||
* Builds the Brigadier command tree for this command.
|
||||
*
|
||||
@@ -20,38 +24,6 @@ public interface PlexCommand
|
||||
*/
|
||||
LiteralCommandNode<CommandSourceStack> buildCommand();
|
||||
|
||||
/**
|
||||
* Reads command parameter metadata from {@link CommandParameters}.
|
||||
*
|
||||
* @return command parameter metadata
|
||||
* @throws IllegalStateException if the command class is missing {@link CommandParameters}
|
||||
*/
|
||||
default CommandParameters parameters()
|
||||
{
|
||||
CommandParameters parameters = getClass().getAnnotation(CommandParameters.class);
|
||||
if (parameters == null)
|
||||
{
|
||||
throw new IllegalStateException(getClass().getName() + " requires a CommandParameters annotation");
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads command permission metadata from {@link CommandPermissions}.
|
||||
*
|
||||
* @return command permission metadata
|
||||
* @throws IllegalStateException if the command class is missing {@link CommandPermissions}
|
||||
*/
|
||||
default CommandPermissions permissions()
|
||||
{
|
||||
CommandPermissions permissions = getClass().getAnnotation(CommandPermissions.class);
|
||||
if (permissions == null)
|
||||
{
|
||||
throw new IllegalStateException(getClass().getName() + " requires a CommandPermissions annotation");
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary command name.
|
||||
*
|
||||
@@ -59,7 +31,7 @@ public interface PlexCommand
|
||||
*/
|
||||
default String getName()
|
||||
{
|
||||
return parameters().name();
|
||||
return commandSpec().name();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +41,7 @@ public interface PlexCommand
|
||||
*/
|
||||
default String getDescription()
|
||||
{
|
||||
return parameters().description();
|
||||
return commandSpec().description();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +51,7 @@ public interface PlexCommand
|
||||
*/
|
||||
default String getUsage()
|
||||
{
|
||||
return parameters().usage().replace("<command>", getName());
|
||||
return commandSpec().resolvedUsage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +61,7 @@ public interface PlexCommand
|
||||
*/
|
||||
default String getPermission()
|
||||
{
|
||||
return permissions().permission();
|
||||
return commandSpec().permission();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,24 +71,16 @@ public interface PlexCommand
|
||||
*/
|
||||
default RequiredCommandSource getRequiredSource()
|
||||
{
|
||||
return permissions().source();
|
||||
return commandSpec().requiredSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns command aliases as a trimmed list.
|
||||
*
|
||||
* @return comma-separated aliases from {@link CommandParameters#aliases()} as a trimmed list
|
||||
* @return command aliases
|
||||
*/
|
||||
default List<String> getAliases()
|
||||
{
|
||||
String aliases = parameters().aliases();
|
||||
if (aliases.isBlank())
|
||||
{
|
||||
return List.of();
|
||||
}
|
||||
return Arrays.stream(aliases.split(","))
|
||||
.map(String::trim)
|
||||
.filter(alias -> !alias.isBlank())
|
||||
.toList();
|
||||
return commandSpec().aliases();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package dev.plex.command.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Declares display and invocation metadata for a Plex command.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandParameters
|
||||
{
|
||||
/**
|
||||
* Returns the primary command name.
|
||||
*
|
||||
* @return primary command name
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Returns the short command description.
|
||||
*
|
||||
* @return short command description
|
||||
*/
|
||||
String description() default "";
|
||||
|
||||
/**
|
||||
* Returns the command usage text.
|
||||
*
|
||||
* @return command usage text; {@code <command>} is replaced with the command name
|
||||
*/
|
||||
String usage() default "/<command>";
|
||||
|
||||
/**
|
||||
* Returns comma-separated command aliases.
|
||||
*
|
||||
* @return comma-separated command aliases
|
||||
*/
|
||||
String aliases() default "";
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package dev.plex.command.annotation;
|
||||
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Declares permission and command-source requirements for a Plex command.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandPermissions
|
||||
{
|
||||
/**
|
||||
* Returns the permission node required to use the command.
|
||||
*
|
||||
* @return permission node required to use the command
|
||||
*/
|
||||
String permission() default "";
|
||||
|
||||
/**
|
||||
* Returns the command source required to run the command.
|
||||
*
|
||||
* @return command source required to run the command
|
||||
*/
|
||||
RequiredCommandSource source() default RequiredCommandSource.ANY;
|
||||
}
|
||||
@@ -106,6 +106,13 @@ public abstract class PlexModule
|
||||
/**
|
||||
* Registers and tracks a command owned by this module.
|
||||
*
|
||||
* <p>Paper Brigadier commands are lifecycle-registered. Commands registered
|
||||
* during module load before Plex's command handler initializes are active for
|
||||
* the current startup. Commands registered after the Paper command lifecycle
|
||||
* has already run are tracked by Plex but are not guaranteed to appear in the
|
||||
* live dispatcher until Paper rebuilds lifecycle commands, normally on a full
|
||||
* server restart.</p>
|
||||
*
|
||||
* @param command command to register
|
||||
*/
|
||||
public void registerCommand(PlexCommand command)
|
||||
@@ -120,6 +127,10 @@ public abstract class PlexModule
|
||||
/**
|
||||
* Unregisters and stops tracking a command owned by this module.
|
||||
*
|
||||
* <p>Unregistration removes the command from this module and Plex's registry.
|
||||
* If Paper has already built the active Brigadier dispatcher, the command may
|
||||
* remain callable until Paper rebuilds lifecycle commands.</p>
|
||||
*
|
||||
* @param command command to unregister
|
||||
*/
|
||||
public void unregisterCommand(PlexCommand command)
|
||||
|
||||
@@ -6,8 +6,6 @@ import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -16,37 +14,38 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ProxyCommand implements SimpleCommand
|
||||
{
|
||||
/**
|
||||
* Returns the instance of the plugin
|
||||
*/
|
||||
protected static Plex plugin = Plex.get();
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected final Plex plugin;
|
||||
private final CommandSpec commandSpec;
|
||||
private final RequiredCommandSource commandSource;
|
||||
|
||||
public ProxyCommand()
|
||||
/**
|
||||
* Creates and registers a proxy command using the current proxy plugin.
|
||||
*
|
||||
* @param commandSpec explicit command metadata
|
||||
*/
|
||||
protected ProxyCommand(CommandSpec commandSpec)
|
||||
{
|
||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||
this.commandSource = this.perms.source();
|
||||
this(Plex.get(), commandSpec);
|
||||
}
|
||||
|
||||
CommandMeta.Builder meta = plugin.getServer().getCommandManager().metaBuilder(this.params.name());
|
||||
if (!this.params.aliases().isEmpty())
|
||||
/**
|
||||
* Creates and registers a proxy command.
|
||||
*
|
||||
* @param plugin running proxy plugin
|
||||
* @param commandSpec explicit command metadata
|
||||
*/
|
||||
protected ProxyCommand(Plex plugin, CommandSpec commandSpec)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.commandSpec = commandSpec;
|
||||
this.commandSource = commandSpec.requiredSource();
|
||||
|
||||
CommandMeta.Builder meta = plugin.getServer().getCommandManager().metaBuilder(commandSpec.name());
|
||||
if (!commandSpec.aliases().isEmpty())
|
||||
{
|
||||
meta.aliases(this.params.aliases().split(","));
|
||||
meta.aliases(commandSpec.aliases().toArray(String[]::new));
|
||||
}
|
||||
meta.plugin(Plex.get());
|
||||
meta.plugin(plugin);
|
||||
plugin.getServer().getCommandManager().register(meta.build(), this);
|
||||
}
|
||||
|
||||
@@ -74,9 +73,9 @@ public abstract class ProxyCommand implements SimpleCommand
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!perms.permission().isEmpty())
|
||||
if (!commandSpec.permission().isEmpty())
|
||||
{
|
||||
if (!invocation.source().hasPermission(perms.permission()))
|
||||
if (!invocation.source().hasPermission(commandSpec.permission()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -90,11 +89,11 @@ public abstract class ProxyCommand implements SimpleCommand
|
||||
|
||||
private boolean matches(String label)
|
||||
{
|
||||
if (params.name().equalsIgnoreCase(label))
|
||||
if (commandSpec.name().equalsIgnoreCase(label))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return !params.aliases().isEmpty() && java.util.Arrays.stream(params.aliases().split(",")).anyMatch(s -> s.equalsIgnoreCase(label));
|
||||
return commandSpec.aliases().stream().anyMatch(alias -> alias.equalsIgnoreCase(label));
|
||||
}
|
||||
|
||||
protected void send(Audience audience, Component component)
|
||||
|
||||
@@ -31,4 +31,10 @@ final class DefaultCommandApi implements CommandApi
|
||||
plugin.getCommandHandler().unregisterCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresLifecycleReload()
|
||||
{
|
||||
return plugin.getCommandHandler() != null && plugin.getCommandHandler().requiresLifecycleReload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,27 +18,20 @@ import dev.plex.command.exception.PlayerNotBannedException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
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.Locale;
|
||||
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.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Brigadier-backed superclass for Plex's built-in server commands.
|
||||
@@ -48,6 +41,7 @@ public abstract class ServerCommand implements PlexCommand
|
||||
private static Runtime runtime;
|
||||
|
||||
protected final Plex plugin;
|
||||
private final CommandSpec commandSpec;
|
||||
private final RequiredCommandSource commandSource;
|
||||
|
||||
public static void setRuntime(Runtime runtime)
|
||||
@@ -55,13 +49,25 @@ public abstract class ServerCommand implements PlexCommand
|
||||
ServerCommand.runtime = runtime;
|
||||
}
|
||||
|
||||
protected ServerCommand()
|
||||
protected ServerCommand(CommandSpec commandSpec)
|
||||
{
|
||||
this.plugin = requireRuntime().plugin();
|
||||
this.commandSource = permissions().source();
|
||||
this.commandSpec = commandSpec;
|
||||
this.commandSource = commandSpec.requiredSource();
|
||||
}
|
||||
|
||||
protected abstract Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args);
|
||||
protected static CommandSpec.Builder command(String name)
|
||||
{
|
||||
return CommandSpec.builder(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final CommandSpec commandSpec()
|
||||
{
|
||||
return commandSpec;
|
||||
}
|
||||
|
||||
protected abstract Component execute(@NotNull ServerCommandContext context);
|
||||
|
||||
@Override
|
||||
public final LiteralCommandNode<CommandSourceStack> buildCommand()
|
||||
@@ -227,7 +233,7 @@ public abstract class ServerCommand implements PlexCommand
|
||||
{
|
||||
return (context, builder) ->
|
||||
{
|
||||
if (!silentCheckPermission(context.getSource().getSender(), permission))
|
||||
if (!canUsePermission(context.getSource(), permission))
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
@@ -237,6 +243,15 @@ public abstract class ServerCommand implements PlexCommand
|
||||
};
|
||||
}
|
||||
|
||||
protected boolean canUsePermission(CommandSourceStack source, String permission)
|
||||
{
|
||||
if (permission.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return !(source.getSender() instanceof Player player) || player.hasPermission(permission);
|
||||
}
|
||||
|
||||
private boolean canUse(CommandSourceStack source)
|
||||
{
|
||||
CommandSender sender = source.getSender();
|
||||
@@ -271,41 +286,42 @@ public abstract class ServerCommand implements PlexCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
private int dispatchCommand(CommandContext<CommandSourceStack> context, String[] args)
|
||||
private int dispatchCommand(CommandContext<CommandSourceStack> brigadierContext, String[] args)
|
||||
{
|
||||
CommandSender sender = context.getSource().getSender();
|
||||
if (!validateSourceAndPermission(sender))
|
||||
ServerCommandContext context = new ServerCommandContext(plugin, this, brigadierContext, args);
|
||||
CommandSender sender = context.sender();
|
||||
if (!validateSourceAndPermission(sender, context))
|
||||
{
|
||||
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Component component = this.execute(sender, isConsole(sender) ? null : (Player)sender, args);
|
||||
Component component = this.execute(context);
|
||||
if (component != null)
|
||||
{
|
||||
send(sender, component);
|
||||
context.send(sender, component);
|
||||
}
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException | ConsoleOnlyException |
|
||||
ConsoleMustDefinePlayerException | PlayerNotBannedException | NumberFormatException ex)
|
||||
{
|
||||
send(sender, exceptionComponent(ex));
|
||||
context.send(sender, context.exceptionComponent(ex));
|
||||
}
|
||||
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private boolean validateSourceAndPermission(CommandSender sender)
|
||||
private boolean validateSourceAndPermission(CommandSender sender, ServerCommandContext context)
|
||||
{
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionInGame"));
|
||||
context.send(sender, context.messageComponent("noPermissionInGame"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (commandSource == RequiredCommandSource.IN_GAME && sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
send(sender, messageComponent("noPermissionConsole"));
|
||||
context.send(sender, context.messageComponent("noPermissionConsole"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -323,7 +339,7 @@ public abstract class ServerCommand implements PlexCommand
|
||||
}
|
||||
if (!player.hasPermission(permission))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", permission));
|
||||
context.send(sender, context.messageComponent("noPermissionNode", permission));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -335,7 +351,7 @@ public abstract class ServerCommand implements PlexCommand
|
||||
Player player = plexPlayer == null ? null : Bukkit.getPlayer(plexPlayer.getName());
|
||||
if (player == null || !plugin.getPermissions().playerHas(null, player, permission))
|
||||
{
|
||||
send(sender, messageComponent("noPermissionNode", permission));
|
||||
context.send(sender, context.messageComponent("noPermissionNode", permission));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -357,185 +373,11 @@ public abstract class ServerCommand implements PlexCommand
|
||||
return rawArgs.trim().split("\\s+");
|
||||
}
|
||||
|
||||
protected PlexPlayer getPlexPlayer(@NotNull Player player)
|
||||
{
|
||||
return plugin.getPlayerService().getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkPermission((Player)sender, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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 true;
|
||||
}
|
||||
|
||||
protected boolean checkPermission(Player player, String permission)
|
||||
{
|
||||
if (!permission.isEmpty() && !player.hasPermission(permission))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean silentCheckPermission(Player player, String permission)
|
||||
{
|
||||
return permission.isEmpty() || player.hasPermission(permission);
|
||||
}
|
||||
|
||||
protected UUID getUUID(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
public @NotNull Plex getPlugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
protected boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
protected Component messageComponent(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageComponent(s, objects);
|
||||
}
|
||||
|
||||
protected Component messageComponent(String s, Component... objects)
|
||||
{
|
||||
return PlexUtils.messageComponent(s, objects);
|
||||
}
|
||||
|
||||
protected String messageString(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageString(s, objects);
|
||||
}
|
||||
|
||||
protected Component usage()
|
||||
{
|
||||
return messageComponent("correctUsagePrefix").append(componentFromString(this.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");
|
||||
}
|
||||
String message = ex.getMessage();
|
||||
return message == null ? componentFromString(ex.getClass().getSimpleName()) : PlexUtils.mmDeserialize(message);
|
||||
}
|
||||
|
||||
protected Player getNonNullPlayer(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
UUID uuid = UUID.fromString(name);
|
||||
return Bukkit.getPlayer(uuid);
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
protected PlexPlayer getOnlinePlexPlayer(String name)
|
||||
{
|
||||
Player player = getNonNullPlayer(name);
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(player.getUniqueId());
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
protected PlexPlayer getOfflinePlexPlayer(UUID uuid)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(uuid);
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
protected World getNonNullWorld(String name)
|
||||
{
|
||||
World world = Bukkit.getWorld(name);
|
||||
if (world == null)
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.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 PlexUtils.mmDeserialize(s);
|
||||
}
|
||||
|
||||
private static Runtime requireRuntime()
|
||||
{
|
||||
if (runtime == null)
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import dev.plex.Plex;
|
||||
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.player.PlexPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
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.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Runtime context and helper facade for a server command execution.
|
||||
*/
|
||||
public final class ServerCommandContext
|
||||
{
|
||||
private final Plex plugin;
|
||||
private final PlexCommand command;
|
||||
private final CommandContext<CommandSourceStack> brigadierContext;
|
||||
private final CommandSender sender;
|
||||
private final Player player;
|
||||
private final String[] args;
|
||||
|
||||
ServerCommandContext(Plex plugin, PlexCommand command, CommandContext<CommandSourceStack> brigadierContext, String[] args)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.command = command;
|
||||
this.brigadierContext = brigadierContext;
|
||||
this.sender = brigadierContext.getSource().getSender();
|
||||
this.player = sender instanceof Player playerSender ? playerSender : null;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the running Plex plugin.
|
||||
*
|
||||
* @return running Plex plugin
|
||||
*/
|
||||
public Plex plugin()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Plex command being executed.
|
||||
*
|
||||
* @return Plex command
|
||||
*/
|
||||
public PlexCommand command()
|
||||
{
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Brigadier command context.
|
||||
*
|
||||
* @return Brigadier command context
|
||||
*/
|
||||
public CommandContext<CommandSourceStack> brigadierContext()
|
||||
{
|
||||
return brigadierContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command sender.
|
||||
*
|
||||
* @return command sender
|
||||
*/
|
||||
public CommandSender sender()
|
||||
{
|
||||
return sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player sender, if this command was run by a player.
|
||||
*
|
||||
* @return player sender, or {@code null} for non-player senders
|
||||
*/
|
||||
public @Nullable Player player()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string-array arguments built from the Brigadier parse.
|
||||
*
|
||||
* @return execution arguments
|
||||
*/
|
||||
public String[] args()
|
||||
{
|
||||
return args;
|
||||
}
|
||||
|
||||
public PlexPlayer getPlexPlayer(@NotNull Player player)
|
||||
{
|
||||
return plugin.getPlayerService().getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void send(Audience audience, String s)
|
||||
{
|
||||
audience.sendMessage(componentFromString(s));
|
||||
}
|
||||
|
||||
public void send(Audience audience, Component component)
|
||||
{
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
|
||||
public boolean checkPermission(CommandSender sender, String permission)
|
||||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return checkPermission((Player)sender, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean silentCheckPermission(CommandSender sender, String permission)
|
||||
{
|
||||
PlexLog.debug("Checking {0} with {1}", sender.getName(), permission);
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
return silentCheckPermission((Player)sender, permission);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkPermission(Player player, String permission)
|
||||
{
|
||||
if (!permission.isEmpty() && !player.hasPermission(permission))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("noPermissionNode", permission));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean silentCheckPermission(Player player, String permission)
|
||||
{
|
||||
return permission.isEmpty() || player.hasPermission(permission);
|
||||
}
|
||||
|
||||
public @Nullable UUID getUUID(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player player))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return player.getUniqueId();
|
||||
}
|
||||
|
||||
public boolean isConsole(CommandSender sender)
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
public boolean isConsole()
|
||||
{
|
||||
return isConsole(sender);
|
||||
}
|
||||
|
||||
public Component messageComponent(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageComponent(s, objects);
|
||||
}
|
||||
|
||||
public Component messageComponent(String s, Component... objects)
|
||||
{
|
||||
return PlexUtils.messageComponent(s, objects);
|
||||
}
|
||||
|
||||
public String messageString(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.messageString(s, objects);
|
||||
}
|
||||
|
||||
public Component usage()
|
||||
{
|
||||
return messageComponent("correctUsagePrefix").append(componentFromString(command.getUsage()).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
public Component usage(String s)
|
||||
{
|
||||
return messageComponent("correctUsagePrefix").append(componentFromString(s).color(NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
public Player getNonNullPlayer(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
UUID uuid = UUID.fromString(name);
|
||||
return Bukkit.getPlayer(uuid);
|
||||
}
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
public PlexPlayer getOnlinePlexPlayer(String name)
|
||||
{
|
||||
Player player = getNonNullPlayer(name);
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(player.getUniqueId());
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public PlexPlayer getOfflinePlexPlayer(UUID uuid)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(uuid);
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public World getNonNullWorld(String name)
|
||||
{
|
||||
World world = Bukkit.getWorld(name);
|
||||
if (world == null)
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("worldNotFound"));
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public Component componentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s).colorIfAbsent(NamedTextColor.GRAY);
|
||||
}
|
||||
|
||||
public Component noColorComponentFromString(String s)
|
||||
{
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(s);
|
||||
}
|
||||
|
||||
public Component mmString(String s)
|
||||
{
|
||||
return PlexUtils.mmDeserialize(s);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
String message = ex.getMessage();
|
||||
return message == null ? componentFromString(ex.getClass().getSimpleName()) : PlexUtils.mmDeserialize(message);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.hook.VaultHook;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
@@ -20,12 +18,18 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.adminchat", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
|
||||
public class AdminChatCMD extends ServerCommand
|
||||
{
|
||||
public AdminChatCMD()
|
||||
{
|
||||
super(command("adminchat")
|
||||
.description("Talk privately with other admins")
|
||||
.usage("/<command> <message>")
|
||||
.aliases("o,ac,sc,staffchat")
|
||||
.permission("plex.adminchat")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -35,8 +39,11 @@ public class AdminChatCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
PlexPlayer player;
|
||||
if (args.length == 0)
|
||||
{
|
||||
@@ -44,9 +51,9 @@ public class AdminChatCMD extends ServerCommand
|
||||
{
|
||||
player = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||
player.setStaffChat(!player.isStaffChat());
|
||||
return messageComponent("adminChatToggled", messageString(player.isStaffChat() ? "stateOn" : "stateOff"));
|
||||
return context.messageComponent("adminChatToggled", context.messageString(player.isStaffChat() ? "stateOn" : "stateOff"));
|
||||
}
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
String prefix;
|
||||
@@ -61,7 +68,7 @@ public class AdminChatCMD extends ServerCommand
|
||||
}
|
||||
PlexLog.debug("admin chat prefix: {0}", prefix);
|
||||
String message = StringUtils.join(args, " ");
|
||||
plugin.getServer().getConsoleSender().sendMessage(messageComponent("adminChatFormat", sender.getName(), prefix, message));
|
||||
plugin.getServer().getConsoleSender().sendMessage(context.messageComponent("adminChatFormat", sender.getName(), prefix, message));
|
||||
MessageUtil.sendStaffChat(plugin, sender, SafeMiniMessage.mmDeserialize(message), PlexUtils.adminChat(sender.getName(), prefix, message).toArray(UUID[]::new));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
|
||||
@@ -14,12 +13,18 @@ import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.adminworld", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "adminworld", aliases = "aw", description = "Teleport to the adminworld")
|
||||
public class AdminworldCMD extends ServerCommand
|
||||
{
|
||||
public AdminworldCMD()
|
||||
{
|
||||
super(command("adminworld")
|
||||
.description("Teleport to the adminworld")
|
||||
.aliases("aw")
|
||||
.permission("plex.adminworld")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -27,15 +32,18 @@ public class AdminworldCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
assert playerSender != null;
|
||||
// TODO: Add adminworld settings
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("adminworld"), 0, 50, 0);
|
||||
playerSender.teleportAsync(loc);
|
||||
return messageComponent("teleportedToWorld", "adminworld");
|
||||
return context.messageComponent("teleportedToWorld", "adminworld");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -17,48 +15,56 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.gamemode.adventure", source = RequiredCommandSource.ANY)
|
||||
@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
|
||||
{
|
||||
public AdventureCMD()
|
||||
{
|
||||
super(command("adventure")
|
||||
.description("Set your own or another player's gamemode to adventure mode")
|
||||
.aliases("gma,egma,eadventure,adventuremode,eadventuremode")
|
||||
.permission("plex.gamemode.adventure")
|
||||
.build());
|
||||
}
|
||||
@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"))
|
||||
.requires(source -> canUsePermission(source, "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)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
if (context.isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(messageString("consoleMustDefinePlayer"));
|
||||
throw new CommandFailException(context.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.ADVENTURE));
|
||||
return null;
|
||||
}
|
||||
|
||||
checkPermission(sender, "plex.gamemode.adventure.others");
|
||||
context.checkPermission(sender, "plex.gamemode.adventure.others");
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.ADVENTURE);
|
||||
messageComponent("gameModeSetTo", "adventure");
|
||||
context.messageComponent("gameModeSetTo", "adventure");
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "adventure"));
|
||||
PlexUtils.broadcast(context.messageComponent("setEveryoneGameMode", sender.getName(), "adventure"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
Player nPlayer = context.getNonNullPlayer(args[0]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.ADVENTURE));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -26,13 +24,19 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@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
|
||||
{
|
||||
public BanCMD()
|
||||
{
|
||||
super(command("ban")
|
||||
.description("Bans a player, offline or online")
|
||||
.usage("/<command> <player> [message] [-rb]")
|
||||
.aliases("offlineban,gtfo")
|
||||
.permission("plex.ban")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -45,11 +49,14 @@ public class BanCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
final PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(args[0]);
|
||||
@@ -72,23 +79,23 @@ public class BanCMD extends ServerCommand
|
||||
}
|
||||
if (aBoolean)
|
||||
{
|
||||
send(sender, messageComponent("playerBanned"));
|
||||
context.send(sender, context.messageComponent("playerBanned"));
|
||||
return;
|
||||
}
|
||||
String reason;
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), context.getUUID(sender));
|
||||
punishment.setType(PunishmentType.BAN);
|
||||
boolean rollBack = false;
|
||||
if (args.length > 1)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 1, args.length);
|
||||
String newReason = StringUtils.normalizeSpace(reason.replace("-rb", ""));
|
||||
punishment.setReason(newReason.trim().isEmpty() ? messageString("noReasonProvided") : newReason);
|
||||
punishment.setReason(newReason.trim().isEmpty() ? context.messageString("noReasonProvided") : newReason);
|
||||
rollBack = reason.startsWith("-rb") || reason.endsWith("-rb");
|
||||
}
|
||||
else
|
||||
{
|
||||
punishment.setReason(messageString("noReasonProvided"));
|
||||
punishment.setReason(context.messageString("noReasonProvided"));
|
||||
}
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
@@ -97,7 +104,7 @@ public class BanCMD extends ServerCommand
|
||||
punishment.setActive(true);
|
||||
punishment.setIp(plexPlayer.getIps().getLast());
|
||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
||||
if (player != null)
|
||||
{
|
||||
plugin.getApi().scheduler().runEntity(player, () -> BungeeUtil.kickPlayer(plugin, player, Punishment.generateBanMessage(punishment, plugin.config.getString("banning.ban_url"), plugin.getPlayerService())));
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.punishment.Punishment;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
@@ -14,12 +13,17 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "banlist", description = "Manages the banlist", usage = "/<command> [purge]")
|
||||
@CommandPermissions(permission = "plex.banlist")
|
||||
public class BanListCommand extends ServerCommand
|
||||
{
|
||||
public BanListCommand()
|
||||
{
|
||||
super(command("banlist")
|
||||
.description("Manages the banlist")
|
||||
.usage("/<command> [purge]")
|
||||
.permission("plex.banlist")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -31,13 +35,16 @@ public class BanListCommand extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
plugin.getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
|
||||
{
|
||||
send(sender, messageComponent("activeBansList", punishments.size(), StringUtils.join(punishments.stream().map(Punishment::getPunishedUsername).collect(Collectors.toList()), ", ")));
|
||||
context.send(sender, context.messageComponent("activeBansList", punishments.size(), StringUtils.join(punishments.stream().map(Punishment::getPunishedUsername).collect(Collectors.toList()), ", ")));
|
||||
});
|
||||
return null;
|
||||
}
|
||||
@@ -45,11 +52,11 @@ public class BanListCommand extends ServerCommand
|
||||
{
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
return messageComponent("noPermissionInGame");
|
||||
return context.messageComponent("noPermissionInGame");
|
||||
}
|
||||
if (!sender.getName().equalsIgnoreCase("console"))
|
||||
{
|
||||
if (!checkPermission(sender, "plex.banlist.clear"))
|
||||
if (!context.checkPermission(sender, "plex.banlist.clear"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -57,7 +64,7 @@ public class BanListCommand extends ServerCommand
|
||||
plugin.getPunishmentManager().getActiveBans().whenComplete((punishments, throwable) ->
|
||||
{
|
||||
punishments.forEach(plugin.getPunishmentManager()::unban);
|
||||
send(sender, messageComponent("unbannedPlayers", punishments.size()));
|
||||
context.send(sender, context.messageComponent("unbannedPlayers", punishments.size()));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -3,10 +3,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@@ -17,12 +15,18 @@ 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;
|
||||
|
||||
@CommandPermissions(permission = "plex.broadcastloginmessage", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "bcastloginmessage", usage = "/<command> <player>", description = "Broadcast your login message (for vanish support)", aliases = "bcastlm")
|
||||
public class BcastLoginMessageCMD extends ServerCommand
|
||||
{
|
||||
public BcastLoginMessageCMD()
|
||||
{
|
||||
super(command("bcastloginmessage")
|
||||
.description("Broadcast your login message (for vanish support)")
|
||||
.usage("/<command> <player>")
|
||||
.aliases("bcastlm")
|
||||
.permission("plex.broadcastloginmessage")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -32,11 +36,14 @@ public class BcastLoginMessageCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(args[0]);
|
||||
@@ -50,11 +57,11 @@ public class BcastLoginMessageCMD extends ServerCommand
|
||||
if (!loginMessage.isEmpty())
|
||||
{
|
||||
PlexUtils.broadcast(PlexUtils.stringToComponent(loginMessage));
|
||||
PlexUtils.broadcast(messageComponent("loginMessage", plexPlayer.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("loginMessage", plexPlayer.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return messageComponent("playerHasNoLoginMessage");
|
||||
return context.messageComponent("playerHasNoLoginMessage");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.listener.impl.BlockListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -15,12 +14,18 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.blockedit")
|
||||
@CommandParameters(name = "blockedit", usage = "/<command> [list | purge | all | <player>]", aliases = "bedit", description = "Prevent players from modifying blocks")
|
||||
public class BlockEditCMD extends ServerCommand
|
||||
{
|
||||
public BlockEditCMD()
|
||||
{
|
||||
super(command("blockedit")
|
||||
.description("Prevent players from modifying blocks")
|
||||
.usage("/<command> [list | purge | all | <player>]")
|
||||
.aliases("bedit")
|
||||
.permission("plex.blockedit")
|
||||
.build());
|
||||
}
|
||||
private final BlockListener bl = new BlockListener();
|
||||
|
||||
@Override
|
||||
@@ -38,32 +43,35 @@ public class BlockEditCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
send(sender, messageComponent("listOfPlayersBlocked"));
|
||||
context.send(sender, context.messageComponent("listOfPlayersBlocked"));
|
||||
|
||||
int count = 0;
|
||||
for (String player : bl.blockedPlayers.stream().toList())
|
||||
{
|
||||
send(sender, messageComponent("blockeditListEntry", player));
|
||||
context.send(sender, context.messageComponent("blockeditListEntry", player));
|
||||
++count;
|
||||
}
|
||||
if (count == 0)
|
||||
{
|
||||
send(sender, messageComponent("blockeditListNone"));
|
||||
context.send(sender, context.messageComponent("blockeditListNone"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("purge"))
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("unblockingEdits", sender.getName(), messageString("blockeditAllPlayers")));
|
||||
PlexUtils.broadcast(context.messageComponent("unblockingEdits", sender.getName(), context.messageString("blockeditAllPlayers")));
|
||||
int count = 0;
|
||||
for (String player : bl.blockedPlayers.stream().toList())
|
||||
{
|
||||
@@ -73,43 +81,43 @@ public class BlockEditCMD extends ServerCommand
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return messageComponent("blockeditSize", messageString("blockeditUnblockedAction"), count);
|
||||
return context.messageComponent("blockeditSize", context.messageString("blockeditUnblockedAction"), count);
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("all"))
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("blockingEdits", sender.getName(), messageString("blockeditAllNonAdmins")));
|
||||
PlexUtils.broadcast(context.messageComponent("blockingEdits", sender.getName(), context.messageString("blockeditAllNonAdmins")));
|
||||
int count = 0;
|
||||
for (final Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (!silentCheckPermission(player, "plex.blockedit"))
|
||||
if (!context.silentCheckPermission(player, "plex.blockedit"))
|
||||
{
|
||||
bl.blockedPlayers.add(player.getName());
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return messageComponent("blockeditSize", messageString("blockeditBlockedAction"), count);
|
||||
return context.messageComponent("blockeditSize", context.messageString("blockeditBlockedAction"), count);
|
||||
}
|
||||
|
||||
final Player player = getNonNullPlayer(args[0]);
|
||||
final Player player = context.getNonNullPlayer(args[0]);
|
||||
if (!bl.blockedPlayers.contains(player.getName()))
|
||||
{
|
||||
if (silentCheckPermission(player, "plex.blockedit"))
|
||||
if (context.silentCheckPermission(player, "plex.blockedit"))
|
||||
{
|
||||
send(sender, messageComponent("higherRankThanYou"));
|
||||
context.send(sender, context.messageComponent("higherRankThanYou"));
|
||||
return null;
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("blockingEdits", sender.getName(), player.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("blockingEdits", sender.getName(), player.getName()));
|
||||
bl.blockedPlayers.add(player.getName());
|
||||
send(player, messageComponent("editsModified", messageString("blockeditBlockedState")));
|
||||
send(sender, messageComponent("editsBlocked", player.getName()));
|
||||
context.send(player, context.messageComponent("editsModified", context.messageString("blockeditBlockedState")));
|
||||
context.send(sender, context.messageComponent("editsBlocked", player.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("unblockingEdits", sender.getName(), player.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("unblockingEdits", sender.getName(), player.getName()));
|
||||
bl.blockedPlayers.remove(player.getName());
|
||||
send(player, messageComponent("editsModified", messageString("blockeditUnblockedState")));
|
||||
send(sender, messageComponent("editsUnblocked", player.getName()));
|
||||
context.send(player, context.messageComponent("editsModified", context.messageString("blockeditUnblockedState")));
|
||||
context.send(sender, context.messageComponent("editsUnblocked", player.getName()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
|
||||
@@ -14,12 +13,18 @@ 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;
|
||||
|
||||
@CommandPermissions(permission = "plex.commandspy", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "commandspy", aliases = "cmdspy", description = "Spy on other player's commands")
|
||||
public class CommandSpyCMD extends ServerCommand
|
||||
{
|
||||
public CommandSpyCMD()
|
||||
{
|
||||
super(command("commandspy")
|
||||
.description("Spy on other player's commands")
|
||||
.aliases("cmdspy")
|
||||
.permission("plex.commandspy")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -27,16 +32,19 @@ public class CommandSpyCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (playerSender != null)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||
plexPlayer.setCommandSpy(!plexPlayer.isCommandSpy());
|
||||
plugin.getPlayerService().update(plexPlayer);
|
||||
send(sender, messageComponent("toggleCommandSpy")
|
||||
context.send(sender, context.messageComponent("toggleCommandSpy")
|
||||
.append(Component.space())
|
||||
.append(plexPlayer.isCommandSpy() ? messageComponent("enabled") : messageComponent("disabled")));
|
||||
.append(plexPlayer.isCommandSpy() ? context.messageComponent("enabled") : context.messageComponent("disabled")));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -14,12 +13,19 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.consolesay", source = RequiredCommandSource.CONSOLE)
|
||||
@CommandParameters(name = "consolesay", usage = "/<command> <message>", description = "Displays a message to everyone", aliases = "csay")
|
||||
public class ConsoleSayCMD extends ServerCommand
|
||||
{
|
||||
public ConsoleSayCMD()
|
||||
{
|
||||
super(command("consolesay")
|
||||
.description("Displays a message to everyone")
|
||||
.usage("/<command> <message>")
|
||||
.aliases("csay")
|
||||
.permission("plex.consolesay")
|
||||
.source(RequiredCommandSource.CONSOLE)
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -29,11 +35,14 @@ public class ConsoleSayCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("consoleSayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
|
||||
@@ -2,10 +2,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -17,30 +15,38 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.gamemode.creative", source = RequiredCommandSource.ANY)
|
||||
@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
|
||||
{
|
||||
public CreativeCMD()
|
||||
{
|
||||
super(command("creative")
|
||||
.description("Set your own or another player's gamemode to creative mode")
|
||||
.aliases("gmc,egmc,ecreative,eecreative,creativemode,ecreativemode")
|
||||
.permission("plex.gamemode.creative")
|
||||
.build());
|
||||
}
|
||||
@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"))
|
||||
.requires(source -> canUsePermission(source, "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)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
if (context.isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(messageString("consoleMustDefinePlayer"));
|
||||
throw new CommandFailException(context.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
if (!(playerSender == null))
|
||||
{
|
||||
@@ -49,19 +55,19 @@ public class CreativeCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
checkPermission(sender, "plex.gamemode.creative.others");
|
||||
context.checkPermission(sender, "plex.gamemode.creative.others");
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||
messageComponent("gameModeSetTo", "creative");
|
||||
context.messageComponent("gameModeSetTo", "creative");
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "creative"));
|
||||
PlexUtils.broadcast(context.messageComponent("setEveryoneGameMode", sender.getName(), "creative"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
Player nPlayer = context.getNonNullPlayer(args[0]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.CREATIVE));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@ package dev.plex.command.impl;
|
||||
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.command.ServerCommandContext;
|
||||
import dev.plex.menu.impl.MaterialMenu;
|
||||
import dev.plex.util.GameRuleUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
@@ -20,12 +19,17 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "pdebug", description = "Plex's debug command", usage = "/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
||||
@CommandPermissions(permission = "plex.debug")
|
||||
public class DebugCMD extends ServerCommand
|
||||
{
|
||||
public DebugCMD()
|
||||
{
|
||||
super(command("pdebug")
|
||||
.description("Plex's debug command")
|
||||
.usage("/<command> <aliases <command> | redis-reset <player> | gamerules>")
|
||||
.permission("plex.debug")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -43,23 +47,26 @@ public class DebugCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("redis-reset"))
|
||||
{
|
||||
if (args.length == 2)
|
||||
{
|
||||
Player player = getNonNullPlayer(args[1]);
|
||||
Player player = context.getNonNullPlayer(args[1]);
|
||||
if (plugin.getRedisConnection().query(jedis -> jedis.exists(player.getUniqueId().toString())))
|
||||
{
|
||||
plugin.getRedisConnection().execute(jedis -> jedis.del(player.getUniqueId().toString()));
|
||||
return messageComponent("redisResetSuccessful", player.getName());
|
||||
return context.messageComponent("redisResetSuccessful", player.getName());
|
||||
}
|
||||
return messageComponent("redisResetPlayerNotFound");
|
||||
return context.messageComponent("redisResetPlayerNotFound");
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("gamerules"))
|
||||
@@ -78,7 +85,7 @@ public class DebugCMD extends ServerCommand
|
||||
PlexLog.log("Set specific gamerules for world: " + world.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
return messageComponent("reappliedGamerules");
|
||||
return context.messageComponent("reappliedGamerules");
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("aliases"))
|
||||
{
|
||||
@@ -88,26 +95,26 @@ public class DebugCMD extends ServerCommand
|
||||
PlexCommand plexCommand = plugin.getCommandHandler().getCommand(commandName);
|
||||
if (plexCommand != null)
|
||||
{
|
||||
return messageComponent("commandAliases", commandName, Arrays.toString(plexCommand.getAliases().toArray(new String[0])));
|
||||
return context.messageComponent("commandAliases", commandName, Arrays.toString(plexCommand.getAliases().toArray(new String[0])));
|
||||
}
|
||||
Command command = plugin.getServer().getCommandMap().getCommand(commandName);
|
||||
if (command == null)
|
||||
{
|
||||
return messageComponent("commandNotFound");
|
||||
return context.messageComponent("commandNotFound");
|
||||
}
|
||||
return messageComponent("commandAliases", commandName, Arrays.toString(command.getAliases().toArray(new String[0])));
|
||||
return context.messageComponent("commandAliases", commandName, Arrays.toString(command.getAliases().toArray(new String[0])));
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("pagination"))
|
||||
{
|
||||
if (playerSender == null)
|
||||
{
|
||||
return messageComponent("noPermissionConsole");
|
||||
return context.messageComponent("noPermissionConsole");
|
||||
}
|
||||
new MaterialMenu().open(playerSender);
|
||||
return null;
|
||||
}
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -23,12 +21,18 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
||||
@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
|
||||
{
|
||||
public EntityWipeCMD()
|
||||
{
|
||||
super(command("entitywipe")
|
||||
.description("Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.")
|
||||
.usage("/<command> [entity] [radius]")
|
||||
.aliases("ew,rd")
|
||||
.permission("plex.entitywipe")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -53,8 +57,11 @@ public class EntityWipeCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
List<String> entityBlacklist = plugin.config.getStringList("entitywipe_list");
|
||||
|
||||
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
|
||||
@@ -68,7 +75,7 @@ public class EntityWipeCMD extends ServerCommand
|
||||
|
||||
if (radiusSpecified)
|
||||
{
|
||||
radius = parseInt(sender, entityWhitelist.getLast()); // get the args length as the size of the list
|
||||
radius = parseInt(context, sender, entityWhitelist.getLast()); // get the args length as the size of the list
|
||||
radius *= radius;
|
||||
entityWhitelist.removeLast(); // remove the radius from the list
|
||||
}
|
||||
@@ -81,7 +88,7 @@ public class EntityWipeCMD extends ServerCommand
|
||||
boolean res = Arrays.stream(entityTypes).noneMatch(entityType -> name.equalsIgnoreCase(entityType.name()));
|
||||
if (res)
|
||||
{
|
||||
sender.sendMessage(messageComponent("invalidEntityType", name));
|
||||
sender.sendMessage(context.messageComponent("invalidEntityType", name));
|
||||
}
|
||||
return res;
|
||||
});
|
||||
@@ -120,23 +127,23 @@ public class EntityWipeCMD extends ServerCommand
|
||||
|
||||
if (useBlacklist)
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("removedEntities", sender.getName(), entityCount));
|
||||
PlexUtils.broadcast(context.messageComponent("removedEntities", sender.getName(), entityCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entityCount == 0)
|
||||
{
|
||||
sender.sendMessage(messageComponent("noRemovedEntities"));
|
||||
sender.sendMessage(context.messageComponent("noRemovedEntities"));
|
||||
return null;
|
||||
}
|
||||
String list = String.join(", ", entityCounts.keySet());
|
||||
list = list.replaceAll("(, )(?!.*\1)", (list.indexOf(", ") == list.lastIndexOf(", ") ? "" : ",") + " and ");
|
||||
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), entityCount, list));
|
||||
PlexUtils.broadcast(context.messageComponent("removedEntitiesOfTypes", sender.getName(), entityCount, list));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer parseInt(CommandSender sender, String string)
|
||||
private Integer parseInt(ServerCommandContext context, CommandSender sender, String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -144,7 +151,7 @@ public class EntityWipeCMD extends ServerCommand
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
sender.sendMessage(messageComponent("notANumber", string));
|
||||
sender.sendMessage(context.messageComponent("notANumber", string));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
|
||||
@@ -14,12 +13,17 @@ import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.flatlands", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "flatlands", description = "Teleport to the flatlands")
|
||||
public class FlatlandsCMD extends ServerCommand
|
||||
{
|
||||
public FlatlandsCMD()
|
||||
{
|
||||
super(command("flatlands")
|
||||
.description("Teleport to the flatlands")
|
||||
.permission("plex.flatlands")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -27,14 +31,17 @@ public class FlatlandsCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
assert playerSender != null;
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("flatlands"), 0, 50, 0);
|
||||
playerSender.teleportAsync(loc);
|
||||
return messageComponent("teleportedToWorld", "flatlands");
|
||||
return context.messageComponent("teleportedToWorld", "flatlands");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -18,12 +17,18 @@ 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 = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>", aliases = "fr")
|
||||
@CommandPermissions(permission = "plex.freeze")
|
||||
public class FreezeCMD extends ServerCommand
|
||||
{
|
||||
public FreezeCMD()
|
||||
{
|
||||
super(command("freeze")
|
||||
.description("Freeze a player on the server")
|
||||
.usage("/<command> <player>")
|
||||
.aliases("fr")
|
||||
.permission("plex.freeze")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -33,21 +38,24 @@ public class FreezeCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = getPlexPlayer(player);
|
||||
Player player = context.getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = context.getPlexPlayer(player);
|
||||
|
||||
if (punishedPlayer.isFrozen())
|
||||
{
|
||||
return messageComponent("playerFrozen");
|
||||
return context.messageComponent("playerFrozen");
|
||||
}
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), context.getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusSeconds(plugin.config.getInt("punishments.freeze-timer", 300)));
|
||||
@@ -58,7 +66,7 @@ public class FreezeCMD extends ServerCommand
|
||||
punishment.setActive(true);
|
||||
|
||||
plugin.getPunishmentManager().punish(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("frozePlayer", sender.getName(), player.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("frozePlayer", sender.getName(), player.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -16,12 +14,18 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "gamemode", usage = "/<command> <creative | survival | adventure | default | spectator> [player]", description = "Change your gamemode", aliases = "gm,egamemode,gmt,egmt")
|
||||
@CommandPermissions(permission = "plex.gamemode", source = RequiredCommandSource.ANY)
|
||||
public class GamemodeCMD extends ServerCommand
|
||||
{
|
||||
public GamemodeCMD()
|
||||
{
|
||||
super(command("gamemode")
|
||||
.description("Change your gamemode")
|
||||
.usage("/<command> <creative | survival | adventure | default | spectator> [player]")
|
||||
.aliases("gm,egamemode,gmt,egmt")
|
||||
.permission("plex.gamemode")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -50,56 +54,59 @@ public class GamemodeCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "survival", "s", "0" ->
|
||||
{
|
||||
update(sender, playerSender, args, GameMode.SURVIVAL);
|
||||
update(context, sender, playerSender, args, GameMode.SURVIVAL);
|
||||
return null;
|
||||
}
|
||||
case "creative", "c", "1" ->
|
||||
{
|
||||
update(sender, playerSender, args, GameMode.CREATIVE);
|
||||
update(context, sender, playerSender, args, GameMode.CREATIVE);
|
||||
return null;
|
||||
}
|
||||
case "adventure", "a", "2" ->
|
||||
{
|
||||
update(sender, playerSender, args, GameMode.ADVENTURE);
|
||||
update(context, sender, playerSender, args, GameMode.ADVENTURE);
|
||||
return null;
|
||||
}
|
||||
case "default", "d", "5" ->
|
||||
{
|
||||
update(sender, playerSender, args, plugin.getServer().getDefaultGameMode());
|
||||
update(context, sender, playerSender, args, plugin.getServer().getDefaultGameMode());
|
||||
return null;
|
||||
}
|
||||
case "spectator", "sp", "3", "6" ->
|
||||
{
|
||||
checkPermission(sender, "plex.gamemode.spectator");
|
||||
update(sender, playerSender, args, GameMode.SPECTATOR);
|
||||
context.checkPermission(sender, "plex.gamemode.spectator");
|
||||
update(context, sender, playerSender, args, GameMode.SPECTATOR);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
private void update(CommandSender sender, Player playerSender, String[] args, GameMode gameMode)
|
||||
private void update(ServerCommandContext context, CommandSender sender, Player playerSender, String[] args, GameMode gameMode)
|
||||
{
|
||||
if (args.length > 1)
|
||||
{
|
||||
checkPermission(sender, "plex.gamemode.others");
|
||||
Player player = getNonNullPlayer(args[1]);
|
||||
context.checkPermission(sender, "plex.gamemode.others");
|
||||
Player player = context.getNonNullPlayer(args[1]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, player, gameMode));
|
||||
return;
|
||||
}
|
||||
if (isConsole(sender))
|
||||
if (context.isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(PlexUtils.messageString("consoleMustDefinePlayer"));
|
||||
throw new CommandFailException(context.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
if (!(playerSender == null))
|
||||
{
|
||||
|
||||
@@ -3,10 +3,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -24,12 +22,18 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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>", aliases = "ekick")
|
||||
@CommandPermissions(permission = "plex.kick", source = RequiredCommandSource.ANY)
|
||||
public class KickCMD extends ServerCommand
|
||||
{
|
||||
public KickCMD()
|
||||
{
|
||||
super(command("kick")
|
||||
.description("Kicks a player")
|
||||
.usage("/<command> <player>")
|
||||
.aliases("ekick")
|
||||
.permission("plex.kick")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -41,15 +45,18 @@ public class KickCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(args[0]);
|
||||
String reason = messageString("noReasonProvided");
|
||||
String reason = context.messageString("noReasonProvided");
|
||||
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
@@ -61,7 +68,7 @@ public class KickCMD extends ServerCommand
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), context.getUUID(sender));
|
||||
punishment.setType(PunishmentType.KICK);
|
||||
if (args.length > 1)
|
||||
{
|
||||
@@ -75,7 +82,7 @@ public class KickCMD extends ServerCommand
|
||||
punishment.setActive(false);
|
||||
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
||||
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
||||
BungeeUtil.kickPlayer(plugin, player, Punishment.generateKickMessage(punishment, plugin.getPlayerService()));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.hook.VaultHook;
|
||||
import dev.plex.meta.PlayerMeta;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@@ -18,12 +17,18 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "list", description = "Show a list of all online players", usage = "/<command> [-d | -v]", aliases = "lsit,who,playerlist,online")
|
||||
@CommandPermissions(permission = "plex.list")
|
||||
public class ListCMD extends ServerCommand
|
||||
{
|
||||
public ListCMD()
|
||||
{
|
||||
super(command("list")
|
||||
.description("Show a list of all online players")
|
||||
.usage("/<command> [-d | -v]")
|
||||
.aliases("lsit,who,playerlist,online")
|
||||
.permission("plex.list")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -31,17 +36,20 @@ public class ListCMD extends ServerCommand
|
||||
command.then(literal("-d")
|
||||
.executes(context -> executeCommand(context, "-d")));
|
||||
command.then(literal("-v")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.list.vanished"))
|
||||
.requires(source -> canUsePermission(source, "plex.list.vanished"))
|
||||
.executes(context -> executeCommand(context, "-v")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("-v"))
|
||||
{
|
||||
checkPermission(sender, "plex.list.vanished");
|
||||
context.checkPermission(sender, "plex.list.vanished");
|
||||
players.removeIf(player -> !PlayerMeta.isVanished(player));
|
||||
}
|
||||
else
|
||||
@@ -50,7 +58,7 @@ public class ListCMD extends ServerCommand
|
||||
}
|
||||
Component list = Component.empty();
|
||||
Component header = PlexUtils.messageComponent(players.size() == 1 ? "listHeader" : "listHeaderPlural", players.size(), Bukkit.getMaxPlayers());
|
||||
send(sender, header);
|
||||
context.send(sender, header);
|
||||
if (players.isEmpty())
|
||||
{
|
||||
return null;
|
||||
@@ -58,7 +66,7 @@ public class ListCMD extends ServerCommand
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
{
|
||||
Player player = players.get(i);
|
||||
Component prefix = VaultHook.getPrefix(getPlexPlayer(player));
|
||||
Component prefix = VaultHook.getPrefix(context.getPlexPlayer(player));
|
||||
if (prefix != null && !prefix.equals(Component.empty()) && !prefix.equals(Component.space()))
|
||||
{
|
||||
list = list.append(prefix).append(Component.space());
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
|
||||
@@ -12,12 +11,17 @@ 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 = "localspawn", description = "Teleport to the spawnpoint of the world you are in")
|
||||
@CommandPermissions(permission = "plex.localspawn", source = RequiredCommandSource.IN_GAME)
|
||||
public class LocalSpawnCMD extends ServerCommand
|
||||
{
|
||||
public LocalSpawnCMD()
|
||||
{
|
||||
super(command("localspawn")
|
||||
.description("Teleport to the spawnpoint of the world you are in")
|
||||
.permission("plex.localspawn")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -25,11 +29,14 @@ public class LocalSpawnCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
assert playerSender != null;
|
||||
playerSender.teleportAsync(playerSender.getWorld().getSpawnLocation());
|
||||
return messageComponent("teleportedToWorldSpawn");
|
||||
return context.messageComponent("teleportedToWorldSpawn");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -13,12 +12,17 @@ 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 = "lockup", description = "Lockup a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(permission = "plex.lockup")
|
||||
public class LockupCMD extends ServerCommand
|
||||
{
|
||||
public LockupCMD()
|
||||
{
|
||||
super(command("lockup")
|
||||
.description("Lockup a player on the server")
|
||||
.usage("/<command> <player>")
|
||||
.permission("plex.lockup")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -28,21 +32,24 @@ public class LockupCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||
Player player = context.getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = context.getOfflinePlexPlayer(player.getUniqueId());
|
||||
|
||||
punishedPlayer.setLockedUp(!punishedPlayer.isLockedUp());
|
||||
if (punishedPlayer.isLockedUp())
|
||||
{
|
||||
player.openInventory(player.getInventory());
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedPlayer", sender.getName(), player.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent(punishedPlayer.isLockedUp() ? "lockedUpPlayer" : "unlockedPlayer", sender.getName(), player.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
|
||||
@@ -14,12 +13,18 @@ import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.masterbuilderworld", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "masterbuilderworld", aliases = "mbw", description = "Teleport to the Master Builder world")
|
||||
public class MasterbuilderworldCMD extends ServerCommand
|
||||
{
|
||||
public MasterbuilderworldCMD()
|
||||
{
|
||||
super(command("masterbuilderworld")
|
||||
.description("Teleport to the Master Builder world")
|
||||
.aliases("mbw")
|
||||
.permission("plex.masterbuilderworld")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -27,15 +32,18 @@ public class MasterbuilderworldCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
assert playerSender != null;
|
||||
// TODO: Add masterbuilderworld settings
|
||||
if (args.length == 0)
|
||||
{
|
||||
Location loc = new Location(Bukkit.getWorld("masterbuilderworld"), 0, 50, 0);
|
||||
playerSender.teleportAsync(loc);
|
||||
return messageComponent("teleportedToWorld", "Master Builder World");
|
||||
return context.messageComponent("teleportedToWorld", "Master Builder World");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -17,12 +15,18 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "moblimit", usage = "/<command> [on | off | setmax <limit>]", aliases = "entitylimit", description = "Manages the mob limit per chunk.")
|
||||
@CommandPermissions(permission = "plex.moblimit", source = RequiredCommandSource.ANY)
|
||||
public class MobLimitCMD extends ServerCommand
|
||||
{
|
||||
public MobLimitCMD()
|
||||
{
|
||||
super(command("moblimit")
|
||||
.description("Manages the mob limit per chunk.")
|
||||
.usage("/<command> [on | off | setmax <limit>]")
|
||||
.aliases("entitylimit")
|
||||
.permission("plex.moblimit")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -37,8 +41,11 @@ public class MobLimitCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
Chunk chunk = playerSender != null ? playerSender.getLocation().getChunk() : Bukkit.getWorlds().getFirst().getChunkAt(0, 0);
|
||||
@@ -67,7 +74,7 @@ public class MobLimitCMD extends ServerCommand
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
int newLimit = Integer.parseInt(args[1]);
|
||||
@@ -92,7 +99,7 @@ public class MobLimitCMD extends ServerCommand
|
||||
return PlexUtils.messageComponent("unableToParseNumber", args[1]);
|
||||
}
|
||||
default:
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -23,12 +21,18 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command> [mob]", aliases = "mp")
|
||||
public class MobPurgeCMD extends ServerCommand
|
||||
{
|
||||
public MobPurgeCMD()
|
||||
{
|
||||
super(command("mobpurge")
|
||||
.description("Purge all mobs.")
|
||||
.usage("/<command> [mob]")
|
||||
.aliases("mp")
|
||||
.permission("plex.mobpurge")
|
||||
.build());
|
||||
}
|
||||
private final List<EntityType> MOB_TYPES = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
@@ -41,8 +45,11 @@ public class MobPurgeCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
EntityType type = null;
|
||||
String mobName = null;
|
||||
if (args.length > 0)
|
||||
@@ -54,14 +61,14 @@ public class MobPurgeCMD extends ServerCommand
|
||||
catch (Exception e)
|
||||
{
|
||||
PlexLog.debug("A genius tried and failed removing the following invalid mob: " + args[0].toUpperCase());
|
||||
send(sender, messageComponent("notAValidMob"));
|
||||
context.send(sender, context.messageComponent("notAValidMob"));
|
||||
return null;
|
||||
}
|
||||
if (!MOB_TYPES.contains(type))
|
||||
{
|
||||
PlexLog.debug(Arrays.deepToString(MOB_TYPES.toArray()));
|
||||
PlexLog.debug("A genius tried to remove a mob that doesn't exist: " + args[0].toUpperCase());
|
||||
sender.sendMessage(messageComponent("notAValidMobButValidEntity"));
|
||||
sender.sendMessage(context.messageComponent("notAValidMobButValidEntity"));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -73,15 +80,15 @@ public class MobPurgeCMD extends ServerCommand
|
||||
int count = purgeMobs(type);
|
||||
if (type != null)
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), count, mobName));
|
||||
PlexUtils.broadcast(context.messageComponent("removedEntitiesOfTypes", sender.getName(), count, mobName));
|
||||
PlexLog.debug("All " + count + " of " + mobName + " were removed");
|
||||
}
|
||||
else
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), count));
|
||||
PlexUtils.broadcast(context.messageComponent("removedMobs", sender.getName(), count));
|
||||
PlexLog.debug("All " + count + " valid mobs were removed");
|
||||
}
|
||||
sender.sendMessage(messageComponent("amountOfMobsRemoved", count, type != null ? mobName + multipleS(count) : messageString(count == 1 ? "mobSingular" : "mobPlural")));
|
||||
sender.sendMessage(context.messageComponent("amountOfMobsRemoved", count, type != null ? mobName + multipleS(count) : context.messageString(count == 1 ? "mobSingular" : "mobPlural")));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -18,12 +17,18 @@ 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,emute,silence,esilence")
|
||||
@CommandPermissions(permission = "plex.mute")
|
||||
public class MuteCMD extends ServerCommand
|
||||
{
|
||||
public MuteCMD()
|
||||
{
|
||||
super(command("mute")
|
||||
.description("Mute a player on the server")
|
||||
.usage("/<command> <player>")
|
||||
.aliases("stfu,emute,silence,esilence")
|
||||
.permission("plex.mute")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -33,27 +38,30 @@ public class MuteCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||
Player player = context.getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = context.getOfflinePlexPlayer(player.getUniqueId());
|
||||
|
||||
if (punishedPlayer.isMuted())
|
||||
{
|
||||
return messageComponent("playerMuted");
|
||||
return context.messageComponent("playerMuted");
|
||||
}
|
||||
|
||||
if (silentCheckPermission(player, "plex.mute"))
|
||||
if (context.silentCheckPermission(player, "plex.mute"))
|
||||
{
|
||||
send(sender, messageComponent("higherRankThanYou"));
|
||||
context.send(sender, context.messageComponent("higherRankThanYou"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), context.getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE));
|
||||
punishment.setEndDate(date.plusSeconds(plugin.config.getInt("punishments.mute-timer", 300)));
|
||||
@@ -64,7 +72,7 @@ public class MuteCMD extends ServerCommand
|
||||
punishment.setActive(true);
|
||||
|
||||
plugin.getPunishmentManager().punish(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("mutedPlayer", sender.getName(), player.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("mutedPlayer", sender.getName(), player.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.extra.Note;
|
||||
import dev.plex.util.TimeUtils;
|
||||
@@ -21,12 +20,17 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "notes", description = "Manage notes for a player", usage = "/<command> <player> <list | add <note> | remove <id> | clear>")
|
||||
@CommandPermissions(permission = "plex.notes")
|
||||
public class NotesCMD extends ServerCommand
|
||||
{
|
||||
public NotesCMD()
|
||||
{
|
||||
super(command("notes")
|
||||
.description("Manage notes for a player")
|
||||
.usage("/<command> <player> <list | add <note> | remove <id> | clear>")
|
||||
.permission("plex.notes")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -45,18 +49,21 @@ public class NotesCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length < 2)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(args[0]);
|
||||
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
return messageComponent("playerNotFound");
|
||||
return context.messageComponent("playerNotFound");
|
||||
}
|
||||
|
||||
switch (args[1].toLowerCase())
|
||||
@@ -67,10 +74,10 @@ public class NotesCMD extends ServerCommand
|
||||
{
|
||||
if (notes.isEmpty())
|
||||
{
|
||||
send(sender, messageComponent("noNotes"));
|
||||
context.send(sender, context.messageComponent("noNotes"));
|
||||
return;
|
||||
}
|
||||
readNotes(sender, plexPlayer, notes);
|
||||
readNotes(context, sender, plexPlayer, notes);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
@@ -78,7 +85,7 @@ public class NotesCMD extends ServerCommand
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
String content = StringUtils.join(ArrayUtils.subarray(args, 2, args.length), " ");
|
||||
if (playerSender != null)
|
||||
@@ -86,14 +93,14 @@ public class NotesCMD extends ServerCommand
|
||||
Note note = new Note(plexPlayer.getUuid(), content, playerSender.getUniqueId(), ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
plexPlayer.getNotes().add(note);
|
||||
plugin.getNoteRepository().addNote(note);
|
||||
return messageComponent("noteAdded");
|
||||
return context.messageComponent("noteAdded");
|
||||
}
|
||||
}
|
||||
case "remove":
|
||||
{
|
||||
if (args.length < 3)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
int id;
|
||||
try
|
||||
@@ -102,7 +109,7 @@ public class NotesCMD extends ServerCommand
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
return messageComponent("unableToParseNumber", args[2]);
|
||||
return context.messageComponent("unableToParseNumber", args[2]);
|
||||
}
|
||||
plugin.getNoteRepository().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||
{
|
||||
@@ -112,13 +119,13 @@ public class NotesCMD extends ServerCommand
|
||||
if (note.getId() == id)
|
||||
{
|
||||
plugin.getNoteRepository().deleteNote(id, plexPlayer.getUuid()).whenComplete((notes1, ex1) ->
|
||||
send(sender, messageComponent("removedNote", id)));
|
||||
context.send(sender, context.messageComponent("removedNote", id)));
|
||||
deleted = true;
|
||||
}
|
||||
}
|
||||
if (!deleted)
|
||||
{
|
||||
send(sender, messageComponent("noteNotFound"));
|
||||
context.send(sender, context.messageComponent("noteNotFound"));
|
||||
}
|
||||
plexPlayer.getNotes().removeIf(note -> note.getId() == id);
|
||||
});
|
||||
@@ -129,26 +136,26 @@ public class NotesCMD extends ServerCommand
|
||||
int count = plexPlayer.getNotes().size();
|
||||
plexPlayer.getNotes().clear();
|
||||
plugin.getPlayerService().update(plexPlayer);
|
||||
return messageComponent("clearedNotes", count);
|
||||
return context.messageComponent("clearedNotes", count);
|
||||
}
|
||||
default:
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readNotes(@NotNull CommandSender sender, PlexPlayer plexPlayer, List<Note> notes)
|
||||
private void readNotes(ServerCommandContext context, @NotNull CommandSender sender, PlexPlayer plexPlayer, List<Note> notes)
|
||||
{
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(messageComponent("notesHeader", plexPlayer.getName()));
|
||||
AtomicReference<Component> noteList = new AtomicReference<>(context.messageComponent("notesHeader", plexPlayer.getName()));
|
||||
for (Note note : notes)
|
||||
{
|
||||
Component noteLine = messageComponent("notePrefix", note.getId(), plugin.getPlayerService().getPlayer(note.getWrittenBy()).getName(), TimeUtils.useTimezone(note.getTimestamp()));
|
||||
noteLine = noteLine.append(messageComponent("noteLine", note.getNote()));
|
||||
Component noteLine = context.messageComponent("notePrefix", note.getId(), plugin.getPlayerService().getPlayer(note.getWrittenBy()).getName(), TimeUtils.useTimezone(note.getTimestamp()));
|
||||
noteLine = noteLine.append(context.messageComponent("noteLine", note.getNote()));
|
||||
noteList.set(noteList.get().append(Component.newline()));
|
||||
noteList.set(noteList.get().append(noteLine));
|
||||
}
|
||||
send(sender, noteList.get());
|
||||
context.send(sender, noteList.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.module.PlexModule;
|
||||
import dev.plex.module.PlexModuleFile;
|
||||
import dev.plex.util.BuildInfo;
|
||||
@@ -24,12 +22,16 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "plex", usage = "/<command> [reload | redis | update | modules [reload | update]]", description = "Show information about Plex or reload it")
|
||||
public class PlexCMD extends ServerCommand
|
||||
{
|
||||
public PlexCMD()
|
||||
{
|
||||
super(command("plex")
|
||||
.description("Show information about Plex or reload it")
|
||||
.usage("/<command> [reload | redis | update | modules [reload | update]]")
|
||||
.build());
|
||||
}
|
||||
// Don't modify this command
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
@@ -50,106 +52,109 @@ public class PlexCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
send(sender, mmString("<light_purple>Plex - A new freedom plugin."));
|
||||
send(sender, mmString("<light_purple>Plugin version: <gold>" + plugin.getPluginMeta().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.shortenCommit(BuildInfo.getCommit())));
|
||||
send(sender, mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
||||
send(sender, mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate()));
|
||||
send(sender, mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
||||
context.send(sender, context.mmString("<light_purple>Plex - A new freedom plugin."));
|
||||
context.send(sender, context.mmString("<light_purple>Plugin version: <gold>" + plugin.getPluginMeta().getVersion() + " #" + BuildInfo.getNumber() + " <light_purple>Git: <gold>" + BuildInfo.shortenCommit(BuildInfo.getCommit())));
|
||||
context.send(sender, context.mmString("<light_purple>Authors: <gold>Telesphoreo, Taahh"));
|
||||
context.send(sender, context.mmString("<light_purple>Built by: <gold>" + BuildInfo.getAuthor() + " <light_purple>on <gold>" + BuildInfo.getDate()));
|
||||
context.send(sender, context.mmString("<light_purple>Run <gold>/plex modules <light_purple>to see a list of modules."));
|
||||
plugin.getUpdateChecker().getUpdateStatusMessage(sender, true, 2);
|
||||
return null;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkPermission(sender, "plex.reload");
|
||||
context.checkPermission(sender, "plex.reload");
|
||||
plugin.config.load();
|
||||
PlexLog.setDebugEnabled(plugin.config.getBoolean("debug"));
|
||||
send(sender, "Reloaded config file");
|
||||
context.send(sender, "Reloaded config file");
|
||||
plugin.messages.load();
|
||||
PlexUtils.configure(plugin.config, plugin.messages);
|
||||
send(sender, "Reloaded messages file");
|
||||
context.send(sender, "Reloaded messages file");
|
||||
plugin.indefBans.load(false);
|
||||
plugin.getPunishmentManager().mergeIndefiniteBans();
|
||||
send(sender, "Reloaded indefinite bans");
|
||||
context.send(sender, "Reloaded indefinite bans");
|
||||
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault"))
|
||||
{
|
||||
throw new RuntimeException("Vault is required to run on the server if you use permissions!");
|
||||
}
|
||||
plugin.getServiceManager().endServices();
|
||||
plugin.getServiceManager().startServices();
|
||||
send(sender, "Restarted services.");
|
||||
context.send(sender, "Restarted services.");
|
||||
TimeUtils.TIMEZONE = plugin.config.getString("server.timezone");
|
||||
send(sender, "Set timezone to: " + TimeUtils.TIMEZONE);
|
||||
send(sender, "Plex successfully reloaded.");
|
||||
context.send(sender, "Set timezone to: " + TimeUtils.TIMEZONE);
|
||||
context.send(sender, "Plex successfully reloaded.");
|
||||
return null;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("redis"))
|
||||
{
|
||||
checkPermission(sender, "plex.redis");
|
||||
context.checkPermission(sender, "plex.redis");
|
||||
if (!plugin.getRedisConnection().isEnabled())
|
||||
{
|
||||
throw new CommandFailException("&cRedis is not enabled.");
|
||||
}
|
||||
plugin.getRedisConnection().execute(jedis -> jedis.set("test", "123"));
|
||||
send(sender, "Set test to 123. Now outputting key test...");
|
||||
context.send(sender, "Set test to 123. Now outputting key test...");
|
||||
String test = plugin.getRedisConnection().query(jedis -> jedis.get("test"));
|
||||
send(sender, test);
|
||||
context.send(sender, test);
|
||||
return null;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("modules"))
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return mmString("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
|
||||
return context.mmString("<gold>Modules (" + plugin.getModuleManager().getModules().size() + "): <yellow>" + StringUtils.join(plugin.getModuleManager().getModules().stream().map(PlexModule::getPlexModuleFile).map(PlexModuleFile::getName).collect(Collectors.toList()), ", "));
|
||||
}
|
||||
if (args[1].equalsIgnoreCase("reload"))
|
||||
{
|
||||
checkPermission(sender, "plex.modules.reload");
|
||||
context.checkPermission(sender, "plex.modules.reload");
|
||||
plugin.getModuleManager().reloadModules();
|
||||
return mmString("<green>All modules reloaded!");
|
||||
return context.mmString("<green>All modules reloaded!");
|
||||
}
|
||||
else if (args[1].equalsIgnoreCase("update"))
|
||||
{
|
||||
if (!hasUpdateAccess(playerSender, sender))
|
||||
if (!hasUpdateAccess(context, playerSender, sender))
|
||||
{
|
||||
return mmString("<red>You must be a Developer to use this command.");
|
||||
return context.mmString("<red>You must be a Developer to use this command.");
|
||||
}
|
||||
for (PlexModule module : plugin.getModuleManager().getModules())
|
||||
{
|
||||
plugin.getUpdateChecker().updateJar(sender, module.getPlexModuleFile().getName(), true);
|
||||
}
|
||||
plugin.getModuleManager().reloadModules();
|
||||
return mmString("<green>All modules updated and reloaded!");
|
||||
return context.mmString("<green>All modules updated and reloaded!");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("update"))
|
||||
{
|
||||
if (!hasUpdateAccess(playerSender, sender))
|
||||
if (!hasUpdateAccess(context, playerSender, sender))
|
||||
{
|
||||
return mmString("<red>You must be a Developer to use this command.");
|
||||
return context.mmString("<red>You must be a Developer to use this command.");
|
||||
}
|
||||
if (!plugin.getUpdateChecker().getUpdateStatusMessage(sender, false, 0))
|
||||
{
|
||||
return mmString("<red>Plex is already up to date!");
|
||||
return context.mmString("<red>Plex is already up to date!");
|
||||
}
|
||||
plugin.getUpdateChecker().updateJar(sender, "Plex", false);
|
||||
return mmString("<red>Alert: Restart the server for the new JAR file to be applied.");
|
||||
return context.mmString("<red>Alert: Restart the server for the new JAR file to be applied.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Owners and developers only have access
|
||||
private boolean hasUpdateAccess(Player player, CommandSender sender)
|
||||
private boolean hasUpdateAccess(ServerCommandContext context, Player player, CommandSender sender)
|
||||
{
|
||||
// Allow CONSOLE, get OfflinePlayer for Telnet
|
||||
if (isConsole(sender))
|
||||
if (context.isConsole(sender))
|
||||
{
|
||||
if (sender.getName().equalsIgnoreCase("CONSOLE"))
|
||||
{
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.menu.impl.PunishedPlayerMenu;
|
||||
@@ -19,12 +18,19 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "punishments", usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
|
||||
@CommandPermissions(permission = "plex.punishments", source = RequiredCommandSource.IN_GAME)
|
||||
public class PunishmentsCMD extends ServerCommand
|
||||
{
|
||||
public PunishmentsCMD()
|
||||
{
|
||||
super(command("punishments")
|
||||
.description("Opens the Punishments GUI")
|
||||
.usage("/<command> [player]")
|
||||
.aliases("punishlist,punishes")
|
||||
.permission("plex.punishments")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -34,8 +40,11 @@ public class PunishmentsCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
new PunishmentMenu(plugin.getPlayerService()).open(playerSender);
|
||||
@@ -48,7 +57,7 @@ public class PunishmentsCMD extends ServerCommand
|
||||
}
|
||||
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[0]);
|
||||
final PlexPlayer player = offlinePlayer.isOnline() ? getOnlinePlexPlayer(args[0]) : getOfflinePlexPlayer(offlinePlayer.getUniqueId());
|
||||
final PlexPlayer player = offlinePlayer.isOnline() ? context.getOnlinePlexPlayer(args[0]) : context.getOfflinePlexPlayer(offlinePlayer.getUniqueId());
|
||||
|
||||
new PunishedPlayerMenu(player, plugin.getPlayerService()).open(playerSender);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
|
||||
@@ -14,12 +12,17 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.rawsay", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "rawsay", usage = "/<command> <message>", description = "Displays a raw message to everyone")
|
||||
public class RawSayCMD extends ServerCommand
|
||||
{
|
||||
public RawSayCMD()
|
||||
{
|
||||
super(command("rawsay")
|
||||
.description("Displays a raw message to everyone")
|
||||
.usage("/<command> <message>")
|
||||
.permission("plex.rawsay")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -29,11 +32,14 @@ public class RawSayCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(StringUtils.join(args, " "));
|
||||
|
||||
@@ -3,9 +3,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
|
||||
|
||||
@@ -14,55 +12,64 @@ 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;
|
||||
|
||||
@CommandPermissions(permission = "plex.removeloginmessage", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "removeloginmessage", usage = "/<command> [-o <player>]", description = "Remove your own (or someone else's) login message", aliases = "rlm,removeloginmsg")
|
||||
public class RemoveLoginMessageCMD extends ServerCommand
|
||||
{
|
||||
public RemoveLoginMessageCMD()
|
||||
{
|
||||
super(command("removeloginmessage")
|
||||
.description("Remove your own (or someone else's) login message")
|
||||
.usage("/<command> [-o <player>]")
|
||||
.aliases("rlm,removeloginmsg")
|
||||
.permission("plex.removeloginmessage")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
command.executes(context -> executeCommand(context));
|
||||
command.then(literal("-o")
|
||||
.requires(source -> silentCheckPermission(source.getSender(), "plex.removeloginmessage.others"))
|
||||
.requires(source -> canUsePermission(source, "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)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
if (args.length == 0 && !isConsole(sender))
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0 && !context.isConsole(sender))
|
||||
{
|
||||
if (playerSender != null)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||
plexPlayer.setLoginMessage("");
|
||||
return messageComponent("removedOwnLoginMessage");
|
||||
return context.messageComponent("removedOwnLoginMessage");
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("-o"))
|
||||
{
|
||||
checkPermission(sender, "plex.removeloginmessage.others");
|
||||
context.checkPermission(sender, "plex.removeloginmessage.others");
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
return messageComponent("specifyPlayer");
|
||||
return context.messageComponent("specifyPlayer");
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(args[1]);
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
return messageComponent("playerNotFound");
|
||||
return context.messageComponent("playerNotFound");
|
||||
}
|
||||
plexPlayer.setLoginMessage("");
|
||||
return messageComponent("removedOtherLoginMessage", plexPlayer.getName());
|
||||
return context.messageComponent("removedOtherLoginMessage", plexPlayer.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return messageComponent("noPermissionConsole");
|
||||
return context.messageComponent("noPermissionConsole");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
|
||||
@@ -14,12 +12,17 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.say", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "say", usage = "/<command> <message>", description = "Displays a message to everyone")
|
||||
public class SayCMD extends ServerCommand
|
||||
{
|
||||
public SayCMD()
|
||||
{
|
||||
super(command("say")
|
||||
.description("Displays a message to everyone")
|
||||
.usage("/<command> <message>")
|
||||
.permission("plex.say")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -29,11 +32,14 @@ public class SayCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("sayMessage", sender.getName(), PlexUtils.mmStripColor(StringUtils.join(args, " "))));
|
||||
|
||||
@@ -3,10 +3,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
@@ -20,12 +18,18 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.setloginmessage", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "setloginmessage", usage = "/<command> [-o <player>] <message>", description = "Sets your (or someone else's) login message", aliases = "slm,setloginmsg")
|
||||
public class SetLoginMessageCMD extends ServerCommand
|
||||
{
|
||||
public SetLoginMessageCMD()
|
||||
{
|
||||
super(command("setloginmessage")
|
||||
.description("Sets your (or someone else's) login message")
|
||||
.usage("/<command> [-o <player>] <message>")
|
||||
.aliases("slm,setloginmsg")
|
||||
.permission("plex.setloginmessage")
|
||||
.build());
|
||||
}
|
||||
private final boolean nameRequired = plugin.getConfig().getBoolean("loginmessages.name");
|
||||
|
||||
@Override
|
||||
@@ -35,7 +39,7 @@ public class SetLoginMessageCMD extends ServerCommand
|
||||
command.then(greedyString("message")
|
||||
.suggests((context, builder) ->
|
||||
{
|
||||
if (!silentCheckPermission(context.getSource().getSender(), "plex.setloginmessage.others"))
|
||||
if (!canUsePermission(context.getSource(), "plex.setloginmessage.others"))
|
||||
{
|
||||
return builder.buildFuture();
|
||||
}
|
||||
@@ -61,58 +65,61 @@ public class SetLoginMessageCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
if (playerSender != null)
|
||||
{
|
||||
if (args[0].equals("-o"))
|
||||
{
|
||||
checkPermission(sender, "plex.setloginmessage.others");
|
||||
context.checkPermission(sender, "plex.setloginmessage.others");
|
||||
|
||||
if (args.length < 2)
|
||||
{
|
||||
return messageComponent("specifyPlayer");
|
||||
return context.messageComponent("specifyPlayer");
|
||||
}
|
||||
if (args.length < 3)
|
||||
{
|
||||
return messageComponent("specifyLoginMessage");
|
||||
return context.messageComponent("specifyLoginMessage");
|
||||
}
|
||||
PlexPlayer plexPlayer = plugin.getPlayerService().getPlayer(args[1]);
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
return messageComponent("playerNotFound");
|
||||
return context.messageComponent("playerNotFound");
|
||||
}
|
||||
String message = StringUtils.join(args, " ", 2, args.length);
|
||||
message = message.replace(plexPlayer.getName(), "%player%");
|
||||
validateMessage(message);
|
||||
validateMessage(context, message);
|
||||
plexPlayer.setLoginMessage(message);
|
||||
return messageComponent("setOtherPlayersLoginMessage", plexPlayer.getName(),
|
||||
return context.messageComponent("setOtherPlayersLoginMessage", plexPlayer.getName(),
|
||||
MiniMessage.miniMessage().serialize(PlexUtils.stringToComponent(message.replace("%player%", plexPlayer.getName()))));
|
||||
}
|
||||
if (isConsole(sender))
|
||||
if (context.isConsole(sender))
|
||||
{
|
||||
return messageComponent("noPermissionConsole");
|
||||
return context.messageComponent("noPermissionConsole");
|
||||
}
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayer(playerSender.getUniqueId());
|
||||
String message = StringUtils.join(args, " ", 0, args.length)
|
||||
.replace(plexPlayer.getName(), "%player%");
|
||||
validateMessage(message);
|
||||
validateMessage(context, message);
|
||||
plexPlayer.setLoginMessage(message);
|
||||
return messageComponent("setOwnLoginMessage", PlexUtils.stringToComponent(message.replace("%player%", plexPlayer.getName())));
|
||||
return context.messageComponent("setOwnLoginMessage", PlexUtils.stringToComponent(message.replace("%player%", plexPlayer.getName())));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void validateMessage(String message)
|
||||
private void validateMessage(ServerCommandContext context, String message)
|
||||
{
|
||||
if (nameRequired && !message.contains("%player%"))
|
||||
{
|
||||
PlexLog.debug("Validating login message has a valid name in it");
|
||||
throw new CommandFailException(messageString("nameRequired"));
|
||||
throw new CommandFailException(context.messageString("nameRequired"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -26,12 +24,17 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.smite", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "smite", usage = "/<command> <player> [reason] [-ci | -q]", description = "Someone being a little bitch? Smite them down...")
|
||||
public class SmiteCMD extends ServerCommand
|
||||
{
|
||||
public SmiteCMD()
|
||||
{
|
||||
super(command("smite")
|
||||
.description("Someone being a little bitch? Smite them down...")
|
||||
.usage("/<command> <player> [reason] [-ci | -q]")
|
||||
.permission("plex.smite")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -44,11 +47,14 @@ public class SmiteCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length < 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
String reason = null;
|
||||
@@ -79,19 +85,19 @@ public class SmiteCMD extends ServerCommand
|
||||
}
|
||||
}
|
||||
|
||||
final Player player = getNonNullPlayer(args[0]);
|
||||
final PlexPlayer plexPlayer = getPlexPlayer(player);
|
||||
final Player player = context.getNonNullPlayer(args[0]);
|
||||
final PlexPlayer plexPlayer = context.getPlexPlayer(player);
|
||||
|
||||
Title title = Title.title(messageComponent("smiteTitleHeader"), messageComponent("smiteTitleMessage", reason, sender.getName()));
|
||||
Title title = Title.title(context.messageComponent("smiteTitleHeader"), context.messageComponent("smiteTitleMessage", reason, sender.getName()));
|
||||
player.showTitle(title);
|
||||
|
||||
if (!silent)
|
||||
{
|
||||
PlexUtils.broadcast(messageComponent("smiteBroadcast", player.getName(), reason != null ? reason : messageString("noReasonProvided"), sender.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("smiteBroadcast", player.getName(), reason != null ? reason : context.messageString("noReasonProvided"), sender.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
send(sender, messageComponent("smittenQuietly", player.getName()));
|
||||
context.send(sender, context.messageComponent("smittenQuietly", player.getName()));
|
||||
}
|
||||
|
||||
// Set gamemode to survival
|
||||
@@ -118,7 +124,7 @@ public class SmiteCMD extends ServerCommand
|
||||
// Kill
|
||||
player.setHealth(0.0);
|
||||
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), getUUID(sender));
|
||||
Punishment punishment = new Punishment(plexPlayer.getUuid(), context.getUUID(sender));
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
||||
punishment.setType(PunishmentType.SMITE);
|
||||
@@ -129,7 +135,7 @@ public class SmiteCMD extends ServerCommand
|
||||
{
|
||||
punishment.setReason(reason);
|
||||
}
|
||||
send(player, messageComponent("smitten", reason != null ? reason : messageString("noReasonProvided")));
|
||||
context.send(player, context.messageComponent("smitten", reason != null ? reason : context.messageString("noReasonProvided")));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -17,49 +15,57 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.gamemode.spectator", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "spectator", aliases = "gmsp,egmsp,spec", description = "Set your own or another player's gamemode to spectator mode")
|
||||
public class SpectatorCMD extends ServerCommand
|
||||
{
|
||||
public SpectatorCMD()
|
||||
{
|
||||
super(command("spectator")
|
||||
.description("Set your own or another player's gamemode to spectator mode")
|
||||
.aliases("gmsp,egmsp,spec")
|
||||
.permission("plex.gamemode.spectator")
|
||||
.build());
|
||||
}
|
||||
@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"))
|
||||
.requires(source -> canUsePermission(source, "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)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
if (context.isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(messageString("consoleMustDefinePlayer"));
|
||||
throw new CommandFailException(context.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SPECTATOR));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkPermission(sender, "plex.gamemode.spectator.others"))
|
||||
if (context.checkPermission(sender, "plex.gamemode.spectator.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SPECTATOR);
|
||||
messageComponent("gameModeSetTo", "spectator");
|
||||
context.messageComponent("gameModeSetTo", "spectator");
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "spectator"));
|
||||
PlexUtils.broadcast(context.messageComponent("setEveryoneGameMode", sender.getName(), "spectator"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
Player nPlayer = context.getNonNullPlayer(args[0]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.SPECTATOR));
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -2,10 +2,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.event.GameModeUpdateEvent;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -17,49 +15,57 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.gamemode.survival", source = RequiredCommandSource.ANY)
|
||||
@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
|
||||
{
|
||||
public SurvivalCMD()
|
||||
{
|
||||
super(command("survival")
|
||||
.description("Set your own or another player's gamemode to survival mode")
|
||||
.aliases("gms,egms,esurvival,survivalmode,esurvivalmode")
|
||||
.permission("plex.gamemode.survival")
|
||||
.build());
|
||||
}
|
||||
@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"))
|
||||
.requires(source -> canUsePermission(source, "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)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
if (context.isConsole(sender))
|
||||
{
|
||||
throw new CommandFailException(messageString("consoleMustDefinePlayer"));
|
||||
throw new CommandFailException(context.messageString("consoleMustDefinePlayer"));
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, playerSender, GameMode.SURVIVAL));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (checkPermission(sender, "plex.gamemode.survival.others"))
|
||||
if (context.checkPermission(sender, "plex.gamemode.survival.others"))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
||||
send(targetPlayer, messageComponent("gameModeSetTo", "survival"));
|
||||
context.send(targetPlayer, context.messageComponent("gameModeSetTo", "survival"));
|
||||
}
|
||||
PlexUtils.broadcast(messageComponent("setEveryoneGameMode", sender.getName(), "survival"));
|
||||
PlexUtils.broadcast(context.messageComponent("setEveryoneGameMode", sender.getName(), "survival"));
|
||||
return null;
|
||||
}
|
||||
|
||||
Player nPlayer = getNonNullPlayer(args[0]);
|
||||
Player nPlayer = context.getNonNullPlayer(args[0]);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new GameModeUpdateEvent(sender, nPlayer, GameMode.SURVIVAL));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -19,12 +17,18 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.tag", source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(name = "tag", aliases = "prefix", description = "Set or clear your prefix", usage = "/<command> <set <prefix> | clear <player>>")
|
||||
public class TagCMD extends ServerCommand
|
||||
{
|
||||
public TagCMD()
|
||||
{
|
||||
super(command("tag")
|
||||
.description("Set or clear your prefix")
|
||||
.usage("/<command> <set <prefix> | clear <player>>")
|
||||
.aliases("prefix")
|
||||
.permission("plex.tag")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -40,40 +44,43 @@ public class TagCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return usage("/tag clear <player>");
|
||||
return context.usage("/tag clear <player>");
|
||||
}
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("set"))
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return messageComponent("noPermissionConsole");
|
||||
return context.messageComponent("noPermissionConsole");
|
||||
}
|
||||
assert playerSender != null;
|
||||
PlexPlayer player = plugin.getPlayerService().getPlayer(playerSender.getUniqueId());
|
||||
if (args.length < 2)
|
||||
{
|
||||
return usage("/tag set <prefix>");
|
||||
return context.usage("/tag set <prefix>");
|
||||
}
|
||||
|
||||
Component convertedComponent = PlexUtils.stringToComponent(StringUtils.join(args, " ", 1, args.length));
|
||||
|
||||
if (PlainTextComponentSerializer.plainText().serialize(convertedComponent).length() > plugin.config.getInt("chat.max-tag-length", 16))
|
||||
{
|
||||
return messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
|
||||
return context.messageComponent("maximumPrefixLength", plugin.config.getInt("chat.max-tag-length", 16));
|
||||
}
|
||||
|
||||
player.setPrefix(MiniMessage.miniMessage().serialize(convertedComponent));
|
||||
plugin.getPlayerService().update(player);
|
||||
return messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
|
||||
return context.messageComponent("prefixSetTo", MiniMessage.miniMessage().serialize(convertedComponent));
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("clear"))
|
||||
@@ -82,7 +89,7 @@ public class TagCMD extends ServerCommand
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
return messageComponent("noPermissionConsole");
|
||||
return context.messageComponent("noPermissionConsole");
|
||||
}
|
||||
|
||||
if (playerSender == null)
|
||||
@@ -93,16 +100,16 @@ public class TagCMD extends ServerCommand
|
||||
PlexPlayer player = plugin.getPlayerService().getPlayer(playerSender.getUniqueId());
|
||||
player.setPrefix(null);
|
||||
plugin.getPlayerService().update(player);
|
||||
return messageComponent("prefixCleared");
|
||||
return context.messageComponent("prefixCleared");
|
||||
}
|
||||
checkPermission(sender, "plex.tag.clear.others");
|
||||
Player target = getNonNullPlayer(args[1]);
|
||||
context.checkPermission(sender, "plex.tag.clear.others");
|
||||
Player target = context.getNonNullPlayer(args[1]);
|
||||
PlexPlayer plexTarget = plugin.getPlayerService().getPlayer(target.getUniqueId());
|
||||
plexTarget.setPrefix(null);
|
||||
plugin.getPlayerService().update(plexTarget);
|
||||
return messageComponent("otherPrefixCleared", target.getName());
|
||||
return context.messageComponent("otherPrefixCleared", target.getName());
|
||||
}
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -23,13 +21,18 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@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
|
||||
{
|
||||
public TempbanCMD()
|
||||
{
|
||||
super(command("tempban")
|
||||
.description("Temporarily ban a player")
|
||||
.usage("/<command> <player> <time> [message] [-rb]")
|
||||
.permission("plex.tempban")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -43,11 +46,14 @@ public class TempbanCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length <= 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
PlexPlayer target = plugin.getPlayerService().getPlayer(args[0]);
|
||||
@@ -61,21 +67,21 @@ public class TempbanCMD extends ServerCommand
|
||||
|
||||
if (plugin.getPunishmentManager().isBanned(target.getUuid()))
|
||||
{
|
||||
return messageComponent("playerBanned");
|
||||
return context.messageComponent("playerBanned");
|
||||
}
|
||||
Punishment punishment = new Punishment(target.getUuid(), getUUID(sender));
|
||||
Punishment punishment = new Punishment(target.getUuid(), context.getUUID(sender));
|
||||
punishment.setType(PunishmentType.TEMPBAN);
|
||||
boolean rollBack = false;
|
||||
if (args.length > 2)
|
||||
{
|
||||
reason = StringUtils.join(args, " ", 2, args.length);
|
||||
String newReason = StringUtils.normalizeSpace(reason.replace("-rb", ""));
|
||||
punishment.setReason(newReason.trim().isEmpty() ? messageString("noReasonProvided") : newReason);
|
||||
punishment.setReason(newReason.trim().isEmpty() ? context.messageString("noReasonProvided") : newReason);
|
||||
rollBack = reason.startsWith("-rb") || reason.endsWith("-rb");
|
||||
}
|
||||
else
|
||||
{
|
||||
punishment.setReason(messageString("noReasonProvided"));
|
||||
punishment.setReason(context.messageString("noReasonProvided"));
|
||||
}
|
||||
punishment.setPunishedUsername(target.getName());
|
||||
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
||||
@@ -83,7 +89,7 @@ public class TempbanCMD extends ServerCommand
|
||||
punishment.setActive(true);
|
||||
punishment.setIp(target.getIps().getLast());
|
||||
plugin.getPunishmentManager().punish(target, punishment);
|
||||
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), target.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("banningPlayer", sender.getName(), target.getName()));
|
||||
if (player != null)
|
||||
{
|
||||
plugin.getApi().scheduler().runEntity(player, () -> BungeeUtil.kickPlayer(plugin, player, Punishment.generateBanMessage(punishment, plugin.config.getString("banning.ban_url"), plugin.getPlayerService())));
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
@@ -18,13 +17,18 @@ 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 = "tempmute", description = "Temporarily mute a player on the server",
|
||||
usage = "/<command> <player> <time> [reason]", aliases = "tmute")
|
||||
@CommandPermissions(permission = "plex.tempmute")
|
||||
public class TempmuteCMD extends ServerCommand
|
||||
{
|
||||
public TempmuteCMD()
|
||||
{
|
||||
super(command("tempmute")
|
||||
.description("Temporarily mute a player on the server")
|
||||
.usage("/<command> <player> <time> [reason]")
|
||||
.aliases("tmute")
|
||||
.permission("plex.tempmute")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -37,24 +41,27 @@ public class TempmuteCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length < 2)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = getOfflinePlexPlayer(player.getUniqueId());
|
||||
Player player = context.getNonNullPlayer(args[0]);
|
||||
PlexPlayer punishedPlayer = context.getOfflinePlexPlayer(player.getUniqueId());
|
||||
|
||||
if (punishedPlayer.isMuted())
|
||||
{
|
||||
return messageComponent("playerMuted");
|
||||
return context.messageComponent("playerMuted");
|
||||
}
|
||||
|
||||
if (silentCheckPermission(player, "plex.tempmute"))
|
||||
if (context.silentCheckPermission(player, "plex.tempmute"))
|
||||
{
|
||||
send(sender, messageComponent("higherRankThanYou"));
|
||||
context.send(sender, context.messageComponent("higherRankThanYou"));
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -65,24 +72,24 @@ public class TempmuteCMD extends ServerCommand
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return messageComponent("invalidTimeFormat");
|
||||
return context.messageComponent("invalidTimeFormat");
|
||||
}
|
||||
|
||||
if (endDate.isBefore(ZonedDateTime.now()))
|
||||
{
|
||||
return messageComponent("timeMustBeFuture");
|
||||
return context.messageComponent("timeMustBeFuture");
|
||||
}
|
||||
|
||||
ZonedDateTime oneWeekFromNow = ZonedDateTime.now().plusWeeks(1);
|
||||
if (endDate.isAfter(oneWeekFromNow))
|
||||
{
|
||||
return messageComponent("maxTimeExceeded");
|
||||
return context.messageComponent("maxTimeExceeded");
|
||||
}
|
||||
|
||||
final String reason = args.length >= 3 ? String.join(" ", Arrays.copyOfRange(args, 2, args.length))
|
||||
: messageString("noReasonProvided");
|
||||
: context.messageString("noReasonProvided");
|
||||
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), getUUID(sender));
|
||||
Punishment punishment = new Punishment(punishedPlayer.getUuid(), context.getUUID(sender));
|
||||
punishment.setCustomTime(true);
|
||||
punishment.setEndDate(endDate);
|
||||
punishment.setType(PunishmentType.MUTE);
|
||||
@@ -92,7 +99,7 @@ public class TempmuteCMD extends ServerCommand
|
||||
punishment.setActive(true);
|
||||
|
||||
plugin.getPunishmentManager().punish(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(messageComponent("tempMutedPlayer", sender.getName(), player.getName(), TimeUtils.formatRelativeTime(endDate)));
|
||||
PlexUtils.broadcast(context.messageComponent("tempMutedPlayer", sender.getName(), player.getName(), TimeUtils.formatRelativeTime(endDate)));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,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;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.menu.impl.ToggleMenu;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -14,12 +12,17 @@ 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 = "toggle", description = "Allows toggling various server aspects through a GUI", aliases = "toggles")
|
||||
@CommandPermissions(permission = "plex.toggle", source = RequiredCommandSource.ANY)
|
||||
public class ToggleCMD extends ServerCommand
|
||||
{
|
||||
public ToggleCMD()
|
||||
{
|
||||
super(command("toggle")
|
||||
.description("Allows toggling various server aspects through a GUI")
|
||||
.aliases("toggles")
|
||||
.permission("plex.toggle")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -39,51 +42,54 @@ public class ToggleCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
if (isConsole(sender) || playerSender == null)
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (context.isConsole(sender) || playerSender == null)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.sendMessage(messageComponent("toggleAvailable"));
|
||||
sender.sendMessage(toggleListItem("toggleExplosions", "explosions"));
|
||||
sender.sendMessage(toggleListItem("toggleFluidSpread", "fluidspread"));
|
||||
sender.sendMessage(toggleListItem("toggleDrops", "drops"));
|
||||
sender.sendMessage(toggleListItem("toggleRedstone", "redstone"));
|
||||
sender.sendMessage(toggleListItem("togglePvp", "pvp"));
|
||||
sender.sendMessage(toggleListItem("toggleChat", "chat"));
|
||||
sender.sendMessage(context.messageComponent("toggleAvailable"));
|
||||
sender.sendMessage(toggleListItem(context, "toggleExplosions", "explosions"));
|
||||
sender.sendMessage(toggleListItem(context, "toggleFluidSpread", "fluidspread"));
|
||||
sender.sendMessage(toggleListItem(context, "toggleDrops", "drops"));
|
||||
sender.sendMessage(toggleListItem(context, "toggleRedstone", "redstone"));
|
||||
sender.sendMessage(toggleListItem(context, "togglePvp", "pvp"));
|
||||
sender.sendMessage(toggleListItem(context, "toggleChat", "chat"));
|
||||
return null;
|
||||
}
|
||||
switch (args[0].toLowerCase())
|
||||
{
|
||||
case "explosions" ->
|
||||
{
|
||||
return toggle("explosions");
|
||||
return toggle(context, "explosions");
|
||||
}
|
||||
case "fluidspread" ->
|
||||
{
|
||||
return toggle("fluidspread");
|
||||
return toggle(context, "fluidspread");
|
||||
}
|
||||
case "drops" ->
|
||||
{
|
||||
return toggle("drops");
|
||||
return toggle(context, "drops");
|
||||
}
|
||||
case "redstone" ->
|
||||
{
|
||||
return toggle("redstone");
|
||||
return toggle(context, "redstone");
|
||||
}
|
||||
case "pvp" ->
|
||||
{
|
||||
return toggle("pvp");
|
||||
return toggle(context, "pvp");
|
||||
}
|
||||
case "chat" ->
|
||||
{
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("chatToggled", sender.getName(), messageString(plugin.toggles.getBoolean("chat") ? "stateOff" : "stateOn")));
|
||||
return toggle("chat");
|
||||
PlexUtils.broadcast(PlexUtils.messageComponent("chatToggled", sender.getName(), context.messageString(plugin.toggles.getBoolean("chat") ? "stateOff" : "stateOn")));
|
||||
return toggle(context, "chat");
|
||||
}
|
||||
default ->
|
||||
{
|
||||
return messageComponent("invalidToggle");
|
||||
return context.messageComponent("invalidToggle");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,20 +97,20 @@ public class ToggleCMD extends ServerCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
private Component toggleListItem(String nameKey, String toggle)
|
||||
private Component toggleListItem(ServerCommandContext context, String nameKey, String toggle)
|
||||
{
|
||||
return messageComponent("toggleListItem", messageString(nameKey), status(toggle));
|
||||
return context.messageComponent("toggleListItem", context.messageString(nameKey), status(context, toggle));
|
||||
}
|
||||
|
||||
private Component toggle(String toggle)
|
||||
private Component toggle(ServerCommandContext context, String toggle)
|
||||
{
|
||||
plugin.toggles.set(toggle, !plugin.getToggles().getBoolean(toggle));
|
||||
return messageComponent("toggleCommandResult", messageString(toggleNameKey(toggle)), status(toggle));
|
||||
return context.messageComponent("toggleCommandResult", context.messageString(toggleNameKey(toggle)), status(context, toggle));
|
||||
}
|
||||
|
||||
private String status(String toggle)
|
||||
private String status(ServerCommandContext context, String toggle)
|
||||
{
|
||||
return messageString(plugin.toggles.getBoolean(toggle) ? "stateEnabled" : "stateDisabled");
|
||||
return context.messageString(plugin.toggles.getBoolean(toggle) ? "stateEnabled" : "stateDisabled");
|
||||
}
|
||||
|
||||
private String toggleNameKey(String toggle)
|
||||
|
||||
@@ -3,10 +3,8 @@ 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.ServerCommandContext;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexUtils;
|
||||
|
||||
@@ -16,13 +14,18 @@ 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 = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
||||
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
|
||||
|
||||
public class UnbanCMD extends ServerCommand
|
||||
{
|
||||
public UnbanCMD()
|
||||
{
|
||||
super(command("unban")
|
||||
.description("Unbans a player, offline or online")
|
||||
.usage("/<command> <player>")
|
||||
.permission("plex.ban")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -32,11 +35,14 @@ public class UnbanCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
@@ -52,11 +58,11 @@ public class UnbanCMD extends ServerCommand
|
||||
{
|
||||
if (!aBoolean)
|
||||
{
|
||||
send(sender, messageComponent("playerNotBanned"));
|
||||
context.send(sender, context.messageComponent("playerNotBanned"));
|
||||
return;
|
||||
}
|
||||
plugin.getPunishmentManager().unban(target.getUuid());
|
||||
PlexUtils.broadcast(messageComponent("unbanningPlayer", sender.getName(), target.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("unbanningPlayer", sender.getName(), target.getName()));
|
||||
});
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
@@ -17,12 +16,17 @@ 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;
|
||||
|
||||
@CommandPermissions(permission = "plex.unfreeze")
|
||||
@CommandParameters(name = "unfreeze", description = "Unfreeze a player", usage = "/<command> <player>")
|
||||
public class UnfreezeCMD extends ServerCommand
|
||||
{
|
||||
public UnfreezeCMD()
|
||||
{
|
||||
super(command("unfreeze")
|
||||
.description("Unfreeze a player")
|
||||
.usage("/<command> <player>")
|
||||
.permission("plex.unfreeze")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -32,11 +36,14 @@ public class UnfreezeCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
PlexPlayer punishedPlayer = plugin.getPlayerService().getPlayer(args[0]);
|
||||
if (punishedPlayer == null)
|
||||
@@ -54,7 +61,7 @@ public class UnfreezeCMD extends ServerCommand
|
||||
punishment.setActive(false);
|
||||
plugin.getPunishmentRepository().updatePunishment(punishment.getType(), false, punishment.getPunished());
|
||||
});
|
||||
PlexUtils.broadcast(messageComponent("unfrozePlayer", sender.getName(), punishedPlayer.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("unfrozePlayer", sender.getName(), punishedPlayer.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
@@ -17,12 +16,18 @@ 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;
|
||||
|
||||
@CommandPermissions(permission = "plex.unmute")
|
||||
@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/<command> <player>", aliases = "eunmute")
|
||||
public class UnmuteCMD extends ServerCommand
|
||||
{
|
||||
public UnmuteCMD()
|
||||
{
|
||||
super(command("unmute")
|
||||
.description("Unmute a player")
|
||||
.usage("/<command> <player>")
|
||||
.aliases("eunmute")
|
||||
.permission("plex.unmute")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -32,11 +37,14 @@ public class UnmuteCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
PlexPlayer punishedPlayer = plugin.getPlayerService().getPlayer(args[0]);
|
||||
if (punishedPlayer == null)
|
||||
@@ -54,7 +62,7 @@ public class UnmuteCMD extends ServerCommand
|
||||
punishment.setActive(false);
|
||||
plugin.getPunishmentRepository().updatePunishment(punishment.getType(), false, punishment.getPunished());
|
||||
});
|
||||
PlexUtils.broadcast(messageComponent("unmutedPlayer", sender.getName(), punishedPlayer.getName()));
|
||||
PlexUtils.broadcast(context.messageComponent("unmutedPlayer", sender.getName(), punishedPlayer.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -17,12 +16,18 @@ import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.whohas")
|
||||
@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
|
||||
{
|
||||
public WhoHasCMD()
|
||||
{
|
||||
super(command("whohas")
|
||||
.description("Returns a list of players with a specific item in their inventory.")
|
||||
.usage("/<command> <material>")
|
||||
.aliases("wh")
|
||||
.permission("plex.whohas")
|
||||
.build());
|
||||
}
|
||||
@Override
|
||||
protected void buildCommand(LiteralArgumentBuilder<CommandSourceStack> command)
|
||||
{
|
||||
@@ -35,25 +40,28 @@ public class WhoHasCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
if (args.length == 0)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
final Material material = Material.getMaterial(args[0].toUpperCase());
|
||||
|
||||
if (material == null)
|
||||
{
|
||||
return messageComponent("materialNotFound", args[0]);
|
||||
return context.messageComponent("materialNotFound", args[0]);
|
||||
}
|
||||
|
||||
boolean clearInventory = args.length > 1 && args[1].equalsIgnoreCase("clear");
|
||||
|
||||
if (clearInventory && !sender.hasPermission("plex.whohas.clear"))
|
||||
{
|
||||
return messageComponent("noPermissionNode", "plex.whohas.clear");
|
||||
return context.messageComponent("noPermissionNode", "plex.whohas.clear");
|
||||
}
|
||||
|
||||
List<TextComponent> players = Bukkit.getOnlinePlayers().stream().filter(player ->
|
||||
@@ -68,11 +76,11 @@ public class WhoHasCMD extends ServerCommand
|
||||
}).toList();
|
||||
|
||||
return players.isEmpty() ?
|
||||
messageComponent("nobodyHasThatMaterial") :
|
||||
context.messageComponent("nobodyHasThatMaterial") :
|
||||
(clearInventory ?
|
||||
messageComponent("playersMaterialCleared", Component.text(material.name()),
|
||||
context.messageComponent("playersMaterialCleared", Component.text(material.name()),
|
||||
Component.join(JoinConfiguration.commas(true), players)) :
|
||||
messageComponent("playersWithMaterial", Component.text(material.name()),
|
||||
context.messageComponent("playersWithMaterial", Component.text(material.name()),
|
||||
Component.join(JoinConfiguration.commas(true), players)));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,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;
|
||||
import dev.plex.command.ServerCommandContext;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
|
||||
import java.util.List;
|
||||
@@ -18,12 +17,18 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandPermissions(permission = "plex.world", source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(name = "world", description = "Teleport to a world.", usage = "/<command> <world>")
|
||||
public class WorldCMD extends ServerCommand
|
||||
{
|
||||
public WorldCMD()
|
||||
{
|
||||
super(command("world")
|
||||
.description("Teleport to a world.")
|
||||
.usage("/<command> <world>")
|
||||
.permission("plex.world")
|
||||
.source(RequiredCommandSource.IN_GAME)
|
||||
.build());
|
||||
}
|
||||
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
|
||||
@@ -44,7 +49,7 @@ public class WorldCMD extends ServerCommand
|
||||
try
|
||||
{
|
||||
UUID uuid = UUID.fromString(worldName);
|
||||
if (uuid.equals(player.getUniqueId()) || silentCheckPermission(player, "plex.world.playerworlds"))
|
||||
if (uuid.equals(player.getUniqueId()) || player.hasPermission("plex.world.playerworlds"))
|
||||
{
|
||||
completions.add(worldName);
|
||||
}
|
||||
@@ -60,22 +65,25 @@ public class WorldCMD extends ServerCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
||||
protected Component execute(@NotNull ServerCommandContext context)
|
||||
{
|
||||
CommandSender sender = context.sender();
|
||||
Player playerSender = context.player();
|
||||
String[] args = context.args();
|
||||
assert playerSender != null;
|
||||
if (args.length != 1)
|
||||
{
|
||||
return usage();
|
||||
return context.usage();
|
||||
}
|
||||
|
||||
World world = getNonNullWorld(args[0]);
|
||||
World world = context.getNonNullWorld(args[0]);
|
||||
boolean playerWorld = args[0].matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}");
|
||||
if (playerWorld && plugin.getModuleManager().getModules().stream().anyMatch(plexModule -> plexModule.getPlexModuleFile().getName().equalsIgnoreCase("Module-TFMExtras")))
|
||||
{
|
||||
checkPermission(playerSender, "plex.world.playerworlds");
|
||||
context.checkPermission(playerSender, "plex.world.playerworlds");
|
||||
}
|
||||
playerSender.teleportAsync(world.getSpawnLocation());
|
||||
return messageComponent("playerWorldTeleport", world.getName());
|
||||
return context.messageComponent("playerWorldTeleport", world.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class CommandHandler
|
||||
{
|
||||
private final List<PlexCommand> commands = new ArrayList<>();
|
||||
private boolean lifecycleRegistered;
|
||||
private boolean lifecycleReloadRequired;
|
||||
|
||||
public CommandHandler(Plex plugin)
|
||||
{
|
||||
@@ -29,13 +30,24 @@ public class CommandHandler
|
||||
commands.add(command);
|
||||
if (lifecycleRegistered)
|
||||
{
|
||||
PlexLog.warn("Command {0} was registered after the Brigadier command lifecycle event; it will be included on the next command reload.", command.getName());
|
||||
lifecycleReloadRequired = true;
|
||||
PlexLog.warn("Command {0} was registered after the Brigadier command lifecycle event; it will be included on the next command lifecycle rebuild.", command.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterCommand(PlexCommand command)
|
||||
{
|
||||
commands.remove(command);
|
||||
boolean removed = commands.remove(command);
|
||||
if (removed && lifecycleRegistered)
|
||||
{
|
||||
lifecycleReloadRequired = true;
|
||||
PlexLog.warn("Command {0} was unregistered after the Brigadier command lifecycle event; Paper may keep the active Brigadier node until the next command lifecycle rebuild.", command.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean requiresLifecycleReload()
|
||||
{
|
||||
return lifecycleReloadRequired;
|
||||
}
|
||||
|
||||
public @Nullable PlexCommand getCommand(String name)
|
||||
@@ -75,6 +87,7 @@ public class CommandHandler
|
||||
}
|
||||
}
|
||||
lifecycleRegistered = true;
|
||||
lifecycleReloadRequired = false;
|
||||
PlexLog.log("Registered {0} Brigadier commands with {1} root labels.", commands.size(), labels);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,5 +182,9 @@ public class ModuleManager
|
||||
loadAllModules();
|
||||
loadModules();
|
||||
enableModules();
|
||||
if (plugin.getCommandHandler() != null && plugin.getCommandHandler().requiresLifecycleReload())
|
||||
{
|
||||
PlexLog.warn("Module command changes were staged after Paper's Brigadier command lifecycle. Restart the server for the live command dispatcher to match the loaded modules.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user