Class PixelmonCommandUtils

java.lang.Object
com.pixelmonmod.pixelmon.api.command.PixelmonCommandUtils

public class PixelmonCommandUtils extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final List<String>
     
    static final List<String>
     
    static final List<String>
     
    static final List<String>
     
    static final ThreadPool
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    applySpecs(Pokemon pokemon, String[] specList)
    Applies a list of specs to a specified pokemon
    static boolean
    doesStringStartWith(String original, String region)
    Checks if the original begins with region ignoring case
    static void
    endCommand(String message, Object... data)
    Terminates the command with a message
    static com.mojang.authlib.GameProfile
    findProfile(String username)
    Finds the game profile of the player with the given username.
    static net.minecraft.network.chat.MutableComponent
    format(String lang, Object... args)
    Translates the lang to MutableComponent using GRAY color
    static net.minecraft.network.chat.MutableComponent
    format(net.minecraft.ChatFormatting color, String lang, Object... args)
    Converts the language file link to the converted MutableComponent with the given color
    static net.minecraft.network.chat.MutableComponent
    format(net.minecraft.ChatFormatting color, String lang, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... args)
    Converts the language file link to the converted MutableComponent with the given color
    static net.minecraft.network.chat.MutableComponent
    format(net.minecraft.network.chat.TextColor color, String lang, Object... args)
    Converts the language file link to the converted MutableComponent with the given color
    static PCStorage
    getComputerStorage(net.minecraft.server.level.ServerPlayer player)
    static net.minecraft.server.level.ServerPlayer
    Gets the ServerPlayer if they are online else returns null
    static net.minecraft.server.level.ServerPlayer
    Gets the ServerPlayer if they are online else returns null
    static net.minecraft.commands.arguments.selector.EntitySelector
     
    static net.minecraft.commands.CommandRuntimeException
    getException(String translation, Object... data)
    Gets the exception for the translation and the data to be given to the translation
    static net.minecraft.commands.CommandRuntimeException
    getException(net.minecraft.network.chat.MutableComponent translation)
    Gets the exception for the translation and the data to be given to the translation
    getPlayerStorage(net.minecraft.server.level.ServerPlayer player)
    Deprecated, for removal: This API element is subject to removal in a future version.
    static net.minecraft.server.level.ServerLevel
    getWorld(String[] args, net.minecraft.commands.CommandSourceStack sender)
     
    static boolean
    hasPermission(net.minecraft.commands.CommandSourceStack source, String permission)
    If the CommandSourceStack is a player then it will check if they have access to the given permission Otherwise, return true
    static void
    notifyCommandListener(net.minecraft.commands.CommandSourceStack sender, PixelCommand command, int i, String translatedText, Object... values)
     
    static void
    require(boolean boo, String message, Object... data)
    Requires the given boolean to be true otherwise the error message is thrown
    static <T> T
    require(Optional<T> optional, String message, Object... data)
    Requires the optional to have a value otherwise the error will be thrown
    static <T> T
    require(T obj, String message, Object... data)
    Requires the object to be neither null, false or empty otherwise error message is sent
    static net.minecraft.server.level.ServerPlayer
    Checks if the user is online.
    static net.minecraft.server.level.ServerPlayer
    requireEntityPlayer(net.minecraft.commands.CommandSourceStack source)
     
    static int
    requireInt(String input, int min, int max, String message, Object... data)
    Requires the input to be an Integer within the min and max boundsotherwise it will throw a CommandRuntimeException with the given message
    static int
    requireInt(String input, String message)
    Requires the input to be an Integer otherwise it will throw a CommandRuntimeException with the given message
    static void
    sendMessage(net.minecraft.commands.CommandSourceStack sender, String string, Object... data)
    Sends a gray message to the given CommandSourceStack.
    static void
    sendMessage(net.minecraft.commands.CommandSourceStack sender, String string, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... data)
    Sends a gray message to the given CommandSourceStack.
    static void
    sendMessage(net.minecraft.commands.CommandSourceStack sender, net.minecraft.ChatFormatting color, String string, Object... data)
    Sends a message to the given CommandSourceStack.
    static void
    sendMessage(net.minecraft.commands.CommandSourceStack sender, net.minecraft.ChatFormatting color, String string, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... data)
    Sends a message to the given CommandSourceStack.
    static void
    sendMessage(net.minecraft.server.level.ServerPlayer sender, String string, Object... data)
     
    static void
    sendMessage(net.minecraft.server.level.ServerPlayer target, net.minecraft.ChatFormatting color, String string, Object... data)
    Sends a message to the given ServerPlayer.
    static String[]
    setupCommandTargets(PixelCommand command, net.minecraft.commands.CommandSourceStack sender, String[] args, int playerIndex)
    Manage the command argument with Mojang Selectors or with putting the sender as target when the target is missing in the arguments.
    static List<String>
    Gets a tab-complete list for Pokémon names.
    static List<String>
    Gets a tab-complete list for player names.
    static List<String>
    Gets a tab-complete list for world IDs.

    Methods inherited from class java.lang.Object

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

    • THREAD_POOL

      public static final ThreadPool THREAD_POOL
    • PARTY_SLOTS

      public static final List<String> PARTY_SLOTS
    • SPEC_REQUIREMENTS

      public static final List<String> SPEC_REQUIREMENTS
    • REMOVE_ARGUMENT

      public static final List<String> REMOVE_ARGUMENT
    • TARGET_SELECTORS

      public static final List<String> TARGET_SELECTORS
  • Constructor Details

    • PixelmonCommandUtils

      public PixelmonCommandUtils()
  • Method Details

    • notifyCommandListener

      public static void notifyCommandListener(net.minecraft.commands.CommandSourceStack sender, PixelCommand command, int i, String translatedText, Object... values)
    • setupCommandTargets

      public static String[] setupCommandTargets(PixelCommand command, net.minecraft.commands.CommandSourceStack sender, String[] args, int playerIndex) throws net.minecraft.commands.CommandRuntimeException, com.mojang.brigadier.exceptions.CommandSyntaxException
      Manage the command argument with Mojang Selectors or with putting the sender as target when the target is missing in the arguments.
      Parameters:
      command - The command that the targets are being set up for.
      sender - The command executor.
      args - the command arguments.
      playerIndex - the index of the player argument in the args.
      Returns:
      the original arguments or the sender squashed inside the original args.
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException - default possible exception when executing a command
      net.minecraft.commands.CommandRuntimeException
    • getEntitySelector

      public static net.minecraft.commands.arguments.selector.EntitySelector getEntitySelector(String username) throws com.mojang.brigadier.exceptions.CommandSyntaxException
      Throws:
      com.mojang.brigadier.exceptions.CommandSyntaxException
    • requireEntityPlayer

      @Nonnull public static net.minecraft.server.level.ServerPlayer requireEntityPlayer(String username) throws net.minecraft.commands.CommandRuntimeException
      Checks if the user is online. If they are it returns the entityPlayer. If not, it throws a CommandException stating the player can not be found.
      Parameters:
      username - The username or uuid string to check.
      Returns:
      the ServerPlayer
      Throws:
      net.minecraft.commands.CommandRuntimeException - if the player is not online or cant be found.
    • requireEntityPlayer

      public static net.minecraft.server.level.ServerPlayer requireEntityPlayer(net.minecraft.commands.CommandSourceStack source) throws net.minecraft.commands.CommandRuntimeException
      Throws:
      net.minecraft.commands.CommandRuntimeException
    • getEntityPlayer

      @Nullable public static net.minecraft.server.level.ServerPlayer getEntityPlayer(String username)
      Gets the ServerPlayer if they are online else returns null
      Parameters:
      username - The username or uuid string to lookup
      Returns:
      ServerPlayer or null if they are not online
      Throws:
      IllegalArgumentException - if we cant parse the UUID
    • getEntityPlayer

      public static net.minecraft.server.level.ServerPlayer getEntityPlayer(UUID uuid)
      Gets the ServerPlayer if they are online else returns null
      Parameters:
      uuid - The uuid of the player to lookup
      Returns:
      ServerPlayer or null if they are not online
    • findProfile

      public static com.mojang.authlib.GameProfile findProfile(String username)
      Finds the game profile of the player with the given username. If the player is online then it will return the cached game profile from the ServerPlayer If a UUID is provided it will convert the username to a UUID and search the server's cache using that If it's of length 32 then it will bit shift the integer to the right by 64 to get the most significant bits and use the rest as the least significant bits of the UUID Finally, if none of the above are true it will search the cache for the game profile but NOT lookup to Mojang's servers

      Will return null if cannot be found in cache

      Parameters:
      username - The username, UUID, or bits for the user of the GameProfile
      Returns:
      GameProfile of the user
    • requireInt

      public static int requireInt(String input, String message) throws net.minecraft.commands.CommandRuntimeException
      Requires the input to be an Integer otherwise it will throw a CommandRuntimeException with the given message
      Parameters:
      input - the string - potential integer
      message - the error message
      Returns:
      The integer found
      Throws:
      net.minecraft.commands.CommandRuntimeException - Thrown if string isn't an integer
    • requireInt

      public static int requireInt(String input, int min, int max, String message, Object... data) throws net.minecraft.commands.CommandRuntimeException
      Requires the input to be an Integer within the min and max boundsotherwise it will throw a CommandRuntimeException with the given message
      Parameters:
      input - The string - potential integer
      min - The min value of the integer (inclusive)
      max - The max value of the integer (inclusive)
      message - The error message
      data - The data to fill any args in the error message
      Returns:
      The integer parsed
      Throws:
      net.minecraft.commands.CommandRuntimeException - Thrown if the string isn't an integer
    • require

      public static void require(boolean boo, String message, Object... data) throws net.minecraft.commands.CommandRuntimeException
      Requires the given boolean to be true otherwise the error message is thrown
      Parameters:
      boo - The boolean
      message - The error message
      data - The args for the error message
      Throws:
      net.minecraft.commands.CommandRuntimeException - Thrown if boo is false
    • require

      @Nonnull public static <T> T require(Optional<T> optional, String message, Object... data) throws net.minecraft.commands.CommandRuntimeException
      Requires the optional to have a value otherwise the error will be thrown
      Type Parameters:
      T - The type stored in the optional
      Parameters:
      optional - The optional
      message - The error message
      data - The data for the error message
      Returns:
      The value stored in the optional
      Throws:
      net.minecraft.commands.CommandRuntimeException - The error thrown if the optional isn't present
    • require

      @Nonnull public static <T> T require(T obj, String message, Object... data) throws net.minecraft.commands.CommandRuntimeException
      Requires the object to be neither null, false or empty otherwise error message is sent
      Type Parameters:
      T - The type of the object
      Parameters:
      obj - The object
      message - The error message
      data - The data for the error message to parse
      Returns:
      The object that is 100% not null, false or empty
      Throws:
      net.minecraft.commands.CommandRuntimeException - Thrown if any of the initial conditions are not met
    • endCommand

      public static void endCommand(String message, Object... data) throws net.minecraft.commands.CommandRuntimeException
      Terminates the command with a message
      Parameters:
      message - The message to send to the player.
      Throws:
      net.minecraft.commands.CommandRuntimeException - 99.9% of the time.
    • getException

      public static net.minecraft.commands.CommandRuntimeException getException(String translation, Object... data)
      Gets the exception for the translation and the data to be given to the translation
      Parameters:
      translation - The message to translate
      data - The data to populate the placeholders with
      Returns:
      The exception with Throwable.fillInStackTrace() returning itself (remove the stack)
    • getException

      public static net.minecraft.commands.CommandRuntimeException getException(net.minecraft.network.chat.MutableComponent translation)
      Gets the exception for the translation and the data to be given to the translation
      Parameters:
      translation - The message to translate
      Returns:
      The exception with Throwable.fillInStackTrace() returning itself (remove the stack)
    • getPlayerStorage

      @Nullable @Deprecated(forRemoval=true, since="9.2.7") public static PlayerPartyStorage getPlayerStorage(net.minecraft.server.level.ServerPlayer player)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Parameters:
      player - The player you're getting the party of
      Returns:
      The player's party
    • getComputerStorage

      public static PCStorage getComputerStorage(net.minecraft.server.level.ServerPlayer player)
      Parameters:
      player - The player you're getting the PC of
      Returns:
      the player's pc
    • tabCompleteUsernames

      public static List<String> tabCompleteUsernames()
      Gets a tab-complete list for player names.
      Returns:
      - A list of all player names that begin with the last argument.
    • tabCompletePokemon

      public static List<String> tabCompletePokemon()
      Gets a tab-complete list for Pokémon names.
      Returns:
      - A list of all Pokémon names that begin with the last argument.
    • tabCompleteWorld

      public static List<String> tabCompleteWorld()
      Gets a tab-complete list for world IDs.
      Returns:
      - A list of all world IDs that begin with the last argument.
    • getWorld

      public static net.minecraft.server.level.ServerLevel getWorld(String[] args, net.minecraft.commands.CommandSourceStack sender)
    • doesStringStartWith

      public static boolean doesStringStartWith(String original, String region)
      Checks if the original begins with region ignoring case
      Parameters:
      original - The string to check
      region - The potential begging
      Returns:
      True if matches the start
    • format

      public static net.minecraft.network.chat.MutableComponent format(net.minecraft.ChatFormatting color, String lang, Object... args)
      Converts the language file link to the converted MutableComponent with the given color
      Parameters:
      color - The color of the message
      lang - The message to be translated
      args - The args for the translation
      Returns:
      Translated coloured message
    • format

      public static net.minecraft.network.chat.MutableComponent format(net.minecraft.ChatFormatting color, String lang, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... args)
      Converts the language file link to the converted MutableComponent with the given color
      Parameters:
      color - The color of the message
      lang - The message to be translated
      args - The args for the translation
      Returns:
      Translated coloured message
    • format

      public static net.minecraft.network.chat.MutableComponent format(net.minecraft.network.chat.TextColor color, String lang, Object... args)
      Converts the language file link to the converted MutableComponent with the given color
      Parameters:
      color - The color of the message
      lang - The message to be translated
      args - The args for the translation
      Returns:
      Translated coloured message
    • format

      public static net.minecraft.network.chat.MutableComponent format(String lang, Object... args)
      Translates the lang to MutableComponent using GRAY color
      Parameters:
      lang - The message to be translated
      args - The args for the translation
      Returns:
      Translated message
    • sendMessage

      public static void sendMessage(net.minecraft.server.level.ServerPlayer target, net.minecraft.ChatFormatting color, String string, Object... data)
      Sends a message to the given ServerPlayer.
      Parameters:
      target - - The ServerPlayer to send the message to.
      color - - The color of the text.
      string - - The message itself or the translation key.
      data - - Any relevant translation information to substitute '%s' placeholders.
    • sendMessage

      public static void sendMessage(net.minecraft.commands.CommandSourceStack sender, net.minecraft.ChatFormatting color, String string, Object... data)
      Sends a message to the given CommandSourceStack.
      Parameters:
      sender - - The CommandSourceStack to send the message to.
      color - - The color of the text.
      string - - The message itself or the translation key.
      data - - Any relevant translation information to substitute '%s' placeholders.
    • sendMessage

      public static void sendMessage(net.minecraft.commands.CommandSourceStack sender, net.minecraft.ChatFormatting color, String string, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... data)
      Sends a message to the given CommandSourceStack.
      Parameters:
      sender - - The CommandSourceStack to send the message to.
      color - - The color of the text.
      string - - The message itself or the translation key.
      data - - Any relevant translation information to substitute '%s' placeholders.
    • sendMessage

      public static void sendMessage(net.minecraft.commands.CommandSourceStack sender, String string, Object... data)
      Sends a gray message to the given CommandSourceStack.
      Parameters:
      sender - - The CommandSourceStack to send the message to.
      string - - The message itself or the translation key.
      data - - Any relevant translation information to substitute '%s' placeholders.
    • sendMessage

      public static void sendMessage(net.minecraft.commands.CommandSourceStack sender, String string, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... data)
      Sends a gray message to the given CommandSourceStack.
      Parameters:
      sender - - The CommandSourceStack to send the message to.
      string - - The message itself or the translation key.
      data - - Any relevant translation information to substitute '%s' placeholders.
    • sendMessage

      public static void sendMessage(net.minecraft.server.level.ServerPlayer sender, String string, Object... data)
    • hasPermission

      public static boolean hasPermission(net.minecraft.commands.CommandSourceStack source, String permission)
      If the CommandSourceStack is a player then it will check if they have access to the given permission Otherwise, return true
      Parameters:
      source - The command source
      permission - The permission to check
      Returns:
      If they have permission
    • applySpecs

      public static void applySpecs(Pokemon pokemon, String[] specList) throws net.minecraft.commands.CommandRuntimeException
      Applies a list of specs to a specified pokemon
      Parameters:
      pokemon - the pokemon to apply the specList to
      specList - the list of specs to apply to the pokemon
      Throws:
      net.minecraft.commands.CommandRuntimeException