From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Thu, 10 Jul 2025 22:11:47 +0300 Subject: [PATCH] Leaves: Protocol Core Original project: https://github.com/LeavesMC/Leaves Original license: GPLv3 diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java index fb263fa1f30a7dfcb7ec2656abfb38e5fe88eac9..c3be4c2fd4a544967322a45d3b8c0fe78a0684a5 100644 --- a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java +++ b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java @@ -40,13 +40,22 @@ public interface CustomPacketPayload { @Override public void encode(B buffer, CustomPacketPayload value) { + // DivineMC start - Leaves Protocol Core + if (value instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload payload) { + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.encode(buffer, payload); + return; + } + // DivineMC end - Leaves Protocol Core this.writeCap(buffer, value.type(), value); } @Override public CustomPacketPayload decode(B buffer) { ResourceLocation resourceLocation = buffer.readResourceLocation(); - return (CustomPacketPayload)this.findCodec(resourceLocation).decode(buffer); + // DivineMC start - Leaves Protocol Core + var payload = org.leavesmc.leaves.protocol.core.LeavesProtocolManager.decode(resourceLocation, buffer); + return java.util.Objects.requireNonNullElseGet(payload, () -> this.findCodec(resourceLocation).decode(buffer)); + // DivineMC end - Leaves Protocol Core } }; } diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java index d73546a9f086f67bafb3ce3a2a8ed5c227abc355..5feb76f4cd7274943f1b763c5eb7071c4bf2b809 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -1848,6 +1848,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop pluginMessagerChannels; // Paper end - retain certain values + public final GameProfile profile; // DivineMC - Leaves Protocol Core public ServerCommonPacketListenerImpl(MinecraftServer server, Connection connection, CommonListenerCookie cookie) { this.server = server; @@ -75,6 +76,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack this.pluginMessagerChannels = cookie.channels(); this.keepAlive = cookie.keepAlive(); // Paper end + this.profile = cookie.gameProfile(); // DivineMC - Leaves Protocol Core } // Paper start - configuration phase API @@ -166,6 +168,18 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @Override public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { + // DivineMC start - Leaves Protocol Core + if (packet.payload() instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload leavesPayload) { + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePayload(org.leavesmc.leaves.protocol.core.ProtocolUtils.createSelector(this), leavesPayload); + return; + } + if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.DiscardedPayload(net.minecraft.resources.ResourceLocation id, byte[] data)) { + if (org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleBytebuf(org.leavesmc.leaves.protocol.core.ProtocolUtils.createSelector(this), id, io.netty.buffer.Unpooled.wrappedBuffer(data))) { + return; + } + } + // DivineMC end - Leaves Protocol Core + // Paper start if (!(packet.payload() instanceof final net.minecraft.network.protocol.common.custom.DiscardedPayload discardedPayload)) { return; @@ -231,6 +245,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack final String channel = new String(data, from, length, java.nio.charset.StandardCharsets.US_ASCII); if (register) { bridge.addChannel(channel); + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleMinecraftRegister(channel, org.leavesmc.leaves.protocol.core.ProtocolUtils.createSelector(this)); // DivineMC - Leaves Protocol Core } else { bridge.removeChannel(channel); } diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java index 9acc247ec540449a0e4cf3a5a0bc67a0e3dfbf15..bf26f788b3c77ef344f072e399cada116b95e757 100644 --- a/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java @@ -247,6 +247,8 @@ public abstract class PlayerList { return; } + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerJoin(player); // DivineMC - Leaves Protocol Core + final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage(); if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure @@ -433,6 +435,7 @@ public abstract class PlayerList { return this.remove(player, net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? player.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(player.getDisplayName()))); } public @Nullable net.kyori.adventure.text.Component remove(ServerPlayer player, net.kyori.adventure.text.Component leaveMessage) { + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerLeave(player); // DivineMC - Leaves Protocol Core // Paper end - Fix kick event leave message not being sent org.purpurmc.purpur.task.BossBarTask.removeFromAll(player.getBukkitEntity()); // Purpur - Implement TPSBar ServerLevel serverLevel = player.level(); @@ -1329,6 +1332,7 @@ public abstract class PlayerList { serverPlayer.connection.send(clientboundUpdateRecipesPacket); serverPlayer.getRecipeBook().sendInitialRecipeBook(serverPlayer); } + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleDataPackReload(); // DivineMC - Leaves Protocol Core } public boolean isAllowCommandsForAllPlayers() {