2019-02-23 18:17:41 +01:00
|
|
|
From fd36072a3ce6839ef977bedd24f3b459a0933f3d Mon Sep 17 00:00:00 2001
|
2018-05-01 00:27:42 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 30 Apr 2018 17:55:28 -0400
|
|
|
|
Subject: [PATCH] Additional world.getNearbyEntities API's
|
|
|
|
|
|
|
|
Provides more methods to get nearby entities, and filter by types and predicates
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
|
2019-01-15 22:12:19 +01:00
|
|
|
index d499e41b..bc6a51d7 100644
|
2018-05-01 00:27:42 +02:00
|
|
|
--- a/src/main/java/org/bukkit/World.java
|
|
|
|
+++ b/src/main/java/org/bukkit/World.java
|
2018-10-27 06:02:22 +02:00
|
|
|
@@ -2,6 +2,8 @@ package org.bukkit;
|
2018-05-01 00:27:42 +02:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import org.bukkit.generator.ChunkGenerator;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2019-01-15 22:12:19 +01:00
|
|
|
@@ -483,6 +485,238 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
2018-05-01 00:27:42 +02:00
|
|
|
*/
|
|
|
|
public Collection<Entity> getEntitiesByClasses(Class<?>... classes);
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @param radius Radius
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(Location loc, double radius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, loc, radius, radius, radius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(Location loc, double xzRadius, double yRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, loc, xzRadius, yRadius, xzRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z radius
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(Location loc, double xRadius, double yRadius, double zRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, loc, xRadius, yRadius, zRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param radius X Radius
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(Location loc, double radius, Predicate<LivingEntity> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, loc, radius, radius, radius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(Location loc, double xzRadius, double yRadius, Predicate<LivingEntity> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, loc, xzRadius, yRadius, xzRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z radius
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(Location loc, double xRadius, double yRadius, double zRadius, Predicate<LivingEntity> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.LivingEntity.class, loc, xRadius, yRadius, zRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param radius X/Y/Z Radius
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(Location loc, double radius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, loc, radius, radius, radius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(Location loc, double xzRadius, double yRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, loc, xzRadius, yRadius, xzRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(Location loc, double xRadius, double yRadius, double zRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, loc, xRadius, yRadius, zRadius);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param radius X/Y/Z Radius
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(Location loc, double radius, Predicate<Player> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, loc, radius, radius, radius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xzRadius X/Z Radius
|
|
|
|
+ * @param yRadius Y Radius
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(Location loc, double xzRadius, double yRadius, Predicate<Player> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, loc, xzRadius, yRadius, xzRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(Location loc, double xRadius, double yRadius, double zRadius, Predicate<Player> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(org.bukkit.entity.Player.class, loc, 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 loc Center location
|
|
|
|
+ * @param radius X/Y/Z radius to search within
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, Location loc, double radius) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, loc, 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 loc Center location
|
|
|
|
+ * @param xzRadius X/Z radius to search within
|
|
|
|
+ * @param yRadius Y radius to search within
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, Location loc, double xzRadius, double yRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, loc, 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 loc Center location
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * @param <T> the entity type
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, Location loc, double xRadius, double yRadius, double zRadius) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, loc, 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 loc Center location
|
|
|
|
+ * @param radius X/Y/Z radius to search within
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, Location loc, double radius, Predicate<T> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, loc, 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 loc Center location
|
|
|
|
+ * @param xzRadius X/Z radius to search within
|
|
|
|
+ * @param yRadius Y radius to search within
|
2018-08-16 13:20:58 +02: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-05-01 00:27:42 +02:00
|
|
|
+ */
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends T> clazz, Location loc, double xzRadius, double yRadius, Predicate<T> predicate) {
|
|
|
|
+ return getNearbyEntitiesByType(clazz, loc, xzRadius, yRadius, xzRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2018-08-16 13:20:58 +02:00
|
|
|
+ * Gets all nearby entities of the specified type, within the specified radius (bounding box)
|
|
|
|
+ * @param clazz Type to filter by
|
|
|
|
+ * @param loc Center location
|
|
|
|
+ * @param xRadius X Radius
|
|
|
|
+ * @param yRadius Y Radius
|
|
|
|
+ * @param zRadius Z Radius
|
|
|
|
+ * @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-05-01 00:27:42 +02:00
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(Class<? extends Entity> clazz, Location loc, double xRadius, double yRadius, double zRadius, Predicate<T> predicate) {
|
|
|
|
+ if (clazz == null) {
|
|
|
|
+ clazz = Entity.class;
|
|
|
|
+ }
|
|
|
|
+ List<T> nearby = new ArrayList<>();
|
|
|
|
+ for (Entity bukkitEntity : getNearbyEntities(loc, xRadius, yRadius, zRadius)) {
|
|
|
|
+ //noinspection unchecked
|
|
|
|
+ if (clazz.isAssignableFrom(bukkitEntity.getClass()) && (predicate == null || predicate.test((T) bukkitEntity))) {
|
|
|
|
+ //noinspection unchecked
|
|
|
|
+ nearby.add((T) bukkitEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nearby;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Get a list of all players in this World
|
|
|
|
*
|
|
|
|
--
|
2019-01-01 04:15:55 +01:00
|
|
|
2.20.1
|
2018-05-01 00:27:42 +02:00
|
|
|
|