From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:00:41 +0800 Subject: [PATCH] Leaves: Protocol Core TODO: Check whether Leaves's Return-nether-portal-fix.patch improves performance and change store way to sql maybe? Original license: GPLv3 Original project: https://github.com/LeavesMC/Leaves Commit: 99b3aafce1f162c68a771fe56d77f33648636b7d diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java index fb263fa1f30a7dfcb7ec2656abfb38e5fe88eac9..7e19dfe90a63ff26f03b95891dacb7360bba5a3c 100644 --- a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java +++ b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java @@ -40,13 +40,23 @@ public interface CustomPacketPayload { @Override public void encode(B buffer, CustomPacketPayload value) { + // Leaves start - protocol core + if (value instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload payload) { + buffer.writeResourceLocation(payload.id()); + payload.write(buffer); + return; + } + // Leaves end - 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); + // Leaves start - protocol core + var payload = org.leavesmc.leaves.protocol.core.LeavesProtocolManager.decode(resourceLocation, buffer); + return java.util.Objects.requireNonNullElseGet(payload, () -> this.findCodec(resourceLocation).decode(buffer)); + // Leaves end - protocol core } }; } diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java index 047a09cf4a2c32e714aacedeccb0928ef2c7dfa9..dddbb18992348fb7e8a6552423d134809cd7fdbc 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -1747,6 +1747,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop leavesPayload) { + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePayload(player, leavesPayload); + } + // Leaves end - protocol // Paper start if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload(String brand)) { this.player.clientBrandName = brand; @@ -209,6 +214,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack final String channel = new String(data, from, length, java.nio.charset.StandardCharsets.US_ASCII); if (register) { this.getCraftPlayer().addChannel(channel); + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleMinecraftRegister(channel, player); // Leaves - protocol } else { this.getCraftPlayer().removeChannel(channel); } diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java index 9a2f2dc1eb471776de6049590cb16e8a061aa24e..e0dbafdbf36ab8597827ac7a828981013ec16bde 100644 --- a/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java @@ -341,6 +341,8 @@ public abstract class PlayerList { player.didPlayerJoinEvent = true; // Gale - EMC - do not process chat/commands before player has joined + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerJoin(player); // Leaves - protocol + final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage(); if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure @@ -518,6 +520,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 net.kyori.adventure.text.Component remove(ServerPlayer player, net.kyori.adventure.text.Component leaveMessage) { + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerLeave(player); // Leaves - protocol // Paper end - Fix kick event leave message not being sent org.purpurmc.purpur.task.BossBarTask.removeFromAll(player.getBukkitEntity()); // Purpur - Implement TPSBar ServerLevel serverLevel = player.serverLevel();