Class SimplePlexCommand

java.lang.Object
dev.plex.command.SimplePlexCommand
All Implemented Interfaces:
PlexCommand

public abstract class SimplePlexCommand extends Object implements PlexCommand
Convenience base for module commands with typed Brigadier command trees.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
    Target token that selects every online player.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a command from a command definition.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected PlexApi
    api()
    Returns the bound Plex API.
    final void
    Supplies the running Plex API to commands that need API helpers.
    final void
    Supplies the owning module to commands that need module-owned resources.
    protected void
    broadcast(String miniMessage)
    Broadcasts a MiniMessage-formatted message.
    protected void
    broadcast(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 boolean
    checkPermission(org.bukkit.command.CommandSender sender, String permission)
    Checks whether a sender has a permission node.
    protected static CommandSpec.Builder
    Starts a command spec builder for the given command name.
    Returns the command definition.
    protected net.kyori.adventure.text.Component
    Converts text with legacy ampersand color codes to a component.
    protected abstract void
    configureCommand(com.mojang.brigadier.builder.LiteralArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack> command)
    Configures this command's typed Brigadier tree.
    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)
     
    protected org.bukkit.entity.Player
    Returns an online player by UUID string or name.
    protected @Nullable UUID
    getUUID(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>
     
    protected boolean
    isConsole(org.bukkit.command.CommandSender sender)
    Returns whether a sender is not a player.
    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.
    protected String
    Gets a raw configured MiniMessage template.
    protected net.kyori.adventure.text.Component
    Converts MiniMessage-formatted text to a component.
    protected net.kyori.adventure.text.Component
    Converts text with legacy ampersand color codes to a component without adding a default color.
    protected List<String>
    Returns the names of online players.
    protected <T extends io.papermc.paper.threadedregions.scheduler.ScheduledTask>
    T
    ownTask(T task)
    Registers a native Paper task with this command's module lifetime.
    protected net.kyori.adventure.text.Component
    Returns the standard no-permission message for this command's permission node.
    protected net.kyori.adventure.text.Component
    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 void
    send(net.kyori.adventure.audience.Audience audience, String message)
    Sends a message with legacy ampersand color codes to an audience.
    protected void
    send(net.kyori.adventure.audience.Audience audience, net.kyori.adventure.text.Component component)
    Sends a component to an audience.
    protected boolean
    sendPlayerLookupFailure(org.bukkit.command.CommandSender sender, Throwable failure)
     
    protected boolean
    silentCheckPermission(org.bukkit.command.CommandSender sender, String permission)
    Checks whether a sender has a permission node without throwing an exception.
    protected String
    string(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.Plugin
    Returns the Paper plugin that owns native tasks scheduled by this command.
    protected net.kyori.adventure.text.Component
    Returns this command's formatted usage component.
    protected net.kyori.adventure.text.Component
    usage(String usage)
    Formats command usage text with the standard usage prefix.
    protected com.mojang.brigadier.builder.RequiredArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack, String>
    word(String name)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ALL_TARGETS

      protected static final String ALL_TARGETS
      Target token that selects every online player.
      See Also:
  • Constructor Details

    • SimplePlexCommand

      protected SimplePlexCommand(CommandSpec commandSpec)
      Creates a command from a command definition.
      Parameters:
      commandSpec - command definition
  • Method Details

    • command

      protected static CommandSpec.Builder command(String name)
      Starts a command spec builder for the given command name.
      Parameters:
      name - primary command name
      Returns:
      command spec builder
    • commandSpec

      public final CommandSpec commandSpec()
      Description copied from interface: PlexCommand
      Returns the command definition.
      Specified by:
      commandSpec in interface PlexCommand
      Returns:
      command definition
    • bindApi

      public final void bindApi(PlexApi api)
      Description copied from interface: PlexCommand
      Supplies the running Plex API to commands that need API helpers.

      The default implementation does not store the API.

      Specified by:
      bindApi in interface PlexCommand
      Parameters:
      api - running Plex API
    • bindModule

      public final void bindModule(PlexModule module)
      Description copied from interface: PlexCommand
      Supplies the owning module to commands that need module-owned resources.
      Specified by:
      bindModule in interface PlexCommand
      Parameters:
      module - owning module
    • buildCommand

      public final com.mojang.brigadier.tree.LiteralCommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> buildCommand()
      Description copied from interface: PlexCommand
      Builds the Brigadier command tree for this command.
      Specified by:
      buildCommand in interface PlexCommand
      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

      protected com.mojang.brigadier.builder.RequiredArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack, String> word(String name)
    • greedyString

      protected com.mojang.brigadier.builder.RequiredArgumentBuilder<io.papermc.paper.command.brigadier.CommandSourceStack, String> greedyString(String name)
    • string

      protected String string(com.mojang.brigadier.context.CommandContext<io.papermc.paper.command.brigadier.CommandSourceStack> context, String name)
    • 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

      protected PlexApi 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

      protected void send(net.kyori.adventure.audience.Audience audience, String message)
      Sends a message with legacy ampersand color codes to an audience.
      Parameters:
      audience - message recipient
      message - 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 recipient
      component - component to send
    • broadcast

      protected void broadcast(String miniMessage)
      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

      protected boolean checkPermission(org.bukkit.command.CommandSender sender, String permission)
      Checks whether a sender has a permission node.
      Parameters:
      sender - command sender
      permission - permission node to check
      Returns:
      true when the sender can use the permission
      Throws:
      CommandFailException - when the sender lacks the permission
    • silentCheckPermission

      protected boolean silentCheckPermission(org.bukkit.command.CommandSender sender, String permission)
      Checks whether a sender has a permission node without throwing an exception.
      Parameters:
      sender - command sender
      permission - permission node to check
      Returns:
      true when 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

      protected net.kyori.adventure.text.Component permissionMessage(String permission)
      Returns the standard no-permission message for a permission node.
      Parameters:
      permission - permission node
      Returns:
      no-permission component
    • getUUID

      @Nullable protected @Nullable UUID getUUID(org.bukkit.command.CommandSender sender)
      Returns a sender's UUID when the sender is a player.
      Parameters:
      sender - command sender
      Returns:
      player UUID, or null for 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:
      true when 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 key
      placeholders - named replacement values
      Returns:
      resolved message component
    • messageString

      protected String messageString(String key)
      Gets a raw configured MiniMessage template.
      Parameters:
      key - message key
      Returns:
      raw message template
    • usage

      protected net.kyori.adventure.text.Component usage()
      Returns this command's formatted usage component.
      Returns:
      formatted usage component
    • usage

      protected net.kyori.adventure.text.Component usage(String usage)
      Formats command usage text with the standard usage prefix.
      Parameters:
      usage - usage text
      Returns:
      formatted usage component
    • getNonNullPlayer

      protected org.bukkit.entity.Player getNonNullPlayer(String name)
      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 name
      othersPermission - 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 sender
      name - player name, UUID string, -a for every online player, or null for the sender
      othersPermission - permission node for a target other than the sender
      Returns:
      target players
      Throws:
      ConsoleMustDefinePlayerException - when the console gives no target
      PlayerNotFoundException - when no matching online player exists
      CommandFailException - when the sender lacks the permission
    • onlinePlayerNames

      protected List<String> onlinePlayerNames()
      Returns the names of online players.
      Returns:
      online player names
    • componentFromString

      protected net.kyori.adventure.text.Component componentFromString(String value)
      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

      protected net.kyori.adventure.text.Component noColorComponentFromString(String value)
      Converts text with legacy ampersand color codes to a component without adding a default color.
      Parameters:
      value - legacy text
      Returns:
      message component
    • mmString

      protected net.kyori.adventure.text.Component mmString(String value)
      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)