mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
e035fd7034
Upstream has released updates that appear 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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
179 lines
11 KiB
Diff
179 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Corey Shupe <coreyshupe101@gmail.com>
|
|
Date: Wed, 11 Jan 2023 16:40:39 -0500
|
|
Subject: [PATCH] Add Listing API for Player
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
|
|
index aa1c6de4d6cb7bbca33d25895c54707d220ab62a..9810d62c99f5d7dfca61ddfbbc356aebad2f7001 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
|
|
@@ -29,12 +29,46 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet<ClientGamePacke
|
|
this.actions = EnumSet.of(action);
|
|
this.entries = List.of(new ClientboundPlayerInfoUpdatePacket.Entry(player));
|
|
}
|
|
+ // Paper start
|
|
+ public ClientboundPlayerInfoUpdatePacket(EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions, List<ClientboundPlayerInfoUpdatePacket.Entry> entries) {
|
|
+ this.actions = actions;
|
|
+ this.entries = entries;
|
|
+ }
|
|
+
|
|
+ public ClientboundPlayerInfoUpdatePacket(EnumSet<ClientboundPlayerInfoUpdatePacket.Action> actions, ClientboundPlayerInfoUpdatePacket.Entry entry) {
|
|
+ this.actions = actions;
|
|
+ this.entries = List.of(entry);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
public static ClientboundPlayerInfoUpdatePacket createPlayerInitializing(Collection<ServerPlayer> players) {
|
|
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> enumSet = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME);
|
|
return new ClientboundPlayerInfoUpdatePacket(enumSet, players);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public static ClientboundPlayerInfoUpdatePacket createPlayerInitializing(Collection<ServerPlayer> players, ServerPlayer forPlayer) {
|
|
+ final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> enumSet = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME);
|
|
+ final List<ClientboundPlayerInfoUpdatePacket.Entry> entries = new java.util.ArrayList<>(players.size());
|
|
+ final org.bukkit.craftbukkit.entity.CraftPlayer bukkitEntity = forPlayer.getBukkitEntity();
|
|
+ for (final ServerPlayer player : players) {
|
|
+ entries.add(new ClientboundPlayerInfoUpdatePacket.Entry(player, bukkitEntity.isListed(player.getBukkitEntity())));
|
|
+ }
|
|
+ return new ClientboundPlayerInfoUpdatePacket(enumSet, entries);
|
|
+ }
|
|
+
|
|
+ public static ClientboundPlayerInfoUpdatePacket createSinglePlayerInitializing(ServerPlayer player, boolean listed) {
|
|
+ final EnumSet<ClientboundPlayerInfoUpdatePacket.Action> enumSet = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER, ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY, ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME);
|
|
+ final List<ClientboundPlayerInfoUpdatePacket.Entry> entries = List.of(new Entry(player, listed));
|
|
+ return new ClientboundPlayerInfoUpdatePacket(enumSet, entries);
|
|
+ }
|
|
+
|
|
+ public static ClientboundPlayerInfoUpdatePacket updateListed(UUID playerInfoId, boolean listed) {
|
|
+ EnumSet<ClientboundPlayerInfoUpdatePacket.Action> enumSet = EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED);
|
|
+ return new ClientboundPlayerInfoUpdatePacket(enumSet, new ClientboundPlayerInfoUpdatePacket.Entry(playerInfoId, listed));
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public ClientboundPlayerInfoUpdatePacket(FriendlyByteBuf buf) {
|
|
this.actions = buf.readEnumSet(ClientboundPlayerInfoUpdatePacket.Action.class);
|
|
this.entries = buf.readList((buf2) -> {
|
|
@@ -144,8 +178,18 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet<ClientGamePacke
|
|
|
|
public static record Entry(UUID profileId, @Nullable GameProfile profile, boolean listed, int latency, GameType gameMode, @Nullable Component displayName, @Nullable RemoteChatSession.Data chatSession) {
|
|
Entry(ServerPlayer player) {
|
|
- this(player.getUUID(), player.getGameProfile(), true, player.connection.latency(), player.gameMode.getGameModeForPlayer(), player.getTabListDisplayName(), Optionull.map(player.getChatSession(), RemoteChatSession::asData));
|
|
+ // Paper start - add listed
|
|
+ this(player, true);
|
|
+ }
|
|
+ Entry(ServerPlayer player, boolean listed) {
|
|
+ this(player.getUUID(), player.getGameProfile(), listed, player.connection.latency(), player.gameMode.getGameModeForPlayer(), player.getTabListDisplayName(), Optionull.map(player.getChatSession(), RemoteChatSession::asData));
|
|
+ // Paper end - add listed
|
|
+ }
|
|
+ // Paper start
|
|
+ Entry(UUID profileId, boolean listed) {
|
|
+ this(profileId, null, listed, 0, GameType.DEFAULT_MODE, null, null);
|
|
}
|
|
+ // Paper end
|
|
}
|
|
|
|
static class EntryBuilder {
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 098bb36a66e022da30302936aba10d296587ac88..a35638a92479b90afa89cf201fc45b49c9e767f3 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -356,14 +356,22 @@ public abstract class PlayerList {
|
|
// CraftBukkit end
|
|
|
|
// CraftBukkit start - sendAll above replaced with this loop
|
|
- ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(player));
|
|
+ ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(player)); // Paper
|
|
|
|
final List<ServerPlayer> onlinePlayers = Lists.newArrayListWithExpectedSize(this.players.size() - 1); // Paper - use single player info update packet
|
|
for (int i = 0; i < this.players.size(); ++i) {
|
|
ServerPlayer entityplayer1 = (ServerPlayer) this.players.get(i);
|
|
|
|
if (entityplayer1.getBukkitEntity().canSee(bukkitPlayer)) {
|
|
+ // Paper start
|
|
+ if (entityplayer1.getBukkitEntity().isListed(bukkitPlayer)) {
|
|
+ // Paper end
|
|
entityplayer1.connection.send(packet);
|
|
+ // Paper start
|
|
+ } else {
|
|
+ entityplayer1.connection.send(ClientboundPlayerInfoUpdatePacket.createSinglePlayerInitializing(player, false));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
if (entityplayer1 == player || !bukkitPlayer.canSee(entityplayer1.getBukkitEntity())) { // Paper - don't include joining player
|
|
@@ -374,7 +382,7 @@ public abstract class PlayerList {
|
|
}
|
|
// Paper start - use single player info update packet
|
|
if (!onlinePlayers.isEmpty()) {
|
|
- player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(onlinePlayers));
|
|
+ player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(onlinePlayers, player));
|
|
}
|
|
// Paper end
|
|
player.sentListPacket = true;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 1ed523128383e2f8b9090607af982645133338d5..af4b96c5b6b6cea3edf0eaca22d62288bda05ea4 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -182,6 +182,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
private final ConversationTracker conversationTracker = new ConversationTracker();
|
|
private final Set<String> channels = new HashSet<String>();
|
|
private final Map<UUID, Set<WeakReference<Plugin>>> invertedVisibilityEntities = new HashMap<>();
|
|
+ private final Set<UUID> unlistedEntities = new HashSet<>(); // Paper
|
|
private static final WeakHashMap<Plugin, WeakReference<Plugin>> pluginWeakReferences = new WeakHashMap<>();
|
|
private int hash = 0;
|
|
private double health = 20;
|
|
@@ -1986,7 +1987,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
otherPlayer.setUUID(uuidOverride);
|
|
}
|
|
// Paper end
|
|
- this.getHandle().connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(otherPlayer)));
|
|
+ this.getHandle().connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(otherPlayer), this.getHandle())); // Paper
|
|
if (original != null) otherPlayer.setUUID(original); // Paper - uuid override
|
|
}
|
|
|
|
@@ -2095,6 +2096,43 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
return (entity != null) ? this.canSee(entity) : false; // If we can't find it, we can't see it
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public boolean isListed(Player other) {
|
|
+ return !this.unlistedEntities.contains(other.getUniqueId());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean unlistPlayer(@NotNull Player other) {
|
|
+ Preconditions.checkNotNull(other, "hidden entity cannot be null");
|
|
+ if (this.getHandle().connection == null) return false;
|
|
+ if (this.equals(other)) return false;
|
|
+ if (!this.canSee(other)) return false;
|
|
+
|
|
+ if (unlistedEntities.add(other.getUniqueId())) {
|
|
+ this.getHandle().connection.send(ClientboundPlayerInfoUpdatePacket.updateListed(other.getUniqueId(), false));
|
|
+ return true;
|
|
+ } else {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean listPlayer(@NotNull Player other) {
|
|
+ Preconditions.checkNotNull(other, "hidden entity cannot be null");
|
|
+ if (this.getHandle().connection == null) return false;
|
|
+ if (this.equals(other)) return false;
|
|
+ if (!this.canSee(other)) throw new IllegalStateException("Player cannot see other player");
|
|
+
|
|
+ if (this.unlistedEntities.remove(other.getUniqueId())) {
|
|
+ this.getHandle().connection.send(ClientboundPlayerInfoUpdatePacket.updateListed(other.getUniqueId(), true));
|
|
+ return true;
|
|
+ } else {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Map<String, Object> serialize() {
|
|
Map<String, Object> result = new LinkedHashMap<String, Object>();
|