Class PixelmonCommandUtils
java.lang.Object
com.pixelmonmod.pixelmon.api.command.PixelmonCommandUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplySpecs(Pokemon pokemon, String[] specList) Applies a list of specs to a specified pokemonstatic booleandoesStringStartWith(String original, String region) Checks if the original begins with region ignoring casestatic voidendCommand(String message, Object... data) Terminates the command with a messagestatic com.mojang.authlib.GameProfilefindProfile(String username) Finds the game profile of the player with the given username.static net.minecraft.network.chat.MutableComponentTranslates the lang toMutableComponentusing GRAY colorstatic net.minecraft.network.chat.MutableComponentConverts the language file link to the convertedMutableComponentwith the given colorstatic net.minecraft.network.chat.MutableComponentformat(net.minecraft.ChatFormatting color, String lang, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... args) Converts the language file link to the convertedMutableComponentwith the given colorstatic net.minecraft.network.chat.MutableComponentConverts the language file link to the convertedMutableComponentwith the given colorstatic PCStoragegetComputerStorage(net.minecraft.server.level.ServerPlayer player) Shortcut call toStorageManager.getPCForPlayer(ServerPlayer)static net.minecraft.server.level.ServerPlayergetEntityPlayer(String username) Gets theServerPlayerif they are online else returns nullstatic net.minecraft.server.level.ServerPlayergetEntityPlayer(UUID uuid) Gets theServerPlayerif they are online else returns nullstatic net.minecraft.commands.arguments.selector.EntitySelectorgetEntitySelector(String username) static com.mojang.brigadier.exceptions.CommandSyntaxExceptiongetException(String translation, Object... data) Gets the exception for the translation and the data to be given to the translationstatic com.mojang.brigadier.exceptions.CommandSyntaxExceptiongetException(net.minecraft.network.chat.MutableComponent translation) Gets the exception for the translation and the data to be given to the translationstatic PlayerPartyStoragegetPlayerStorage(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.ServerLevelstatic booleanhasPermission(net.minecraft.commands.CommandSourceStack source, String permission) If theCommandSourceStackis a player then it will check if they have access to the given permission Otherwise, return truestatic voidnotifyCommandListener(net.minecraft.commands.CommandSourceStack sender, PixelCommand command, int i, String translatedText, Object... values) static voidRequires the given boolean to be true otherwise the error message is thrownstatic <T> TRequires the optional to have a value otherwise the error will be thrownstatic <T> TRequires the object to be neither null, false or empty otherwise error message is sentstatic net.minecraft.server.level.ServerPlayerrequireEntityPlayer(String username) Checks if the user is online.static net.minecraft.server.level.ServerPlayerrequireEntityPlayer(net.minecraft.commands.CommandSourceStack source) static intrequireInt(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 aCommandSyntaxExceptionwith the given messagestatic intrequireInt(String input, String message) Requires the input to be an Integer otherwise it will throw aCommandSyntaxExceptionwith the given messagestatic voidsendMessage(net.minecraft.commands.CommandSourceStack sender, String string, Object... data) Sends a gray message to the givenCommandSourceStack.static voidsendMessage(net.minecraft.commands.CommandSourceStack sender, String string, Consumer<net.minecraft.network.chat.MutableComponent> formatting, Object... data) Sends a gray message to the givenCommandSourceStack.static voidsendMessage(net.minecraft.commands.CommandSourceStack sender, net.minecraft.ChatFormatting color, String string, Object... data) Sends a message to the givenCommandSourceStack.static voidsendMessage(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 voidsendMessage(net.minecraft.server.level.ServerPlayer sender, String string, Object... data) static voidsendMessage(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 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
-
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 com.mojang.brigadier.exceptions.CommandSyntaxException 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:
com.mojang.brigadier.exceptions.CommandSyntaxException- 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 com.mojang.brigadier.exceptions.CommandSyntaxException - Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException
-
getEntityPlayer
Gets theServerPlayerif they are online else returns null- Parameters:
username- The username or uuid string to lookup- Returns:
ServerPlayeror null if they are not online- Throws:
IllegalArgumentException- if we cant parse the UUID
-
getEntityPlayer
Gets theServerPlayerif they are online else returns null- Parameters:
uuid- The uuid of the player to lookup- Returns:
ServerPlayeror 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 theServerPlayerIf a UUID is provided it will convert the username to aUUIDand 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 theUUIDFinally, 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:
GameProfileof the user
-
requireInt
public static int requireInt(String input, String message) throws com.mojang.brigadier.exceptions.CommandSyntaxException Requires the input to be an Integer otherwise it will throw aCommandSyntaxExceptionwith the given message- Parameters:
input- the string - potential integermessage- the error message- Returns:
- The integer found
- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- Thrown if string isn't an integer
-
requireInt
public static int requireInt(String input, int min, int max, String message, Object... data) throws com.mojang.brigadier.exceptions.CommandSyntaxException Requires the input to be an Integer within the min and max boundsotherwise it will throw aCommandSyntaxExceptionwith 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:
com.mojang.brigadier.exceptions.CommandSyntaxException- Thrown if the string isn't an integer
-
require
public static void require(boolean boo, String message, Object... data) throws com.mojang.brigadier.exceptions.CommandSyntaxException 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:
com.mojang.brigadier.exceptions.CommandSyntaxException- Thrown if boo is false
-
require
@Nonnull public static <T> T require(Optional<T> optional, String message, Object... data) throws com.mojang.brigadier.exceptions.CommandSyntaxException 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:
com.mojang.brigadier.exceptions.CommandSyntaxException- The error thrown if the optional isn't present
-
require
@Nonnull public static <T> T require(T obj, String message, Object... data) throws com.mojang.brigadier.exceptions.CommandSyntaxException 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:
com.mojang.brigadier.exceptions.CommandSyntaxException- Thrown if any of the initial conditions are not met
-
endCommand
public static void endCommand(String message, Object... data) throws com.mojang.brigadier.exceptions.CommandSyntaxException Terminates the command with a message- Parameters:
message- The message to send to the player.- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- 99.9% of the time.
-
getException
public static com.mojang.brigadier.exceptions.CommandSyntaxException 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 com.mojang.brigadier.exceptions.CommandSyntaxException 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 convertedMutableComponentwith 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 convertedMutableComponentwith 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 convertedMutableComponentwith 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 toMutableComponentusing 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- - TheServerPlayerto 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- - TheCommandSourceStackto 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- - TheCommandSourceStackto 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- - TheCommandSourceStackto 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- - TheCommandSourceStackto 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 theCommandSourceStackis 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 com.mojang.brigadier.exceptions.CommandSyntaxException 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:
com.mojang.brigadier.exceptions.CommandSyntaxException
-