2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-04-30 22:27:42 +00: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
|
2020-05-06 09:48:49 +00:00
|
|
|
index 3b027f67c1763ee0a4f7b02490d3cee1c3eff369..fbe7e76c0f3122dd47c7ca4562b5ac3577a71ffc 100644
|
2018-04-30 22:27:42 +00:00
|
|
|
--- a/src/main/java/org/bukkit/World.java
|
|
|
|
+++ b/src/main/java/org/bukkit/World.java
|
2019-04-23 04:47:07 +00:00
|
|
|
@@ -1,6 +1,9 @@
|
|
|
|
package org.bukkit;
|
2018-04-30 22:27:42 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
2019-04-23 04:47:07 +00:00
|
|
|
+import org.bukkit.generator.ChunkGenerator;
|
2018-04-30 22:27:42 +00:00
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2020-03-26 02:37:20 +00:00
|
|
|
@@ -635,6 +638,256 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
2019-03-20 00:28:15 +00:00
|
|
|
@NotNull
|
|
|
|
public Collection<Entity> getEntitiesByClasses(@NotNull Class<?>... classes);
|
2018-04-30 22:27:42 +00:00
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ /**
|
|
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
|
|
+ * @param loc Center location
|
2018-08-16 11:20:58 +00:00
|
|
|
+ * @param radius Radius
|
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double radius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 11:20:58 +00:00
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double xzRadius, double yRadius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 11:20:58 +00:00
|
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
2018-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double xRadius, double yRadius, double zRadius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double radius, @Nullable Predicate<LivingEntity> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double xzRadius, double yRadius, @Nullable Predicate<LivingEntity> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double xRadius, double yRadius, double zRadius, @Nullable Predicate<LivingEntity> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 11:20:58 +00:00
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double radius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 11:20:58 +00:00
|
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
2018-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double xzRadius, double yRadius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 11:20:58 +00:00
|
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
2018-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double xRadius, double yRadius, double zRadius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double radius, @Nullable Predicate<Player> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double xzRadius, double yRadius, @Nullable Predicate<Player> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double xRadius, double yRadius, double zRadius, @Nullable Predicate<Player> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull Location loc, double radius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull Location loc, double xzRadius, double yRadius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull Location loc, double xRadius, double yRadius, double zRadius) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull Location loc, double radius, @Nullable Predicate<T> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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 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-04-30 22:27:42 +00:00
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull Location loc, double xzRadius, double yRadius, @Nullable Predicate<T> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ return getNearbyEntitiesByType(clazz, loc, xzRadius, yRadius, xzRadius, predicate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2018-08-16 11:20:58 +00: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.
|
|
|
|
+ */
|
2019-03-20 00:28:15 +00:00
|
|
|
+ @NotNull
|
|
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends Entity> clazz, @NotNull Location loc, double xRadius, double yRadius, double zRadius, @Nullable Predicate<T> predicate) {
|
2018-04-30 22:27:42 +00:00
|
|
|
+ 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-04-23 04:47:07 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
|
2020-06-25 01:10:30 +00:00
|
|
|
index 16352c7dab042c5042020a06208270200f576c02..e5b811229830e4d55b08ab18bedec1494ff342ac 100644
|
2019-04-23 04:47:07 +00:00
|
|
|
--- a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
|
|
|
|
+++ b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
|
|
|
|
@@ -42,8 +42,7 @@ public class AsyncPlayerPreLoginEvent extends Event {
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * Changes the PlayerProfile the player will login as
|
|
|
|
+ /* * Changes the PlayerProfile the player will login as
|
|
|
|
* @param profile The profile to use
|
|
|
|
*/
|
|
|
|
public void setPlayerProfile(@NotNull PlayerProfile profile) {
|