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 f654664fb06556125cbd2a213c9fb89eabb329e7..9c1798cca21a3f36f0347a0a4ac1fe9ababe60af 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 1ce1de38992f1368bf49432d690bebb0289a7561..713992baae023165f126e7b98c4afb2a815c1e17 100644 --- a/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java @@ -246,6 +246,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 @@ -432,6 +434,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(); @@ -1384,6 +1387,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() {