2023-09-22 06:40:51 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: DigitalRegent <misterwener@gmail.com>
Date: Sat, 11 Apr 2020 13:10:58 +0200
Subject: [PATCH] Brand support
2023-10-08 12:07:48 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-06-13 22:57:13 +02:00
index b808d9c710d6cd59ac34ea537f603fd4002073d0..45d36070735cd7a8baee585165a95a169d7059b4 100644
2023-10-08 12:07:48 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-06-13 22:57:13 +02:00
@@ -294,6 +294,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
2023-10-08 12:07:48 +02:00
public boolean isRealPlayer; // Paper
public final com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> cachedSingleHashSet; // Paper
2024-01-22 18:04:55 +01:00
public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
2024-01-20 23:13:41 +01:00
+ public @Nullable String clientBrandName = null; // Paper - Brand support
2023-10-08 12:07:48 +02:00
2024-01-24 15:57:53 +01:00
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
2023-09-22 06:40:51 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
2024-06-14 01:32:45 +02:00
index 2d1fad00ee084841618f0da8113c7aac8c0e2b0d..a3c67bdc2c08b3550534f37d15b0db90b479e34f 100644
2023-09-22 06:40:51 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
2024-06-13 22:57:13 +02:00
@@ -78,6 +78,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-22 06:40:51 +02:00
private volatile boolean suspendFlushingOnServerThread = false;
2023-12-25 11:51:44 +01:00
public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks
2023-09-22 06:40:51 +02:00
private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
2024-06-14 01:32:45 +02:00
+ protected static final ResourceLocation MINECRAFT_BRAND = ResourceLocation.withDefaultNamespace("brand"); // Paper - Brand support
2023-09-22 06:40:51 +02:00
public ServerCommonPacketListenerImpl(MinecraftServer minecraftserver, Connection networkmanager, CommonListenerCookie commonlistenercookie, ServerPlayer player) { // CraftBukkit
this.server = minecraftserver;
2024-06-13 22:57:13 +02:00
@@ -143,6 +144,11 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-24 20:48:29 +02:00
@Override
public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
2024-01-20 23:13:41 +01:00
+ // Paper start - Brand support
2023-09-24 20:48:29 +02:00
+ if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload brandPayload) {
2023-10-08 12:07:48 +02:00
+ this.player.clientBrandName = brandPayload.brand();
2023-09-24 20:48:29 +02:00
+ }
2024-01-20 23:13:41 +01:00
+ // Paper end - Brand support
2024-04-24 14:11:27 +02:00
if (!(packet.payload() instanceof DiscardedPayload)) {
2023-09-24 20:48:29 +02:00
return;
}
2024-06-13 22:57:13 +02:00
@@ -174,6 +180,15 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
2023-09-22 06:40:51 +02:00
try {
byte[] data = new byte[payload.readableBytes()];
payload.readBytes(data);
2024-01-20 23:13:41 +01:00
+ // Paper start - Brand support; Retain this incase upstream decides to 'break' the new mechanism in favour of backwards compat...
2023-09-22 06:40:51 +02:00
+ if (identifier.equals(MINECRAFT_BRAND)) {
+ try {
2023-10-08 12:07:48 +02:00
+ this.player.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.copiedBuffer(data)).readUtf(256);
2023-09-22 06:40:51 +02:00
+ } catch (StringIndexOutOfBoundsException ex) {
2023-10-08 12:07:48 +02:00
+ this.player.clientBrandName = "illegal";
2023-09-22 06:40:51 +02:00
+ }
+ }
2024-01-20 23:13:41 +01:00
+ // Paper end - Brand support
2023-09-22 06:40:51 +02:00
this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), identifier.toString(), data);
} catch (Exception ex) {
ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2024-06-13 22:57:13 +02:00
index e837939d35ee168f5640b28fae07675817492cb9..8b89959fa688f17ea9f16597cc0cc49f1d94a0ff 100644
2023-09-22 06:40:51 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2024-06-13 22:57:13 +02:00
@@ -3134,6 +3134,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2023-09-22 06:40:51 +02:00
// Paper end
};
+ // Paper start - brand support
+ @Override
+ public String getClientBrandName() {
2023-10-08 12:07:48 +02:00
+ return getHandle().clientBrandName;
2023-09-22 06:40:51 +02:00
+ }
+ // Paper end
+
public Player.Spigot spigot()
{
return this.spigot;