Class PixelmonCommandUtils
java.lang.Object
com.pixelmonmod.pixelmon.api.command.PixelmonCommandUtils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
applySpecs
(Pokemon pokemon, String[] specList) Applies a list of specs to a specified pokemonstatic boolean
doesStringStartWith
(String original, String region) Checks if the original begins with region ignoring casestatic void
endCommand
(String message, Object... data) Terminates the command with a messagestatic com.mojang.authlib.GameProfile
findProfile
(String username) Finds the game profile of the player with the given username.static net.minecraft.network.chat.MutableComponent
Translates the lang toMutableComponent
using GRAY colorstatic net.minecraft.network.chat.MutableComponent
Converts the language file link to the convertedMutableComponent
with the given colorstatic 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 convertedMutableComponent
with the given colorstatic net.minecraft.network.chat.MutableComponent
Converts the language file link to the convertedMutableComponent
with the given colorstatic PCStorage
getComputerStorage
(net.minecraft.server.level.ServerPlayer player) Shortcut call toStorageManager.getPCForPlayer(ServerPlayer)
static net.minecraft.server.level.ServerPlayer
getEntityPlayer
(String username) Gets theServerPlayer
if they are online else returns nullstatic net.minecraft.server.level.ServerPlayer
getEntityPlayer
(UUID uuid) Gets theServerPlayer
if they are online else returns nullstatic net.minecraft.commands.arguments.selector.EntitySelector
getEntitySelector
(String username) static net.minecraft.commands.CommandRuntimeException
getException
(String translation, Object... data) Gets the exception for the translation and the data to be given to the translationstatic 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 translationstatic PlayerPartyStorage
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
static boolean
hasPermission
(net.minecraft.commands.CommandSourceStack source, String permission) If theCommandSourceStack
is a player then it will check if they have access to the given permission Otherwise, return truestatic void
notifyCommandListener
(net.minecraft.commands.CommandSourceStack sender, PixelCommand command, int i, String translatedText, Object... values) static void
Requires the given boolean to be true otherwise the error message is thrownstatic <T> T
Requires the optional to have a value otherwise the error will be thrownstatic <T> T
Requires the object to be neither null, false or empty otherwise error message is sentstatic net.minecraft.server.level.ServerPlayer
requireEntityPlayer
(String username) 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 aCommandRuntimeException
with the given messagestatic int
requireInt
(String input, String message) Requires the input to be an Integer otherwise it will throw aCommandRuntimeException
with the given messagestatic void
sendMessage
(net.minecraft.commands.CommandSourceStack sender, String string, Object... data) Sends a gray message to the givenCommandSourceStack
.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 givenCommandSourceStack
.static void
sendMessage
(net.minecraft.commands.CommandSourceStack sender, net.minecraft.ChatFormatting color, String string, Object... data) Sends a message to the givenCommandSourceStack
.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 givenCommandSourceStack
.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 givenServerPlayer
.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.Gets a tab-complete list for Pokémon names.Gets a tab-complete list for player names.Gets a tab-complete list for world IDs.
-
Field Details
-
THREAD_POOL
-
PARTY_SLOTS
-
SPEC_REQUIREMENTS
-
REMOVE_ARGUMENT
-
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 commandnet.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
Gets theServerPlayer
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
Gets theServerPlayer
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
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 theServerPlayer
If a UUID is provided it will convert the username to aUUID
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 theUUID
Finally, if none of the above are true it will search the cache for the game profile but NOT lookup to Mojang's serversWill return null if cannot be found in cache
- Parameters:
username
- The username, UUID, or bits for the user of theGameProfile
- 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 aCommandRuntimeException
with the given message- Parameters:
input
- the string - potential integermessage
- 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 aCommandRuntimeException
with the given message- Parameters:
input
- The string - potential integermin
- The min value of the integer (inclusive)max
- The max value of the integer (inclusive)message
- The error messagedata
- 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 booleanmessage
- The error messagedata
- 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 optionalmessage
- The error messagedata
- 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 objectmessage
- The error messagedata
- 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 translatedata
- 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.Shortcut call toStorageManager.getParty(ServerPlayer)
.- Parameters:
player
- The player you're getting the party of- Returns:
- The player's party
-
getComputerStorage
Shortcut call toStorageManager.getPCForPlayer(ServerPlayer)
- Parameters:
player
- The player you're getting the PC of- Returns:
- the player's pc
-
tabCompleteUsernames
Gets a tab-complete list for player names.- Returns:
- - A list of all player names that begin with the last argument.
-
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
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
Checks if the original begins with region ignoring case- Parameters:
original
- The string to checkregion
- 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 convertedMutableComponent
with the given color- Parameters:
color
- The color of the messagelang
- The message to be translatedargs
- 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 convertedMutableComponent
with the given color- Parameters:
color
- The color of the messagelang
- The message to be translatedargs
- 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 convertedMutableComponent
with the given color- Parameters:
color
- The color of the messagelang
- The message to be translatedargs
- The args for the translation- Returns:
- Translated coloured message
-
format
Translates the lang toMutableComponent
using GRAY color- Parameters:
lang
- The message to be translatedargs
- 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 givenServerPlayer
.- Parameters:
target
- - TheServerPlayer
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 givenCommandSourceStack
.- Parameters:
sender
- - TheCommandSourceStack
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 givenCommandSourceStack
.- Parameters:
sender
- - TheCommandSourceStack
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 givenCommandSourceStack
.- Parameters:
sender
- - TheCommandSourceStack
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 givenCommandSourceStack
.- Parameters:
sender
- - TheCommandSourceStack
to send the message to.string
- - The message itself or the translation key.data
- - Any relevant translation information to substitute '%s' placeholders.
-
sendMessage
-
hasPermission
public static boolean hasPermission(net.minecraft.commands.CommandSourceStack source, String permission) If theCommandSourceStack
is a player then it will check if they have access to the given permission Otherwise, return true- Parameters:
source
- The command sourcepermission
- 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 tospecList
- the list of specs to apply to the pokemon- Throws:
net.minecraft.commands.CommandRuntimeException
-