Skip to content

Commit

Permalink
Keep newlines in outdated client/server message (#10042)
Browse files Browse the repository at this point in the history
  • Loading branch information
Warriorrrr authored Dec 26, 2023
1 parent c215ce1 commit 4fdda9e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ Subject: [PATCH] Fix hex colors not working in some kick messages


diff --git a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
index 21aafb1ea51769659462d722aa318460b37cbc1c..ea4a7186b707e471d5f3972d21502b7a316e0d55 100644
index 21aafb1ea51769659462d722aa318460b37cbc1c..5d7f092e966d5b0496f48bd5c9d274157ac6d250 100644
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
@@ -77,12 +77,12 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
@@ -77,14 +77,16 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
}
// CraftBukkit end
if (packet.protocolVersion() != SharedConstants.getCurrentVersion().getProtocolVersion()) {
- MutableComponent ichatmutablecomponent;
+ Component ichatmutablecomponent; // Paper - Fix hex colors not working in some kick messages
+ net.kyori.adventure.text.Component adventureComponent; // Paper - Fix hex colors not working in some kick messages

if (packet.protocolVersion() < SharedConstants.getCurrentVersion().getProtocolVersion()) { // Spigot - SPIGOT-7546: Handle version check correctly for outdated client message
- ichatmutablecomponent = Component.literal( java.text.MessageFormat.format( org.spigotmc.SpigotConfig.outdatedClientMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName() ) ); // Spigot
+ ichatmutablecomponent = org.bukkit.craftbukkit.util.CraftChatMessage.fromString( java.text.MessageFormat.format( org.spigotmc.SpigotConfig.outdatedClientMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName() ) )[0]; // Spigot // Paper - Fix hex colors not working in some kick messages
+ adventureComponent = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(java.text.MessageFormat.format(org.spigotmc.SpigotConfig.outdatedClientMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName())); // Spigot // Paper - Fix hex colors not working in some kick messages
} else {
- ichatmutablecomponent = Component.literal( java.text.MessageFormat.format( org.spigotmc.SpigotConfig.outdatedServerMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName() ) ); // Spigot
+ ichatmutablecomponent = org.bukkit.craftbukkit.util.CraftChatMessage.fromString( java.text.MessageFormat.format( org.spigotmc.SpigotConfig.outdatedServerMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName() ) )[0]; // Spigot // Paper - Fix hex colors not working in some kick messages
+ adventureComponent = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(java.text.MessageFormat.format(org.spigotmc.SpigotConfig.outdatedServerMessage.replaceAll("'", "''"), SharedConstants.getCurrentVersion().getName())); // Spigot // Paper - Fix hex colors not working in some kick messages
}

+ Component ichatmutablecomponent = io.papermc.paper.adventure.PaperAdventure.asVanilla(adventureComponent); // Paper
+
this.connection.send(new ClientboundLoginDisconnectPacket(ichatmutablecomponent));
this.connection.disconnect(ichatmutablecomponent);
} else {
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 615fb00e50f3c434809f8e1b201d457b9beae8fd..c58fc7d950ea2aa136c3922fb14e4f183f45f2d3 100644
index 615fb00e50f3c434809f8e1b201d457b9beae8fd..faf1ae03a308ad07091e3e847370e9bda66288b2 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -99,7 +99,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
// CraftBukkit start
@Deprecated
public void disconnect(String s) {
- this.disconnect(Component.literal(s));
+ this.disconnect(org.bukkit.craftbukkit.util.CraftChatMessage.fromString(s, true)[0]); // Paper - Fix hex colors not working in some kick messages
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s))); // Paper - Fix hex colors not working in some kick messages
}
// CraftBukkit end

4 changes: 2 additions & 2 deletions patches/server/0565-Add-bypass-host-check.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Paper.bypassHostCheck
Seriously, fix your firewalls. -.-

diff --git a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
index 2ee5c884571228a353120f658f1a2d39373ea4ca..bb8ba0ba5c70f321d4fd195f14cfb4d75ec0e42f 100644
index 5d7f092e966d5b0496f48bd5c9d274157ac6d250..3068e25f2df958689627fb31783a2d356547f1be 100644
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
@@ -30,6 +30,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
Expand All @@ -19,7 +19,7 @@ index 2ee5c884571228a353120f658f1a2d39373ea4ca..bb8ba0ba5c70f321d4fd195f14cfb4d7

public ServerHandshakePacketListenerImpl(MinecraftServer server, Connection connection) {
this.server = server;
@@ -127,7 +128,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
@@ -129,7 +130,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
if (!handledByEvent && proxyLogicEnabled) {
// Paper end
// if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0596-Add-Unix-domain-socket-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ index 598e3ae877f014ce979d8a578445f8a314f0ba82..b7e6c7fdccb91f3cef5e6d96fe5f0c2e
}
// Spigot End
diff --git a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
index bb8ba0ba5c70f321d4fd195f14cfb4d75ec0e42f..0b3d6b309ea653d44bcfcd6dd418f692e040c87b 100644
index 3068e25f2df958689627fb31783a2d356547f1be..d2edc000f34d7f07a840bb8012c6f884f37e387b 100644
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
@@ -45,6 +45,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
Expand All @@ -128,7 +128,7 @@ index bb8ba0ba5c70f321d4fd195f14cfb4d75ec0e42f..0b3d6b309ea653d44bcfcd6dd418f692
} catch (Throwable t) {
org.apache.logging.log4j.LogManager.getLogger().debug("Failed to check connection throttle", t);
}
@@ -129,8 +131,11 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
@@ -131,8 +133,11 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL
// Paper end
// if (org.spigotmc.SpigotConfig.bungee) { // Paper - comment out, we check above!
if ( ( split.length == 3 || split.length == 4 ) && ( ServerHandshakePacketListenerImpl.BYPASS_HOSTCHECK || ServerHandshakePacketListenerImpl.HOST_PATTERN.matcher( split[1] ).matches() ) ) { // Paper
Expand Down

0 comments on commit 4fdda9e

Please sign in to comment.