mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 20:46:59 +01:00
7e8ae207bd
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: e99c9444 Add Plugin Chunk Ticket API 6a235f06 Fix incorrect nullability annotations for PlayerJoinEvent's join message CraftBukkit Changes:5f889388
Tweak build expiration to 7 days572c02b0
MC-155077, SPIGOT-5113: EntityTracker desync7ad3a1f4
SPIGOT-5146: BlockDataMeta does not work60860983
SPIGOT-5155: Setting EntityExplodeEvent yield to 0 still causes blocks to drop087a2cf4
Print number of force loaded chunks per plugin in crash reports07b5b06d
Add Plugin Chunk Ticket API7ffb2a27
SPIGOT-5149: resetRecipes does nothinga2275f19
SPIGOT-5141: World.generateTree() causes ClassCastException with huge mushrooms31d4a777
SPIGOT-5142: Ignore invalid firework effects Spigot Changes: 5e4e7f32 BUILDTOOLS-471: Rebuild patches 6e944739 SPIGOT-5159: Raider activation range overridden by Monster range
296 lines
14 KiB
Diff
296 lines
14 KiB
Diff
From 8086435d3bbd0275e9ac6bf4e5d5492e8646e3f7 Mon Sep 17 00:00:00 2001
|
|
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
|
|
index 3cd4bff1..36ec897f 100644
|
|
--- a/src/main/java/org/bukkit/World.java
|
|
+++ b/src/main/java/org/bukkit/World.java
|
|
@@ -1,6 +1,9 @@
|
|
package org.bukkit;
|
|
|
|
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;
|
|
@@ -586,6 +589,256 @@ public interface World extends PluginMessageRecipient, Metadatable {
|
|
@NotNull
|
|
public Collection<Entity> getEntitiesByClasses(@NotNull Class<?>... classes);
|
|
|
|
+ // Paper start
|
|
+ /**
|
|
+ * Gets nearby players within the specified radius (bounding box)
|
|
+ * @param loc Center location
|
|
+ * @param radius Radius
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull 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
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull 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
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull 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
|
|
+ * @param predicate a predicate used to filter results
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double radius, @Nullable 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
|
|
+ * @param predicate a predicate used to filter results
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double xzRadius, double yRadius, @Nullable 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
|
|
+ * @param predicate a predicate used to filter results
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<LivingEntity> getNearbyLivingEntities(@NotNull Location loc, double xRadius, double yRadius, double zRadius, @Nullable 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
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull 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
|
|
+ * @return the collection of living entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull 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
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull 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
|
|
+ * @param predicate a predicate used to filter results
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double radius, @Nullable 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
|
|
+ * @param predicate a predicate used to filter results
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double xzRadius, double yRadius, @Nullable 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
|
|
+ * @param predicate a predicate used to filter results
|
|
+ * @return the collection of players near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default Collection<Player> getNearbyPlayers(@NotNull Location loc, double xRadius, double yRadius, double zRadius, @Nullable 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
|
|
+ * @param <T> the entity type
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull 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
|
|
+ * @param <T> the entity type
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull 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
|
|
+ * @param <T> the entity type
|
|
+ * @return the collection of entities near location. This will always be a non-null collection.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull 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
|
|
+ * @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.
|
|
+ */
|
|
+ @NotNull
|
|
+ public default <T extends Entity> Collection<T> getNearbyEntitiesByType(@Nullable Class<? extends T> clazz, @NotNull Location loc, double radius, @Nullable 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
|
|
+ * @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.
|
|
+ */
|
|
+ @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) {
|
|
+ return getNearbyEntitiesByType(clazz, loc, 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 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.
|
|
+ */
|
|
+ @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) {
|
|
+ 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
|
|
*
|
|
diff --git a/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java b/src/main/java/org/bukkit/event/player/AsyncPlayerPreLoginEvent.java
|
|
index 6c09ea6c..76c4a1a6 100644
|
|
--- 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) {
|
|
--
|
|
2.22.0
|
|
|