aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0393-Brand-support.patch
blob: af42b533fd9300ba6a467cf3436850a777ceff84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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


diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index e6e7dc17d1196a8211a565355f34b5dcfd478852..45181bc9c422507682d479e4d43177ecd3253971 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -294,6 +294,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
     // CraftBukkit end
     public boolean isRealPlayer; // Paper
     public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
+    public @Nullable String clientBrandName = null; // Paper - Brand support
 
     public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
         super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index 4f62abfe62c951b7a1df36ece34747100d6a4ff7..48085b2e7197dc44e76b812bdd514af729e21e83 100644
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -83,6 +83,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
     private volatile boolean suspendFlushingOnServerThread = false;
     public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks
     private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
+    protected static final ResourceLocation MINECRAFT_BRAND = ResourceLocation.withDefaultNamespace("brand"); // Paper - Brand support
 
     public ServerCommonPacketListenerImpl(MinecraftServer minecraftserver, Connection networkmanager, CommonListenerCookie commonlistenercookie, ServerPlayer player) { // CraftBukkit
         this.server = minecraftserver;
@@ -148,6 +149,11 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
 
     @Override
     public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
+        // Paper start - Brand support
+        if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload brandPayload) {
+            this.player.clientBrandName = brandPayload.brand();
+        }
+        // Paper end - Brand support
         if (!(packet.payload() instanceof DiscardedPayload)) {
             return;
         }
@@ -179,6 +185,15 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
             try {
                 byte[] data = new byte[payload.readableBytes()];
                 payload.readBytes(data);
+                // Paper start - Brand support; Retain this incase upstream decides to 'break' the new mechanism in favour of backwards compat...
+                if (identifier.equals(MINECRAFT_BRAND)) {
+                    try {
+                        this.player.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.copiedBuffer(data)).readUtf(256);
+                    } catch (StringIndexOutOfBoundsException ex) {
+                        this.player.clientBrandName = "illegal";
+                    }
+                }
+                // Paper end - Brand support
                 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
index 068ff2c228308ec87fcc6d1352bd63b91bd34a93..854533854dfba24b59a15265ac759331e3ddfc74 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3139,6 +3139,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
         // Paper end
     };
 
+    // Paper start - brand support
+    @Override
+    public String getClientBrandName() {
+        return getHandle().clientBrandName;
+    }
+    // Paper end
+
     public Player.Spigot spigot()
     {
         return this.spigot;