Class SentinelUtilities

java.lang.Object
org.mcmonkey.sentinel.SentinelUtilities

public class SentinelUtilities extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Constant: The size of a buffer, 10 kilobytes.
    static final String
    Constant: name of the standard encoding to prefer (UTF-8).
    static Random
    A random object for reuse.
    Look up table for pre-compiled regex values.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    approxEquals(double a, double b)
    Returns true if "a == b" within a small epsilon margin (to compensate for Double value inaccuracies).
    static void
    broadcastToSelected(net.citizensnpcs.api.npc.NPC npc, String message)
    Broadcasts a message to the console and to any player(s) that have an NPC selected.
    static boolean
    checkLineOfSightWithTransparency(org.bukkit.entity.LivingEntity start, org.bukkit.entity.LivingEntity end)
    Does a line-of-sight check between entities, allowing for transparent blocks (like glass).
    static boolean
    checkLineOfSightWithTransparency(org.bukkit.Location start, org.bukkit.Location end)
    Does a line-of-sight check between locations, allowing for transparent blocks (like glass).
    static String
    concatWithSpaces(String[] strs, int start)
    Concatenates (combines) an array of strings with spaces in between - just a shorthand/helper method.
    static double
    getArrowAngle(org.bukkit.Location fireFrom, org.bukkit.Location fireTo, double speed, double gravity)
    Calculates the ideal angle to fire an arrow at to hit a target (roughly based on older Sentry code).
    static org.bukkit.entity.Entity
    Gets the entity for a given UUID.
    static int
    getFireProtection(org.bukkit.entity.LivingEntity entity)
    Gets the fire protection level from an entity's armor.
    static org.bukkit.inventory.ItemStack
    getHeldItem(org.bukkit.entity.LivingEntity entity)
    Returns the item held in an entity's hand.
    static String
    getItemTarget(org.bukkit.inventory.ItemStack item, List<String> targets)
    Returns the string of an item matcher that matches the item (if any).
    static AbstractMap.SimpleEntry<org.bukkit.Location,org.bukkit.util.Vector>
    getLaunchDetail(org.bukkit.Location start, org.bukkit.Location target, org.bukkit.util.Vector lead)
    Gets a 'launch detail' (starting location with direction vector set to correct firing direction, and a vector holding the exact launch vector, scaled to the correct speed).
    static int
    getMaxWorldHeight(org.bukkit.World world)
    Gets the maximum height for a world (as of 1.17 can go above 255).
    static int
    getMinWorldHeight(org.bukkit.World world)
    Gets the minimum height for a world (as of 1.17 can go below 0).
    static org.bukkit.inventory.ItemStack
    getOffhandItem(org.bukkit.entity.LivingEntity entity)
    Returns the item held in an entity's offhand.
    static float
    getPitch(org.bukkit.util.Vector vector)
    Gets the pitch angle value (in degrees) for a normalized vector.
    static String
    getRegexTarget(String name, List<String> regexes)
    Returns the string of a regex that matches the name (if any).
    static org.bukkit.entity.Entity
    getTargetFor(net.citizensnpcs.api.ai.EntityTarget targ)
    Gets the entity target referenced by a CitizensAPI EntityTarget object.
    static org.bukkit.util.Vector
    getVelocity(org.bukkit.entity.Entity entity)
    Gets the velocity for an entity.
    static float
    getYaw(org.bukkit.util.Vector vector)
    Gets the yaw angle value (in degrees) for a normalized vector.
    static double
    hangtime(double launchAngle, double vel, double deltaY, double gravity)
    Calculates the hang-time (time from shot until landing) of a projectile (roughly based on older Sentry code).
    static boolean
    isAir(org.bukkit.inventory.ItemStack its)
    Returns when an item is considered to be an air item.
    static boolean
    isInvisible(org.bukkit.entity.LivingEntity entity)
    Returns whether an entity is invisible (when invisible targets are ignorable).
    static boolean
    isItemTarget(org.bukkit.inventory.ItemStack item, List<String> targets)
    Returns whether a list of item regex values match the item.
    static boolean
    isLookingTowards(org.bukkit.Location myLoc, org.bukkit.Location theirLoc, float yawLimit, float pitchLimit)
    Returns a boolean indicating whether the first location is looking towards a second location, within a yaw and pitch limit.
    static boolean
    isRegexTarget(String name, String regex)
    Returns whether a regex value match the string.
    static boolean
    isRegexTargeted(String name, List<String> regexes)
    Returns whether a list of regex values match the string.
    static float
    normalizeYaw(float yaw)
    Normalizes Mincraft's yaws (which can be negative or can exceed 360) by turning them into proper yaw values that only go from 0 to 359.
    static org.bukkit.Location
    pickNear(org.bukkit.Location start, double range)
    Picks an accessible location near the start location, within a range.
    static double
    randomDecimal(double min, double max)
    Gets a random decimal from a minimum value to a maximum value.
    static org.bukkit.Location
    rayTrace(org.bukkit.Location start, org.bukkit.Location end)
    Traces a ray from a start to an end, returning the end of the ray (stopped early if there are solid blocks in the way).
    static Pattern
    Gets a compiled regex pattern for a string of the regex.
    static String
    Converts an input stream to a string (of the stream's contents).
    tryGetSentinel(org.bukkit.entity.Entity entity)
    Tries to get a Sentinel from an entity.
    static boolean
    Equivalent to "UUID#equals(...)" but ignoring the UUID version flag, to make NPC UUIDs (v4) and entity UUIDS (v2) of the same value be considered equivalent.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • random

      public static Random random
      A random object for reuse.
    • regexes

      public static HashMap<String,Pattern> regexes
      Look up table for pre-compiled regex values.
    • ENCODING

      public static final String ENCODING
      Constant: name of the standard encoding to prefer (UTF-8).
      See Also:
    • BUFFER_10_KB

      public static final int BUFFER_10_KB
      Constant: The size of a buffer, 10 kilobytes.
      See Also:
  • Constructor Details

    • SentinelUtilities

      public SentinelUtilities()
  • Method Details

    • getMinWorldHeight

      public static int getMinWorldHeight(org.bukkit.World world)
      Gets the minimum height for a world (as of 1.17 can go below 0).
    • getMaxWorldHeight

      public static int getMaxWorldHeight(org.bukkit.World world)
      Gets the maximum height for a world (as of 1.17 can go above 255).
    • getVelocity

      public static org.bukkit.util.Vector getVelocity(org.bukkit.entity.Entity entity)
      Gets the velocity for an entity. Uses a special tracker for players (since velocity doesn't network properly).
    • tryGetSentinel

      public static SentinelTrait tryGetSentinel(org.bukkit.entity.Entity entity)
      Tries to get a Sentinel from an entity. Returns null if it is not a Sentinel.
    • getHeldItem

      public static org.bukkit.inventory.ItemStack getHeldItem(org.bukkit.entity.LivingEntity entity)
      Returns the item held in an entity's hand.
    • getOffhandItem

      public static org.bukkit.inventory.ItemStack getOffhandItem(org.bukkit.entity.LivingEntity entity)
      Returns the item held in an entity's offhand.
    • getFireProtection

      public static int getFireProtection(org.bukkit.entity.LivingEntity entity)
      Gets the fire protection level from an entity's armor.
    • rayTrace

      public static org.bukkit.Location rayTrace(org.bukkit.Location start, org.bukkit.Location end)
      Traces a ray from a start to an end, returning the end of the ray (stopped early if there are solid blocks in the way).
    • pickNear

      public static org.bukkit.Location pickNear(org.bukkit.Location start, double range)
      Picks an accessible location near the start location, within a range.
    • regexFor

      public static Pattern regexFor(String input)
      Gets a compiled regex pattern for a string of the regex. More efficient than recompiling every-time due to lookup-table usage.
    • isRegexTarget

      public static boolean isRegexTarget(String name, String regex)
      Returns whether a regex value match the string.
    • getRegexTarget

      public static String getRegexTarget(String name, List<String> regexes)
      Returns the string of a regex that matches the name (if any).
    • getItemTarget

      public static String getItemTarget(org.bukkit.inventory.ItemStack item, List<String> targets)
      Returns the string of an item matcher that matches the item (if any).
    • isItemTarget

      public static boolean isItemTarget(org.bukkit.inventory.ItemStack item, List<String> targets)
      Returns whether a list of item regex values match the item.
    • isRegexTargeted

      public static boolean isRegexTargeted(String name, List<String> regexes)
      Returns whether a list of regex values match the string.
    • isLookingTowards

      public static boolean isLookingTowards(org.bukkit.Location myLoc, org.bukkit.Location theirLoc, float yawLimit, float pitchLimit)
      Returns a boolean indicating whether the first location is looking towards a second location, within a yaw and pitch limit.
    • normalizeYaw

      public static float normalizeYaw(float yaw)
      Normalizes Mincraft's yaws (which can be negative or can exceed 360) by turning them into proper yaw values that only go from 0 to 359.
    • getPitch

      public static float getPitch(org.bukkit.util.Vector vector)
      Gets the pitch angle value (in degrees) for a normalized vector.
    • getYaw

      public static float getYaw(org.bukkit.util.Vector vector)
      Gets the yaw angle value (in degrees) for a normalized vector.
    • randomDecimal

      public static double randomDecimal(double min, double max)
      Gets a random decimal from a minimum value to a maximum value.
    • isAir

      public static boolean isAir(org.bukkit.inventory.ItemStack its)
      Returns when an item is considered to be an air item.
    • getEntityForID

      public static org.bukkit.entity.Entity getEntityForID(UUID id)
      Gets the entity for a given UUID.
    • isInvisible

      public static boolean isInvisible(org.bukkit.entity.LivingEntity entity)
      Returns whether an entity is invisible (when invisible targets are ignorable).
    • getTargetFor

      public static org.bukkit.entity.Entity getTargetFor(net.citizensnpcs.api.ai.EntityTarget targ)
      Gets the entity target referenced by a CitizensAPI EntityTarget object. Should never return null except in error cases.
    • getLaunchDetail

      public static AbstractMap.SimpleEntry<org.bukkit.Location,org.bukkit.util.Vector> getLaunchDetail(org.bukkit.Location start, org.bukkit.Location target, org.bukkit.util.Vector lead)
      Gets a 'launch detail' (starting location with direction vector set to correct firing direction, and a vector holding the exact launch vector, scaled to the correct speed).
    • getArrowAngle

      public static double getArrowAngle(org.bukkit.Location fireFrom, org.bukkit.Location fireTo, double speed, double gravity)
      Calculates the ideal angle to fire an arrow at to hit a target (roughly based on older Sentry code). Can return Double.NEGATIVE_INFINITY when hitting the target is impossible.
    • hangtime

      public static double hangtime(double launchAngle, double vel, double deltaY, double gravity)
      Calculates the hang-time (time from shot until landing) of a projectile (roughly based on older Sentry code).
    • concatWithSpaces

      public static String concatWithSpaces(String[] strs, int start)
      Concatenates (combines) an array of strings with spaces in between - just a shorthand/helper method.
    • streamToString

      public static String streamToString(InputStream is)
      Converts an input stream to a string (of the stream's contents). This only needs to exist because Java inexplicably has no easy native way to accomplish this.
    • checkLineOfSightWithTransparency

      public static boolean checkLineOfSightWithTransparency(org.bukkit.entity.LivingEntity start, org.bukkit.entity.LivingEntity end)
      Does a line-of-sight check between entities, allowing for transparent blocks (like glass).
    • checkLineOfSightWithTransparency

      public static boolean checkLineOfSightWithTransparency(org.bukkit.Location start, org.bukkit.Location end)
      Does a line-of-sight check between locations, allowing for transparent blocks (like glass).
    • approxEquals

      public static boolean approxEquals(double a, double b)
      Returns true if "a == b" within a small epsilon margin (to compensate for Double value inaccuracies).
    • broadcastToSelected

      public static void broadcastToSelected(net.citizensnpcs.api.npc.NPC npc, String message)
      Broadcasts a message to the console and to any player(s) that have an NPC selected.
    • uuidEquals

      public static boolean uuidEquals(UUID a, UUID b)
      Equivalent to "UUID#equals(...)" but ignoring the UUID version flag, to make NPC UUIDs (v4) and entity UUIDS (v2) of the same value be considered equivalent.