From b435e8e8d33af7256523b824a96336bc80076ee3 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 28 Jul 2023 18:56:00 +1000 Subject: [PATCH] SPIGOT-7349: Player#setDisplayName not working when message/format unmodified --- .../network/chat/ChatMessageType.patch | 26 ------------- .../server/network/PlayerConnection.patch | 38 ++++++++----------- 2 files changed, 16 insertions(+), 48 deletions(-) delete mode 100644 nms-patches/net/minecraft/network/chat/ChatMessageType.patch diff --git a/nms-patches/net/minecraft/network/chat/ChatMessageType.patch b/nms-patches/net/minecraft/network/chat/ChatMessageType.patch deleted file mode 100644 index 53c44491b..000000000 --- a/nms-patches/net/minecraft/network/chat/ChatMessageType.patch +++ /dev/null @@ -1,26 +0,0 @@ ---- a/net/minecraft/network/chat/ChatMessageType.java -+++ b/net/minecraft/network/chat/ChatMessageType.java -@@ -2,6 +2,7 @@ - - import com.mojang.serialization.Codec; - import com.mojang.serialization.codecs.RecordCodecBuilder; -+import java.util.List; - import java.util.Optional; - import javax.annotation.Nullable; - import net.minecraft.commands.CommandListenerWrapper; -@@ -27,6 +28,7 @@ - public static final ResourceKey TEAM_MSG_COMMAND_INCOMING = create("team_msg_command_incoming"); - public static final ResourceKey TEAM_MSG_COMMAND_OUTGOING = create("team_msg_command_outgoing"); - public static final ResourceKey EMOTE_COMMAND = create("emote_command"); -+ public static final ResourceKey RAW = create("raw"); // CraftBukkit - - private static ResourceKey create(String s) { - return ResourceKey.create(Registries.CHAT_TYPE, new MinecraftKey(s)); -@@ -40,6 +42,7 @@ - bootstapcontext.register(ChatMessageType.TEAM_MSG_COMMAND_INCOMING, new ChatMessageType(ChatDecoration.teamMessage("chat.type.team.text"), ChatDecoration.withSender("chat.type.text.narrate"))); - bootstapcontext.register(ChatMessageType.TEAM_MSG_COMMAND_OUTGOING, new ChatMessageType(ChatDecoration.teamMessage("chat.type.team.sent"), ChatDecoration.withSender("chat.type.text.narrate"))); - bootstapcontext.register(ChatMessageType.EMOTE_COMMAND, new ChatMessageType(ChatDecoration.withSender("chat.type.emote"), ChatDecoration.withSender("chat.type.emote"))); -+ bootstapcontext.register(ChatMessageType.RAW, new ChatMessageType(new ChatDecoration("%s", List.of(ChatDecoration.a.CONTENT), ChatModifier.EMPTY), new ChatDecoration("%s", List.of(ChatDecoration.a.CONTENT), ChatModifier.EMPTY))); // CraftBukkit - } - - public static ChatMessageType.a bind(ResourceKey resourcekey, Entity entity) { diff --git a/nms-patches/net/minecraft/server/network/PlayerConnection.patch b/nms-patches/net/minecraft/server/network/PlayerConnection.patch index 2df5fd4a8..898e89423 100644 --- a/nms-patches/net/minecraft/server/network/PlayerConnection.patch +++ b/nms-patches/net/minecraft/server/network/PlayerConnection.patch @@ -984,7 +984,7 @@ this.send(new ClientboundSystemChatPacket(IChatBaseComponent.translatable("chat.disabled.options").withStyle(EnumChatFormat.RED), false)); return Optional.empty(); } else { -@@ -1465,6 +2011,122 @@ +@@ -1465,6 +2011,116 @@ return false; } @@ -1023,9 +1023,6 @@ + if (originalFormat.equals(queueEvent.getFormat()) && originalMessage.equals(queueEvent.getMessage()) && queueEvent.getPlayer().getName().equalsIgnoreCase(queueEvent.getPlayer().getDisplayName())) { + PlayerConnection.this.server.getPlayerList().broadcastChatMessage(original, PlayerConnection.this.player, ChatMessageType.bind(ChatMessageType.CHAT, (Entity) PlayerConnection.this.player)); + return null; -+ } else if (CraftChatMessage.fromComponent(original.decoratedContent()).equals(message)) { -+ PlayerConnection.this.server.getPlayerList().broadcastChatMessage(original, PlayerConnection.this.player, ChatMessageType.bind(ChatMessageType.RAW, (Entity) PlayerConnection.this.player)); -+ return null; + } + + for (EntityPlayer recipient : server.getPlayerList().players) { @@ -1062,9 +1059,6 @@ + if (originalFormat.equals(event.getFormat()) && originalMessage.equals(event.getMessage()) && event.getPlayer().getName().equalsIgnoreCase(event.getPlayer().getDisplayName())) { + PlayerConnection.this.server.getPlayerList().broadcastChatMessage(original, PlayerConnection.this.player, ChatMessageType.bind(ChatMessageType.CHAT, (Entity) PlayerConnection.this.player)); + return; -+ } else if (CraftChatMessage.fromComponent(original.decoratedContent()).equals(s)) { -+ PlayerConnection.this.server.getPlayerList().broadcastChatMessage(original, PlayerConnection.this.player, ChatMessageType.bind(ChatMessageType.RAW, (Entity) PlayerConnection.this.player)); -+ return; + } + + for (EntityPlayer recipient : server.getPlayerList().players) { @@ -1107,7 +1101,7 @@ private PlayerChatMessage getSignedMessage(PacketPlayInChat packetplayinchat, LastSeenMessages lastseenmessages) throws SignedMessageChain.a { SignedMessageBody signedmessagebody = new SignedMessageBody(packetplayinchat.message(), packetplayinchat.timeStamp(), packetplayinchat.salt(), lastseenmessages); -@@ -1472,13 +2134,33 @@ +@@ -1472,13 +2128,33 @@ } private void broadcastChatMessage(PlayerChatMessage playerchatmessage) { @@ -1144,7 +1138,7 @@ this.disconnect(IChatBaseComponent.translatable("disconnect.spam")); } -@@ -1500,13 +2182,62 @@ +@@ -1500,13 +2176,62 @@ @Override public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel()); @@ -1207,7 +1201,7 @@ this.player.resetLastActionTime(); Entity entity; IJumpable ijumpable; -@@ -1588,6 +2319,12 @@ +@@ -1588,6 +2313,12 @@ } public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) { @@ -1220,7 +1214,7 @@ this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a.toNetwork(this.player.level().registryAccess()))); this.addPendingMessage(playerchatmessage); } -@@ -1603,6 +2340,7 @@ +@@ -1603,6 +2334,7 @@ @Override public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel()); @@ -1228,7 +1222,7 @@ final WorldServer worldserver = this.player.serverLevel(); final Entity entity = packetplayinuseentity.getTarget(worldserver); -@@ -1617,13 +2355,51 @@ +@@ -1617,13 +2349,51 @@ if (axisalignedbb.distanceToSqr(this.player.getEyePosition()) < PlayerConnection.MAX_INTERACTION_DISTANCE) { packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() { @@ -1281,7 +1275,7 @@ if (enuminteractionresult.consumesAction()) { CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, itemstack1, entity); if (enuminteractionresult.shouldSwing()) { -@@ -1636,23 +2412,29 @@ +@@ -1636,23 +2406,29 @@ @Override public void onInteraction(EnumHand enumhand) { @@ -1314,7 +1308,7 @@ } } else { PlayerConnection.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.invalid_entity_attacked")); -@@ -1675,14 +2457,14 @@ +@@ -1675,14 +2451,14 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; @@ -1331,7 +1325,7 @@ if (this.server.isHardcore()) { this.player.setGameMode(EnumGamemode.SPECTATOR); ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server); -@@ -1698,15 +2480,21 @@ +@@ -1698,15 +2474,21 @@ @Override public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel()); @@ -1355,7 +1349,7 @@ this.player.containerMenu.sendAllDataToRemote(); } else if (!this.player.containerMenu.stillValid(this.player)) { PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); -@@ -1719,7 +2507,284 @@ +@@ -1719,7 +2501,284 @@ boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -1641,7 +1635,7 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1759,6 +2824,7 @@ +@@ -1759,6 +2818,7 @@ @Override public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel()); @@ -1649,7 +1643,7 @@ this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packetplayinenchantitem.getContainerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1801,6 +2867,43 @@ +@@ -1801,6 +2861,43 @@ boolean flag1 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty(); @@ -1693,7 +1687,7 @@ if (flag1 && flag2) { this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).setByPlayer(itemstack); -@@ -1823,6 +2926,7 @@ +@@ -1823,6 +2920,7 @@ } private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List list) { @@ -1701,7 +1695,7 @@ this.player.resetLastActionTime(); WorldServer worldserver = this.player.serverLevel(); BlockPosition blockposition = packetplayinupdatesign.getPos(); -@@ -1843,6 +2947,7 @@ +@@ -1843,6 +2941,7 @@ @Override public void handleKeepAlive(PacketPlayInKeepAlive packetplayinkeepalive) { @@ -1709,7 +1703,7 @@ if (this.keepAlivePending && packetplayinkeepalive.getId() == this.keepAliveChallenge) { int i = (int) (SystemUtils.getMillis() - this.keepAliveTime); -@@ -1857,7 +2962,17 @@ +@@ -1857,7 +2956,17 @@ @Override public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel()); @@ -1728,7 +1722,7 @@ } @Override -@@ -1866,8 +2981,50 @@ +@@ -1866,8 +2975,50 @@ this.player.updateOptions(packetplayinsettings); }