Package me.deecaad.core.utils
Class DistanceUtil
java.lang.Object
me.deecaad.core.utils.DistanceUtil
This final utility class outlines static methods involving the visible distance around a player,
as well as methods to send packets to players so long as the packet's location is within the
player's viewing distance.
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<org.bukkit.entity.Player> getPlayersInRange(@NotNull org.bukkit.Location origin) static List<org.bukkit.entity.Player> getPlayersInRange(@NotNull org.bukkit.Location origin, double min, double max) Returns the entities withing rangestatic intgetRange()Returns the default viewing distance of worlds, defined by the vanilla minecraft server'sserver.propertiesfile.static intgetRange(@NotNull org.bukkit.World world) Returns the viewing distance of the given world.static voidsendPacket(@NotNull org.bukkit.Location origin, Object... packets) Sends the given packet to all players who can see the givenLocation.
-
Method Details
-
getRange
public static int getRange()Returns the default viewing distance of worlds, defined by the vanilla minecraft server'sserver.propertiesfile. Generally, this method should not be used. Use instead:getRange(World)- Returns:
- The non-negative viewing distance, in blocks.
-
getRange
public static int getRange(@NotNull @NotNull org.bukkit.World world) Returns the viewing distance of the given world.- Parameters:
world- Which world to pull the viewing distance from.- Returns:
- The non-negative viewing distance, in blocks.
-
getPlayersInRange
public static List<org.bukkit.entity.Player> getPlayersInRange(@NotNull @NotNull org.bukkit.Location origin) -
getPlayersInRange
public static List<org.bukkit.entity.Player> getPlayersInRange(@NotNull @NotNull org.bukkit.Location origin, double min, double max) Returns the entities withing range- Parameters:
origin- The coordinates that from where entities are takenmin- How far away from the origin must the player bemax- How close to the origin must the player be- Returns:
- The entities withing range of view distance from origin
-
sendPacket
Sends the given packet to all players who can see the givenLocation. The distance that a player can see is defined bygetRange(World).Note that sending packets with too long of a range can cause client sided performance issues. This has been a problem for a long time in the notchian server, so Spigot added entity tracking range, limiting how far the server would send clients packets. It is a good practice to limit how far away you send your packet.
Location origin = /* not shown */; Object packet = /* not shown */; int distance = Math.min(DistanceUtils.getRange(), 50); DistanceUtils.sendPacket(origin, packet, distance)- Parameters:
origin- The coordinates that the packet is being spawned at.packets- The packets to send to players in view.
-