mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-16 15:45:23 +01:00
ac554ad46d
Updated Upstream (Bukkit/CraftBukkit) 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: fa99e752 PR-1007: Add ItemMeta#getAsComponentString() 94a91782 Fix copy-pasted BlockType.Typed documentation 9b34ac8c Largely restore deprecated PotionData API 51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5 702d15fe Fix Javadoc reference 42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them 237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more 87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent CraftBukkit Changes: 4af0f22e8 SPIGOT-7664: Item meta should prevail over block states c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot 124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects 66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API 6118e5398 Fix regression listening to minecraft:brand custom payloads c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check 12360a7ec Remove unused imports 147b098b4 PR-1397: Add ItemMeta#getAsComponentString() 428aefe0e Largely restore deprecated PotionData API afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them 8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets 0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA 2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent 741b84480 PR-1390: Improve internal handling of damage sources 0364df4e1 SPIGOT-7657: Error when loading angry entities
184 lines
11 KiB
Diff
184 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 6247a21c9c391abf1f6db3482c659593e4f29355..9ccca41bf23efadba5329cc584bbcdcacbe09a92 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerInfoUpdatePacket.java
|
|
@@ -37,6 +37,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(
|
|
@@ -50,6 +61,28 @@ 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
|
|
private ClientboundPlayerInfoUpdatePacket(RegistryFriendlyByteBuf buf) {
|
|
this.actions = buf.readEnumSet(ClientboundPlayerInfoUpdatePacket.Action.class);
|
|
this.entries = buf.readList(buf2 -> {
|
|
@@ -158,16 +191,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 ea04eb049e16d1027d15f9863d1fcd16f090c464..0aa28caa1254137c0bae8e213bd08c9a654f5335 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -359,14 +359,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
|
|
@@ -377,7 +385,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 36ffa642655bea0281251996b8207dd6335043ba..e423e97d07ef0f5d0e5bcc7ceb0f353be142e0bf 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -199,6 +199,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;
|
|
@@ -2073,7 +2074,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
|
|
}
|
|
|
|
@@ -2177,6 +2178,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>();
|