From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: DigitalRegent Date: Sat, 11 Apr 2020 13:10:58 +0200 Subject: [PATCH] Brand support diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java index d1808bf9dc19fad84da5eb3b4c3d549bc624b00a..cce6febce229abdad859f183716cdefbec4a8f2e 100644 --- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java @@ -54,6 +54,8 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack private int latency; private volatile boolean suspendFlushingOnServerThread = false; private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit + private @Nullable String clientBrandName = null; // Paper - Brand name + protected static final ResourceLocation MINECRAFT_BRAND = new ResourceLocation("brand"); // Paper - Brand support public ServerCommonPacketListenerImpl(MinecraftServer minecraftserver, Connection networkmanager, CommonListenerCookie commonlistenercookie, ServerPlayer player) { // CraftBukkit this.server = minecraftserver; @@ -140,6 +142,15 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack try { byte[] data = new byte[payload.readableBytes()]; payload.readBytes(data); + // Paper start - Brand support + if (identifier.equals(MINECRAFT_BRAND)) { + try { + this.clientBrandName = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.copiedBuffer(data)).readUtf(256); + } catch (StringIndexOutOfBoundsException ex) { + this.clientBrandName = "illegal"; + } + } + // Paper end this.cserver.getMessenger().dispatchIncomingMessage(this.player.getBukkitEntity(), identifier.toString(), data); } catch (Exception ex) { ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex); @@ -149,6 +160,13 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack } + // Paper start - brand support + @Nullable + public String getClientBrandName() { + return this.clientBrandName; + } + // Paper end + public final boolean isDisconnected() { return (!this.player.joining && !this.connection.isConnected()) || this.processedDisconnect; // Paper } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index e28872e0f86a0106e4ea4e06d1ea8e41128de5c7..a32084082239b71222e72e8d7a1e1b84333d775e 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -2965,6 +2965,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player { // Paper end }; + // Paper start - brand support + @Override + public String getClientBrandName() { + return getHandle().connection != null ? getHandle().connection.getClientBrandName() : null; + } + // Paper end + public Player.Spigot spigot() { return this.spigot;