Class SimplePlexCommand
java.lang.Object
dev.plex.command.SimplePlexCommand
- All Implemented Interfaces:
PlexCommand
Convenience base for module commands with typed Brigadier command trees.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringTarget token that selects every online player. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSimplePlexCommand(CommandSpec commandSpec) Creates a command from a command definition. -
Method Summary
Modifier and TypeMethodDescriptionprotected PlexApiapi()Returns the bound Plex API.final voidSupplies the running Plex API to commands that need API helpers.final voidbindModule(PlexModule module) Supplies the owning module to commands that need module-owned resources.protected voidBroadcasts a MiniMessage-formatted message.protected voidbroadcast(net.kyori.adventure.text.Component component) Broadcasts a component.final com.mojang.brigadier.tree.LiteralCommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> Builds the Brigadier command tree for this command.protected booleancheckPermission(org.bukkit.command.CommandSender sender, String permission) Checks whether a sender has a permission node.protected static CommandSpec.BuilderStarts a command spec builder for the given command name.final CommandSpecReturns the command definition.protected net.kyori.adventure.text.ComponentcomponentFromString(String value) Converts text with legacy ampersand color codes to a component.protected abstract voidconfigureCommand(com.mojang.brigadier.builder.LiteralArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack> command) Configures this command's typed Brigadier tree.protected intexecuteCommand(com.mojang.brigadier.context.CommandContext<io.papermc.paper.command.brigadier.CommandSourceStack> context, BiFunction<org.bukkit.command.CommandSender, org.bukkit.entity.Player, net.kyori.adventure.text.Component> execution) protected org.bukkit.entity.PlayergetNonNullPlayer(String name) Returns an online player by UUID string or name.protected @Nullable UUIDgetUUID(org.bukkit.command.CommandSender sender) Returns a sender's UUID when the sender is a player.protected com.mojang.brigadier.builder.RequiredArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack, String> greedyString(String name) protected booleanisConsole(org.bukkit.command.CommandSender sender) Returns whether a sender is not a player.protected net.kyori.adventure.text.ComponentmessageComponent(String key, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... placeholders) Resolves a configured message as a component.protected StringmessageString(String key) Gets a raw configured MiniMessage template.protected net.kyori.adventure.text.ComponentConverts MiniMessage-formatted text to a component.protected net.kyori.adventure.text.ComponentnoColorComponentFromString(String value) Converts text with legacy ampersand color codes to a component without adding a default color.Returns the names of online players.protected <T extends io.papermc.paper.threadedregions.scheduler.ScheduledTask>
TownTask(T task) Registers a native Paper task with this command's module lifetime.protected net.kyori.adventure.text.ComponentReturns the standard no-permission message for this command's permission node.protected net.kyori.adventure.text.ComponentpermissionMessage(String permission) Returns the standard no-permission message for a permission node.protected List<org.bukkit.entity.Player> resolveTargets(org.bukkit.command.CommandSender sender, @Nullable String name, String othersPermission) Resolves an optional target argument to online players.protected voidSends a message with legacy ampersand color codes to an audience.protected voidsend(net.kyori.adventure.audience.Audience audience, net.kyori.adventure.text.Component component) Sends a component to an audience.protected booleansendPlayerLookupFailure(org.bukkit.command.CommandSender sender, Throwable failure) protected booleansilentCheckPermission(org.bukkit.command.CommandSender sender, String permission) Checks whether a sender has a permission node without throwing an exception.protected Stringstring(com.mojang.brigadier.context.CommandContext<io.papermc.paper.command.brigadier.CommandSourceStack> context, String name) protected CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> suggestMatching(com.mojang.brigadier.suggestion.SuggestionsBuilder builder, Collection<String> values) Suggests matching values using Brigadier's current argument prefix.protected com.mojang.brigadier.builder.RequiredArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack, String> targetArgument(String name, String othersPermission) Creates an optional target argument.protected org.bukkit.plugin.PluginReturns the Paper plugin that owns native tasks scheduled by this command.protected net.kyori.adventure.text.Componentusage()Returns this command's formatted usage component.protected net.kyori.adventure.text.ComponentFormats command usage text with the standard usage prefix.protected com.mojang.brigadier.builder.RequiredArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack, String> Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PlexCommand
getAliases, getDescription, getName, getPermission, getRequiredSource, getUsage
-
Field Details
-
ALL_TARGETS
-
-
Constructor Details
-
SimplePlexCommand
Creates a command from a command definition.- Parameters:
commandSpec- command definition
-
-
Method Details
-
command
Starts a command spec builder for the given command name.- Parameters:
name- primary command name- Returns:
- command spec builder
-
commandSpec
Description copied from interface:PlexCommandReturns the command definition.- Specified by:
commandSpecin interfacePlexCommand- Returns:
- command definition
-
bindApi
Description copied from interface:PlexCommandSupplies the running Plex API to commands that need API helpers.The default implementation does not store the API.
- Specified by:
bindApiin interfacePlexCommand- Parameters:
api- running Plex API
-
bindModule
Description copied from interface:PlexCommandSupplies the owning module to commands that need module-owned resources.- Specified by:
bindModulein interfacePlexCommand- Parameters:
module- owning module
-
buildCommand
public final com.mojang.brigadier.tree.LiteralCommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> buildCommand()Description copied from interface:PlexCommandBuilds the Brigadier command tree for this command.- Specified by:
buildCommandin interfacePlexCommand- Returns:
- root literal command node
-
configureCommand
protected abstract void configureCommand(com.mojang.brigadier.builder.LiteralArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack> command) Configures this command's typed Brigadier tree. -
word
-
greedyString
-
string
-
suggestMatching
protected CompletableFuture<com.mojang.brigadier.suggestion.Suggestions> suggestMatching(com.mojang.brigadier.suggestion.SuggestionsBuilder builder, Collection<String> values) Suggests matching values using Brigadier's current argument prefix. -
executeCommand
protected int executeCommand(com.mojang.brigadier.context.CommandContext<io.papermc.paper.command.brigadier.CommandSourceStack> context, BiFunction<org.bukkit.command.CommandSender, org.bukkit.entity.Player, net.kyori.adventure.text.Component> execution) -
api
Returns the bound Plex API.- Returns:
- bound Plex API
- Throws:
IllegalStateException- when the command has not been bound to the API
-
taskOwner
protected org.bukkit.plugin.Plugin taskOwner()Returns the Paper plugin that owns native tasks scheduled by this command. -
ownTask
@Nullable protected <T extends io.papermc.paper.threadedregions.scheduler.ScheduledTask> T ownTask(@Nullable T task) Registers a native Paper task with this command's module lifetime. -
send
Sends a message with legacy ampersand color codes to an audience.- Parameters:
audience- message recipientmessage- legacy message text
-
send
protected void send(net.kyori.adventure.audience.Audience audience, net.kyori.adventure.text.Component component) Sends a component to an audience.- Parameters:
audience- message recipientcomponent- component to send
-
broadcast
Broadcasts a MiniMessage-formatted message.- Parameters:
miniMessage- MiniMessage-formatted message
-
broadcast
protected void broadcast(net.kyori.adventure.text.Component component) Broadcasts a component.- Parameters:
component- component to broadcast
-
checkPermission
Checks whether a sender has a permission node.- Parameters:
sender- command senderpermission- permission node to check- Returns:
truewhen the sender can use the permission- Throws:
CommandFailException- when the sender lacks the permission
-
silentCheckPermission
Checks whether a sender has a permission node without throwing an exception.- Parameters:
sender- command senderpermission- permission node to check- Returns:
truewhen the sender can use the permission
-
permissionMessage
protected net.kyori.adventure.text.Component permissionMessage()Returns the standard no-permission message for this command's permission node.- Returns:
- no-permission component
-
permissionMessage
Returns the standard no-permission message for a permission node.- Parameters:
permission- permission node- Returns:
- no-permission component
-
getUUID
Returns a sender's UUID when the sender is a player.- Parameters:
sender- command sender- Returns:
- player UUID, or
nullfor non-player senders
-
isConsole
protected boolean isConsole(org.bukkit.command.CommandSender sender) Returns whether a sender is not a player.- Parameters:
sender- command sender- Returns:
truewhen the sender is not a player
-
messageComponent
protected net.kyori.adventure.text.Component messageComponent(String key, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... placeholders) Resolves a configured message as a component.- Parameters:
key- message keyplaceholders- named replacement values- Returns:
- resolved message component
-
messageString
-
usage
protected net.kyori.adventure.text.Component usage()Returns this command's formatted usage component.- Returns:
- formatted usage component
-
usage
Formats command usage text with the standard usage prefix.- Parameters:
usage- usage text- Returns:
- formatted usage component
-
getNonNullPlayer
Returns an online player by UUID string or name.- Parameters:
name- UUID string or player name- Returns:
- matching online player
- Throws:
PlayerNotFoundException- when no matching online player exists
-
targetArgument
protected com.mojang.brigadier.builder.RequiredArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack, String> targetArgument(String name, String othersPermission) Creates an optional target argument. A sender with the permission sees every online name and-a; another sender sees only their own name.- Parameters:
name- argument nameothersPermission- permission node for a target other than the sender- Returns:
- target argument builder
-
resolveTargets
protected List<org.bukkit.entity.Player> resolveTargets(org.bukkit.command.CommandSender sender, @Nullable @Nullable String name, String othersPermission) Resolves an optional target argument to online players.- Parameters:
sender- command sendername- player name, UUID string,-afor every online player, ornullfor the senderothersPermission- permission node for a target other than the sender- Returns:
- target players
- Throws:
ConsoleMustDefinePlayerException- when the console gives no targetPlayerNotFoundException- when no matching online player existsCommandFailException- when the sender lacks the permission
-
onlinePlayerNames
-
componentFromString
Converts text with legacy ampersand color codes to a component. Uses gray when no color is set.- Parameters:
value- legacy text- Returns:
- message component
-
noColorComponentFromString
Converts text with legacy ampersand color codes to a component without adding a default color.- Parameters:
value- legacy text- Returns:
- message component
-
mmString
Converts MiniMessage-formatted text to a component.- Parameters:
value- MiniMessage-formatted text- Returns:
- message component
-
sendPlayerLookupFailure
protected boolean sendPlayerLookupFailure(org.bukkit.command.CommandSender sender, Throwable failure)
-