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: 0O0oO00o0oO diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java index fb263fa1f30a7dfcb7ec2656abfb38e5fe88eac9..96ec0a0133ec244a5eb79dfcb34e7f9de22ea0f4 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 leavesCustomPayload) { + buffer.writeResourceLocation(leavesCustomPayload.id()); + leavesCustomPayload.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 leavesCustomPayload = org.leavesmc.leaves.protocol.core.LeavesProtocolManager.decode(resourceLocation, buffer); + return java.util.Objects.requireNonNullElseGet(leavesCustomPayload, () -> this.findCodec(resourceLocation).decode(buffer)); + // Leaves end - protocol core } }; } diff --git a/net/minecraft/resources/ResourceLocation.java b/net/minecraft/resources/ResourceLocation.java index ea8cfa76093c70a44d065c1f80adaa9127fe4e07..7435e2c3f0defe98cbaa488219974887ee572c57 100644 --- a/net/minecraft/resources/ResourceLocation.java +++ b/net/minecraft/resources/ResourceLocation.java @@ -36,7 +36,7 @@ public final class ResourceLocation implements Comparable { private final String namespace; private final String path; - private ResourceLocation(String namespace, String path) { + public ResourceLocation(String namespace, String path) { // Leaves - private -> public assert isValidNamespace(namespace); assert isValidPath(path); 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 // CraftBukkit start // Paper start - Brand support if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload(String brand)) { @@ -169,6 +174,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack String channels = payload.toString(com.google.common.base.Charsets.UTF_8); for (String channel : channels.split("\0")) { this.getCraftPlayer().addChannel(channel); + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleMinecraftRegister(channel, player); // Leaves - protocol } } catch (Exception ex) { ServerGamePacketListenerImpl.LOGGER.error("Couldn't register custom payload", ex); diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java index d2c11832d3ff9b01ccc3cdd5f77673eb7a844dae..0e81a445a4f960eab5c873bc16f79a9ebfab0122 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();