public class PixelmonCommandUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.List<java.lang.String> |
PARTY_SLOTS |
static java.util.List<java.lang.String> |
REMOVE_ARGUMENT |
static java.util.List<java.lang.String> |
SPEC_REQUIREMENTS |
static java.util.List<java.lang.String> |
TARGET_SELECTORS |
static ThreadPool |
THREAD_POOL |
Constructor and Description |
---|
PixelmonCommandUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
applySpecs(Pokemon pokemon,
java.lang.String[] specList)
Applies a list of specs to a specified pokemon
|
static boolean |
doesStringStartWith(java.lang.String original,
java.lang.String region)
Checks if the original begins with region ignoring case
|
static void |
endCommand(java.lang.String message,
java.lang.Object... data)
Terminates the command with a message
|
static com.mojang.authlib.GameProfile |
findProfile(java.lang.String username)
Finds the game profile of the player with the given username.
|
static net.minecraft.util.text.IFormattableTextComponent |
format(net.minecraft.util.text.Color color,
java.lang.String lang,
java.lang.Object... args)
Converts the language file link to the converted
IFormattableTextComponent with the given
color |
static net.minecraft.util.text.IFormattableTextComponent |
format(java.lang.String lang,
java.lang.Object... args)
Translates the lang to
IFormattableTextComponent using GRAY color |
static net.minecraft.util.text.IFormattableTextComponent |
format(net.minecraft.util.text.TextFormatting color,
java.lang.String lang,
java.util.function.Consumer<net.minecraft.util.text.IFormattableTextComponent> formatting,
java.lang.Object... args)
Converts the language file link to the converted
IFormattableTextComponent with the given
color |
static net.minecraft.util.text.IFormattableTextComponent |
format(net.minecraft.util.text.TextFormatting color,
java.lang.String lang,
java.lang.Object... args)
Converts the language file link to the converted
IFormattableTextComponent with the given
color |
static PCStorage |
getComputerStorage(net.minecraft.entity.player.ServerPlayerEntity player)
Shortcut call to
StorageManager.getPCForPlayer(ServerPlayerEntity) |
static net.minecraft.entity.player.ServerPlayerEntity |
getEntityPlayer(java.lang.String username)
Gets the
ServerPlayerEntity if they are online else returns null |
static net.minecraft.entity.player.ServerPlayerEntity |
getEntityPlayer(java.util.UUID uuid)
Gets the
ServerPlayerEntity if they are online else returns null |
static net.minecraft.command.arguments.EntitySelector |
getEntitySelector(java.lang.String username) |
static net.minecraft.command.CommandException |
getException(net.minecraft.util.text.IFormattableTextComponent translation)
Gets the exception for the translation and the data to be given to the translation
|
static net.minecraft.command.CommandException |
getException(java.lang.String translation,
java.lang.Object... data)
Gets the exception for the translation and the data to be given to the translation
|
static PlayerPartyStorage |
getPlayerStorage(net.minecraft.entity.player.ServerPlayerEntity player)
Shortcut call to
StorageManager.getParty(ServerPlayerEntity) . |
static net.minecraft.world.server.ServerWorld |
getWorld(java.lang.String[] args,
net.minecraft.command.CommandSource sender) |
static boolean |
hasPermission(net.minecraft.command.CommandSource source,
java.lang.String permission)
If the
CommandSource is a player then it will check if they have access to the given permission
Otherwise, return true |
static void |
notifyCommandListener(net.minecraft.command.CommandSource sender,
PixelCommand command,
int i,
java.lang.String translatedText,
java.lang.Object... values) |
static void |
require(boolean boo,
java.lang.String message,
java.lang.Object... data)
Requires the given boolean to be true otherwise the error message is thrown
|
static <T> T |
require(java.util.Optional<T> optional,
java.lang.String message,
java.lang.Object... data)
Requires the optional to have a value otherwise the error will be thrown
|
static <T> T |
require(T obj,
java.lang.String message,
java.lang.Object... data)
Requires the object to be neither null, false or empty otherwise error message is sent
|
static net.minecraft.entity.player.ServerPlayerEntity |
requireEntityPlayer(net.minecraft.command.CommandSource source) |
static net.minecraft.entity.player.ServerPlayerEntity |
requireEntityPlayer(java.lang.String username)
Checks if the user is online.
|
static int |
requireInt(java.lang.String input,
int min,
int max,
java.lang.String message,
java.lang.Object... data)
Requires the input to be an Integer within the min and max boundsotherwise it will throw a
CommandException with the given message |
static int |
requireInt(java.lang.String input,
java.lang.String message)
Requires the input to be an Integer otherwise it will throw a
CommandException with the given message |
static void |
sendMessage(net.minecraft.command.CommandSource sender,
java.lang.String string,
java.util.function.Consumer<net.minecraft.util.text.IFormattableTextComponent> formatting,
java.lang.Object... data)
Sends a gray message to the given
CommandSource . |
static void |
sendMessage(net.minecraft.command.CommandSource sender,
java.lang.String string,
java.lang.Object... data)
Sends a gray message to the given
CommandSource . |
static void |
sendMessage(net.minecraft.command.CommandSource sender,
net.minecraft.util.text.TextFormatting color,
java.lang.String string,
java.util.function.Consumer<net.minecraft.util.text.IFormattableTextComponent> formatting,
java.lang.Object... data)
Sends a message to the given
CommandSource . |
static void |
sendMessage(net.minecraft.command.CommandSource sender,
net.minecraft.util.text.TextFormatting color,
java.lang.String string,
java.lang.Object... data)
Sends a message to the given
CommandSource . |
static void |
sendMessage(net.minecraft.entity.player.ServerPlayerEntity sender,
java.lang.String string,
java.lang.Object... data) |
static void |
sendMessage(net.minecraft.entity.player.ServerPlayerEntity target,
net.minecraft.util.text.TextFormatting color,
java.lang.String string,
java.lang.Object... data)
Sends a message to the given
ServerPlayerEntity . |
static java.lang.String[] |
setupCommandTargets(PixelCommand command,
net.minecraft.command.CommandSource sender,
java.lang.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 java.util.List<java.lang.String> |
tabCompletePokemon()
Gets a tab-complete list for Pokémon names.
|
static java.util.List<java.lang.String> |
tabCompleteUsernames()
Gets a tab-complete list for player names.
|
static java.util.List<java.lang.String> |
tabCompleteWorld()
Gets a tab-complete list for world IDs.
|
public static final ThreadPool THREAD_POOL
public static final java.util.List<java.lang.String> PARTY_SLOTS
public static final java.util.List<java.lang.String> SPEC_REQUIREMENTS
public static final java.util.List<java.lang.String> REMOVE_ARGUMENT
public static final java.util.List<java.lang.String> TARGET_SELECTORS
public static void notifyCommandListener(net.minecraft.command.CommandSource sender, PixelCommand command, int i, java.lang.String translatedText, java.lang.Object... values)
public static java.lang.String[] setupCommandTargets(PixelCommand command, net.minecraft.command.CommandSource sender, java.lang.String[] args, int playerIndex) throws net.minecraft.command.CommandException, com.mojang.brigadier.exceptions.CommandSyntaxException
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.com.mojang.brigadier.exceptions.CommandSyntaxException
- default possible exception when executing a commandnet.minecraft.command.CommandException
public static net.minecraft.command.arguments.EntitySelector getEntitySelector(java.lang.String username) throws com.mojang.brigadier.exceptions.CommandSyntaxException
com.mojang.brigadier.exceptions.CommandSyntaxException
@Nonnull public static net.minecraft.entity.player.ServerPlayerEntity requireEntityPlayer(java.lang.String username) throws net.minecraft.command.CommandException
username
- The username or uuid string to check.ServerPlayerEntity
net.minecraft.command.CommandException
- if the player is not online or cant be found.public static net.minecraft.entity.player.ServerPlayerEntity requireEntityPlayer(net.minecraft.command.CommandSource source) throws net.minecraft.command.CommandException
net.minecraft.command.CommandException
@Nullable public static net.minecraft.entity.player.ServerPlayerEntity getEntityPlayer(java.lang.String username)
ServerPlayerEntity
if they are online else returns nullusername
- The username or uuid string to lookupServerPlayerEntity
or null if they are not onlinejava.lang.IllegalArgumentException
- if we cant parse the UUIDpublic static net.minecraft.entity.player.ServerPlayerEntity getEntityPlayer(java.util.UUID uuid)
ServerPlayerEntity
if they are online else returns nulluuid
- The uuid of the player to lookupServerPlayerEntity
or null if they are not onlinepublic static com.mojang.authlib.GameProfile findProfile(java.lang.String username)
ServerPlayerEntity
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
username
- The username, UUID, or bits for the user of the GameProfile
GameProfile
of the userpublic static int requireInt(java.lang.String input, java.lang.String message) throws net.minecraft.command.CommandException
CommandException
with the given messageinput
- the string - potential integermessage
- the error messagenet.minecraft.command.CommandException
- Thrown if string isn't an integerpublic static int requireInt(java.lang.String input, int min, int max, java.lang.String message, java.lang.Object... data) throws net.minecraft.command.CommandException
CommandException
with the given messageinput
- 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 messagenet.minecraft.command.CommandException
- Thrown if the string isn't an integerpublic static void require(boolean boo, java.lang.String message, java.lang.Object... data) throws net.minecraft.command.CommandException
boo
- The booleanmessage
- The error messagedata
- The args for the error messagenet.minecraft.command.CommandException
- Thrown if boo is false@Nonnull public static <T> T require(java.util.Optional<T> optional, java.lang.String message, java.lang.Object... data) throws net.minecraft.command.CommandException
T
- The type stored in the optionaloptional
- The optionalmessage
- The error messagedata
- The data for the error messagenet.minecraft.command.CommandException
- The error thrown if the optional isn't present@Nonnull public static <T> T require(T obj, java.lang.String message, java.lang.Object... data) throws net.minecraft.command.CommandException
T
- The type of the objectobj
- The objectmessage
- The error messagedata
- The data for the error message to parsenet.minecraft.command.CommandException
- Thrown if any of the initial conditions are not metpublic static void endCommand(java.lang.String message, java.lang.Object... data) throws net.minecraft.command.CommandException
message
- The message to send to the player.net.minecraft.command.CommandException
- 99.9% of the time.public static net.minecraft.command.CommandException getException(java.lang.String translation, java.lang.Object... data)
translation
- The message to translatedata
- The data to populate the placeholders withThrowable.fillInStackTrace()
returning itself (remove the stack)public static net.minecraft.command.CommandException getException(net.minecraft.util.text.IFormattableTextComponent translation)
translation
- The message to translateThrowable.fillInStackTrace()
returning itself (remove the stack)@Nullable public static PlayerPartyStorage getPlayerStorage(net.minecraft.entity.player.ServerPlayerEntity player)
StorageManager.getParty(ServerPlayerEntity)
.player
- The player you're getting the party ofpublic static PCStorage getComputerStorage(net.minecraft.entity.player.ServerPlayerEntity player)
StorageManager.getPCForPlayer(ServerPlayerEntity)
player
- The player you're getting the PC ofpublic static java.util.List<java.lang.String> tabCompleteUsernames()
public static java.util.List<java.lang.String> tabCompletePokemon()
public static java.util.List<java.lang.String> tabCompleteWorld()
public static net.minecraft.world.server.ServerWorld getWorld(java.lang.String[] args, net.minecraft.command.CommandSource sender)
public static boolean doesStringStartWith(java.lang.String original, java.lang.String region)
original
- The string to checkregion
- The potential beggingpublic static net.minecraft.util.text.IFormattableTextComponent format(net.minecraft.util.text.TextFormatting color, java.lang.String lang, java.lang.Object... args)
IFormattableTextComponent
with the given
colorcolor
- The color of the messagelang
- The message to be translatedargs
- The args for the translationpublic static net.minecraft.util.text.IFormattableTextComponent format(net.minecraft.util.text.TextFormatting color, java.lang.String lang, java.util.function.Consumer<net.minecraft.util.text.IFormattableTextComponent> formatting, java.lang.Object... args)
IFormattableTextComponent
with the given
colorcolor
- The color of the messagelang
- The message to be translatedargs
- The args for the translationpublic static net.minecraft.util.text.IFormattableTextComponent format(net.minecraft.util.text.Color color, java.lang.String lang, java.lang.Object... args)
IFormattableTextComponent
with the given
colorcolor
- The color of the messagelang
- The message to be translatedargs
- The args for the translationpublic static net.minecraft.util.text.IFormattableTextComponent format(java.lang.String lang, java.lang.Object... args)
IFormattableTextComponent
using GRAY colorlang
- The message to be translatedargs
- The args for the translationpublic static void sendMessage(net.minecraft.entity.player.ServerPlayerEntity target, net.minecraft.util.text.TextFormatting color, java.lang.String string, java.lang.Object... data)
ServerPlayerEntity
.target
- - The ServerPlayerEntity
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.public static void sendMessage(net.minecraft.command.CommandSource sender, net.minecraft.util.text.TextFormatting color, java.lang.String string, java.lang.Object... data)
CommandSource
.sender
- - The CommandSource
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.public static void sendMessage(net.minecraft.command.CommandSource sender, net.minecraft.util.text.TextFormatting color, java.lang.String string, java.util.function.Consumer<net.minecraft.util.text.IFormattableTextComponent> formatting, java.lang.Object... data)
CommandSource
.sender
- - The CommandSource
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.public static void sendMessage(net.minecraft.command.CommandSource sender, java.lang.String string, java.lang.Object... data)
CommandSource
.sender
- - The CommandSource
to send the message to.string
- - The message itself or the translation key.data
- - Any relevant translation information to substitute '%s' placeholders.public static void sendMessage(net.minecraft.command.CommandSource sender, java.lang.String string, java.util.function.Consumer<net.minecraft.util.text.IFormattableTextComponent> formatting, java.lang.Object... data)
CommandSource
.sender
- - The CommandSource
to send the message to.string
- - The message itself or the translation key.data
- - Any relevant translation information to substitute '%s' placeholders.public static void sendMessage(net.minecraft.entity.player.ServerPlayerEntity sender, java.lang.String string, java.lang.Object... data)
public static boolean hasPermission(net.minecraft.command.CommandSource source, java.lang.String permission)
CommandSource
is a player then it will check if they have access to the given permission
Otherwise, return truesource
- The command sourcepermission
- The permission to checkpublic static void applySpecs(Pokemon pokemon, java.lang.String[] specList)
pokemon
- the pokemon to apply the specList tospecList
- the list of specs to apply to the pokemon