2019-02-23 17:17:41 +00:00
|
|
|
From ba6cfb506e1c9225c1945f2235725143c3694279 Mon Sep 17 00:00:00 2001
|
2018-06-21 01:30:09 +00:00
|
|
|
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
|
|
|
Date: Mon, 18 Jun 2018 00:41:46 -0500
|
|
|
|
Subject: [PATCH] Add "getNearbyXXX" methods to Location
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
|
2019-02-23 17:17:41 +00:00
|
|
|
index 916238c4..162a76e8 100644
|
2018-06-21 01:30:09 +00:00
|
|
|
--- a/src/main/java/org/bukkit/Location.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Location.java
|
|
|
|
@@ -8,6 +8,15 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
|
|
|
import org.bukkit.util.NumberConversions;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
+// Paper start
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.function.Predicate;
|
|
|
|
+import org.bukkit.entity.Entity;
|
|
|
|
+import org.bukkit.entity.LivingEntity;
|
|
|
|
+import org.bukkit.entity.Player;
|
|
|
|
+// Paper end
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Represents a 3-dimensional position in a world.
|
|
|
|
* <br>
|
2018-08-16 11:20:58 +00:00
|
|
|
@@ -514,6 +523,228 @@ public class Location implements Cloneable, ConfigurationSerializable {
|
2018-06-21 01:30:09 +00:00
|
|
|
centerLoc.setZ(getBlockZ() + 0.5);
|
|
|
|
return centerLoc;
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns a list of entities within a bounding box centered around a Location.
|
|
|
|
+ *
|
|
|
|
+ * Some implementations may impose artificial restrictions on the size of the search bounding box.
|
|
|
|
+ *
|
|
|
|
+ * @param x 1/2 the size of the box along x axis
|
|
|
|
+ * @param y 1/2 the size of the box along y axis
|
|
|
|
+ * @param z 1/2 the size of the box along z axis
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
|
|
|
+ */
|
|
|
|
+ public Collection<Entity> getNearbyEntities(double x, double y, double z) {
|
|
|
|
+ if (world == null) {
|
|
|
|
+ throw new IllegalArgumentException("Location has no world");
|
|
|
|
+ }
|
|
|
|
+ return world.getNearbyEntities(this, x, y, z);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param radius X Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<LivingEntity> getNearbyLivingEntities(double radius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, radius, radius, radius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<LivingEntity> getNearbyLivingEntities(double xzRadius, double yRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xzRadius, yRadius, xzRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<LivingEntity> getNearbyLivingEntities(double xRadius, double yRadius, double zRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xRadius, yRadius, zRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param radius Radius
|
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<LivingEntity> getNearbyLivingEntities(double radius, Predicate<LivingEntity> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, radius, radius, radius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<LivingEntity> getNearbyLivingEntities(double xzRadius, double yRadius, Predicate<LivingEntity> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xzRadius, yRadius, xzRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<LivingEntity> getNearbyLivingEntities(double xRadius, double yRadius, double zRadius, Predicate<LivingEntity> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, xRadius, yRadius, zRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param radius X/Y/Z Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
2018-08-16 11:20:58 +00:00
|
|
|
+
|
2018-06-21 01:30:09 +00:00
|
|
|
+ public Collection<Player> getNearbyPlayers(double radius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, radius, radius, radius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<Player> getNearbyPlayers(double xzRadius, double yRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xzRadius, yRadius, xzRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<Player> getNearbyPlayers(double xRadius, double yRadius, double zRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xRadius, yRadius, zRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param radius X/Y/Z Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<Player> getNearbyPlayers(double radius, Predicate<Player> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, radius, radius, radius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<Player> getNearbyPlayers(double xzRadius, double yRadius, Predicate<Player> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xzRadius, yRadius, xzRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public Collection<Player> getNearbyPlayers(double xRadius, double yRadius, double zRadius, Predicate<Player> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, xRadius, yRadius, zRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets all nearby entities of the specified type, within the specified radius (bounding box)
|
|
|
|
+ * @param clazz Type to filter by
|
|
|
|
+ * @param radius X/Y/Z radius to search within
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities of type clazz near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, double radius) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, radius, radius, radius, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets all nearby entities of the specified type, within the specified radius, with x and x radius matching (bounding box)
|
|
|
|
+ * @param clazz Type to filter by
|
|
|
|
+ * @param xzRadius X/Z radius to search within
|
|
|
|
+ * @param yRadius Y radius to search within
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, double xzRadius, double yRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, xzRadius, yRadius, xzRadius, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets all nearby entities of the specified type, within the specified radius (bounding box)
|
|
|
|
+ * @param clazz Type to filter by
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, double xRadius, double yRadius, double zRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, xRadius, yRadius, zRadius, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets all nearby entities of the specified type, within the specified radius (bounding box)
|
|
|
|
+ * @param clazz Type to filter by
|
|
|
|
+ * @param radius X/Y/Z radius to search within
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, double radius, Predicate<T> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, radius, radius, radius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets all nearby entities of the specified type, within the specified radius, with x and x radius matching (bounding box)
|
|
|
|
+ * @param clazz Type to filter by
|
|
|
|
+ * @param xzRadius X/Z radius to search within
|
|
|
|
+ * @param yRadius Y radius to search within
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, double xzRadius, double yRadius, Predicate<T> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, xzRadius, yRadius, xzRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets all nearby entities of the specified type, within the specified radius (bounding box)
|
|
|
|
+ * @param clazz Type to filter by
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param predicate a predicate used to filter results
|
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-06-21 01:30:09 +00:00
|
|
|
+ */
|
|
|
|
+ public <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends Entity> clazz, double xRadius, double yRadius, double zRadius, Predicate<T> predicate) {
|
|
|
|
+ if (world == null) {
|
|
|
|
+ throw new IllegalArgumentException("Location has no world");
|
|
|
|
+ }
|
|
|
|
+ return world.getNearbyEntitiesByType(clazz, this, xRadius, yRadius, zRadius, predicate);
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
--
|
2019-02-23 17:17:41 +00:00
|
|
|
2.20.1
|
2018-06-21 01:30:09 +00:00
|
|
|
|