Package net.glowstone.command
Class CommandUtils
java.lang.Object
net.glowstone.command.CommandUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.bukkit.LocationgetLocation(org.bukkit.command.CommandSender sender) Gets the location that is "~ ~ ~" for a command sender.static org.bukkit.LocationgetLocation(org.bukkit.command.CommandSender sender, String x, String y, String z) Parses coordinates that may be absolute or relative.static org.bukkit.LocationgetLocation(org.bukkit.Location location, String relativeX, String relativeY, String relativeZ) Gets the relative location based on the given axis values (x/y/z) based on tilde notation.static StringgetName(org.bukkit.command.CommandSender sender) Gets the name of a command sender.static StringgetName(org.bukkit.entity.Entity entity) Gets the name of an entity.static org.bukkit.LocationgetRotation(org.bukkit.Location location, String yawRelative, String pitchRelative) Gets the relative location based on the given rotation values (yaw/relative) based on tilde notation.static GlowWorldgetWorld(org.bukkit.command.CommandSender sender) Returns the world that the given command sender is referring to when not specifying one.static booleanisPhysical(org.bukkit.command.CommandSender sender) static BlockStateDataParses a block state from a string.static StringtoNamespaced(String input) Returns the input unchanged if it already has a namespace prefix; otherwise, adds theNamespacedKey.MINECRAFTprefix.
-
Method Details
-
readState
public static BlockStateData readState(org.bukkit.command.CommandSender sender, org.bukkit.Material type, String state) Parses a block state from a string.- Parameters:
sender- the target who should receive an error message ifstateis invalidtype- the block typestate- a string specifying a block state- Returns:
- the block state for
typeandstate, or null if none match
-
getWorld
Returns the world that the given command sender is referring to when not specifying one.- Parameters:
sender- a command sender- Returns:
- the command sender's world if the sender is a block or entity, or the default world otherwise
-
getLocation
public static org.bukkit.Location getLocation(org.bukkit.command.CommandSender sender) Gets the location that is "~ ~ ~" for a command sender.- Parameters:
sender- a command sender- Returns:
- the sender's location if the sender is a block or entity, or the default world's coordinate origin otherwise.
-
getLocation
public static org.bukkit.Location getLocation(org.bukkit.command.CommandSender sender, String x, String y, String z) Parses coordinates that may be absolute or relative.- Parameters:
sender- the command senderx- the x coordinate specifiery- the y coordinate specifierz- the z coordinate specifier- Returns:
- the coordinates
-
getLocation
public static org.bukkit.Location getLocation(org.bukkit.Location location, String relativeX, String relativeY, String relativeZ) Gets the relative location based on the given axis values (x/y/z) based on tilde notation.
For instance, using axis values of ~10 ~ ~15 will return the location with the offset of the given rotation values.
- Parameters:
location- the initial locationrelativeX- the relative x-axis (if there is no tilde [~], then the literal value is used)relativeY- the relative y-axis (if there is no tilde [~], then the literal value is used)relativeZ- the relative z-axis (if there is no tilde [~], then the literal value is used)- Returns:
- the relative location
-
getRotation
public static org.bukkit.Location getRotation(org.bukkit.Location location, String yawRelative, String pitchRelative) Gets the relative location based on the given rotation values (yaw/relative) based on tilde notation.
For instance, using rotations of ~10 ~15 will return the location with the offset of the given rotation values.
- Parameters:
location- the initial locationyawRelative- the relative yaw (if there is no tilde [~], then the literal value is used)pitchRelative- the relative pitch (if there is no tilde [~], then the literal value is used)- Returns:
- the relative location
-
getName
Gets the name of a command sender.- Parameters:
sender- the sender- Returns:
- the sender's name
-
getName
Gets the name of an entity.- Parameters:
entity- an entity- Returns:
- the first of the following that exists and is non-empty:
entity.getCustomName(),entity.getName(),entity.getType().getName()
-
isPhysical
public static boolean isPhysical(org.bukkit.command.CommandSender sender) -
toNamespaced
Returns the input unchanged if it already has a namespace prefix; otherwise, adds theNamespacedKey.MINECRAFTprefix.- Parameters:
input- a namespaced-key name, or prefix of one, that may or may not be namespaced- Returns:
- the input, namespaced
-