Class CommandUtils

java.lang.Object
net.glowstone.command.CommandUtils

public class CommandUtils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.Location
    getLocation(org.bukkit.command.CommandSender sender)
    Gets the location that is "~ ~ ~" for a command sender.
    static org.bukkit.Location
    getLocation(org.bukkit.command.CommandSender sender, String x, String y, String z)
    Parses coordinates that may be absolute or relative.
    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.
    static String
    getName(org.bukkit.command.CommandSender sender)
    Gets the name of a command sender.
    static String
    getName(org.bukkit.entity.Entity entity)
    Gets the name of an entity.
    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.
    static GlowWorld
    getWorld(org.bukkit.command.CommandSender sender)
    Returns the world that the given command sender is referring to when not specifying one.
    static boolean
    isPhysical(org.bukkit.command.CommandSender sender)
     
    readState(org.bukkit.command.CommandSender sender, org.bukkit.Material type, String state)
    Parses a block state from a string.
    static String
    Returns the input unchanged if it already has a namespace prefix; otherwise, adds the NamespacedKey.MINECRAFT prefix.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 if state is invalid
      type - the block type
      state - a string specifying a block state
      Returns:
      the block state for type and state, or null if none match
    • getWorld

      public static GlowWorld getWorld(org.bukkit.command.CommandSender sender)
      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 sender
      x - the x coordinate specifier
      y - the y coordinate specifier
      z - 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 location
      relativeX - 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 location
      yawRelative - 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

      public static String getName(org.bukkit.command.CommandSender sender)
      Gets the name of a command sender.
      Parameters:
      sender - the sender
      Returns:
      the sender's name
    • getName

      public static String getName(org.bukkit.entity.Entity entity)
      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

      public static String toNamespaced(String input)
      Returns the input unchanged if it already has a namespace prefix; otherwise, adds the NamespacedKey.MINECRAFT prefix.
      Parameters:
      input - a namespaced-key name, or prefix of one, that may or may not be namespaced
      Returns:
      the input, namespaced