From f1400a74c5f612c9f0ef62e8bd63336f906cf5c2 Mon Sep 17 00:00:00 2001 From: Tom Date: Fri, 26 Feb 2021 16:27:53 -0600 Subject: [PATCH] Expose Tracked Players A lot of plugins seem to use reflection to determine this, so this could be a bit of a starter-patch as future PR'ers could also exposed tracked entities as well. --- .../Expose-Tracked-Players.patch | 33 ++++++++++++ .../Expose-Tracked-Players.patch | 53 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 Spigot-API-Patches/Expose-Tracked-Players.patch create mode 100644 Spigot-Server-Patches/Expose-Tracked-Players.patch diff --git a/Spigot-API-Patches/Expose-Tracked-Players.patch b/Spigot-API-Patches/Expose-Tracked-Players.patch new file mode 100644 index 0000000000..a667005325 --- /dev/null +++ b/Spigot-API-Patches/Expose-Tracked-Players.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tom +Date: Fri, 26 Feb 2021 16:24:25 -0600 +Subject: [PATCH] Expose Tracked Players + + +diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/entity/Player.java ++++ b/src/main/java/org/bukkit/entity/Player.java +@@ -0,0 +0,0 @@ + package org.bukkit.entity; + + import java.net.InetSocketAddress; ++import java.util.Set; // Paper + import java.util.UUID; + import com.destroystokyo.paper.ClientOption; // Paper + import com.destroystokyo.paper.Title; // Paper +@@ -0,0 +0,0 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM + void sendOpLevel(byte level); + // Paper end + ++ // Paper start ++ /** ++ * @return Returns a set of Players within this player's tracking range (that the player's client can "see") ++ */ ++ @NotNull ++ Set getTrackedPlayers(); ++ // Paper end ++ + // Spigot start + public class Spigot extends Entity.Spigot { + diff --git a/Spigot-Server-Patches/Expose-Tracked-Players.patch b/Spigot-Server-Patches/Expose-Tracked-Players.patch new file mode 100644 index 0000000000..98fd26c3c9 --- /dev/null +++ b/Spigot-Server-Patches/Expose-Tracked-Players.patch @@ -0,0 +1,53 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tom +Date: Fri, 26 Feb 2021 16:24:25 -0600 +Subject: [PATCH] Expose Tracked Players + + +diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/Entity.java ++++ b/src/main/java/net/minecraft/server/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke + public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper + private CraftEntity bukkitEntity; + +- PlayerChunkMap.EntityTracker tracker; // Paper ++ public PlayerChunkMap.EntityTracker tracker; // Paper package private -> public + boolean collisionLoadChunks = false; // Paper + Throwable addedToWorldStack; // Paper - entity debug + public CraftEntity getBukkitEntity() { +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -0,0 +0,0 @@ import java.net.InetSocketAddress; + import java.net.SocketAddress; + import java.util.ArrayList; + import java.util.Collection; ++import java.util.Collections; // Paper + import java.util.HashMap; + import java.util.HashSet; + import java.util.LinkedHashMap; +@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + } + // Paper end + ++ // Paper start ++ @Override ++ public Set getTrackedPlayers() { ++ if (entity.tracker == null) { ++ return Collections.emptySet(); ++ } ++ ++ Set set = new HashSet<>(entity.tracker.trackedPlayers.size()); ++ for (EntityPlayer entityPlayer : entity.tracker.trackedPlayers) { ++ set.add(entityPlayer.getBukkitEntity().getPlayer()); ++ } ++ return set; ++ } ++ // Paper end ++ + // Spigot start + private final Player.Spigot spigot = new Player.Spigot() + {