mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-01 00:10:32 +01:00
526795bacd
* Update patches to handle vineflower decompiler * update patches again to handle inlined simple lambdas * update vf again and re-apply/rebuild patches * update patches after removal of verify-merges flag * fix compile issue * remove maven local * fix some issues * address more issues * fix collision patch * use paperweight release * more fixes * update fineflower and fix patches again * add missing comment descriptor --------- Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
185 lines
11 KiB
Diff
185 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 754a2a5e958a04b3f8bf216b6022f547aa1cd36f..d41fe931daf03c40ca1d7b9159001d0122d72f0c 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
|
|
@@ -29,6 +29,17 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet<ClientGamePacke
|
|
this.actions = EnumSet.of(action);
|
|
this.entries = List.of(new ClientboundPlayerInfoUpdatePacket.Entry(player));
|
|
}
|
|
+ // Paper start - Add Listing API for Player
|
|
+ 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 - Add Listing API for Player
|
|
|
|
public static ClientboundPlayerInfoUpdatePacket createPlayerInitializing(Collection<ServerPlayer> players) {
|
|
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> enumSet = EnumSet.of(
|
|
@@ -42,6 +53,29 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet<ClientGamePacke
|
|
return new ClientboundPlayerInfoUpdatePacket(enumSet, players);
|
|
}
|
|
|
|
+ // Paper start - Add Listing API for Player
|
|
+ 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 - Add Listing API for Player
|
|
+
|
|
public ClientboundPlayerInfoUpdatePacket(FriendlyByteBuf buf) {
|
|
this.actions = buf.readEnumSet(ClientboundPlayerInfoUpdatePacket.Action.class);
|
|
this.entries = buf.readList(buf2 -> {
|
|
@@ -146,16 +180,24 @@ public class ClientboundPlayerInfoUpdatePacket implements Packet<ClientGamePacke
|
|
@Nullable RemoteChatSession.Data chatSession
|
|
) {
|
|
Entry(ServerPlayer player) {
|
|
+ // Paper start - Add Listing API for Player
|
|
+ this(player, true);
|
|
+ }
|
|
+ Entry(ServerPlayer player, boolean listed) {
|
|
this(
|
|
player.getUUID(),
|
|
player.getGameProfile(),
|
|
- true,
|
|
+ listed,
|
|
player.connection.latency(),
|
|
player.gameMode.getGameModeForPlayer(),
|
|
player.getTabListDisplayName(),
|
|
Optionull.map(player.getChatSession(), RemoteChatSession::asData)
|
|
);
|
|
}
|
|
+ Entry(UUID profileId, boolean listed) {
|
|
+ this(profileId, null, listed, 0, GameType.DEFAULT_MODE, null, null);
|
|
+ }
|
|
+ // Paper end - Add Listing API for Player
|
|
}
|
|
|
|
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 bc0e9fb41fe22e0a603837fcbdd82134f51d21d9..d38fe02af4cc35ed5b22acec41bedb76151f8af5 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -357,14 +357,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 - Add Listing API for Player
|
|
|
|
final List<ServerPlayer> onlinePlayers = Lists.newArrayListWithExpectedSize(this.players.size() - 1); // Paper - Use single player info update packet on join
|
|
for (int i = 0; i < this.players.size(); ++i) {
|
|
ServerPlayer entityplayer1 = (ServerPlayer) this.players.get(i);
|
|
|
|
if (entityplayer1.getBukkitEntity().canSee(bukkitPlayer)) {
|
|
+ // Paper start - Add Listing API for Player
|
|
+ if (entityplayer1.getBukkitEntity().isListed(bukkitPlayer)) {
|
|
+ // Paper end - Add Listing API for Player
|
|
entityplayer1.connection.send(packet);
|
|
+ // Paper start - Add Listing API for Player
|
|
+ } else {
|
|
+ entityplayer1.connection.send(ClientboundPlayerInfoUpdatePacket.createSinglePlayerInitializing(player, false));
|
|
+ }
|
|
+ // Paper end - Add Listing API for Player
|
|
}
|
|
|
|
if (entityplayer1 == player || !bukkitPlayer.canSee(entityplayer1.getBukkitEntity())) { // Paper - Use single player info update packet on join; Don't include joining player
|
|
@@ -375,7 +383,7 @@ public abstract class PlayerList {
|
|
}
|
|
// Paper start - Use single player info update packet on join
|
|
if (!onlinePlayers.isEmpty()) {
|
|
- player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(onlinePlayers));
|
|
+ player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(onlinePlayers, player)); // Paper - Add Listing API for Player
|
|
}
|
|
// Paper end - Use single player info update packet on join
|
|
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 15817a84ad5db54ec299f933387f4ad1e0e74b33..15c7724e406655cffddad1a14081d737dab7ef44 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -188,6 +188,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 - Add Listing API for Player
|
|
private static final WeakHashMap<Plugin, WeakReference<Plugin>> pluginWeakReferences = new WeakHashMap<>();
|
|
private int hash = 0;
|
|
private double health = 20;
|
|
@@ -1995,7 +1996,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 - Add Listing API for Player
|
|
if (original != null) otherPlayer.setUUID(original); // Paper - uuid override
|
|
}
|
|
|
|
@@ -2102,6 +2103,41 @@ 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 - Add Listing API for Player
|
|
+ @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.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.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 - Add Listing API for Player
|
|
+
|
|
@Override
|
|
public Map<String, Object> serialize() {
|
|
Map<String, Object> result = new LinkedHashMap<String, Object>();
|