c8b50d84a9
Co-authored-by: MrHua269 <mrhua269@gmail.com>
127 lines
7.7 KiB
Diff
127 lines
7.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
Date: Sun, 3 Aug 2025 15:24:01 +0800
|
|
Subject: [PATCH] Leaves: Leaves Base Protocol Core
|
|
|
|
Co-authored by: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
As a part of : Leaves (https://github.com/LeavesMC/Leaves/blob/9d2bd3f7b0a48f00df7bc8c74292338ed9c3a458/leaves-server/minecraft-patches/features/0122-Leaves-Protocol-Core.patch)
|
|
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
|
|
diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
|
|
index 08e253662a2c183c0ab53a51cc07485cff33bf2c..1bd678d668a1febc129f4cb4d0d95ea27acc4252 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(final B output, final CustomPacketPayload value) {
|
|
+ // Leaves start - protocol core
|
|
+ if (value instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload payload) {
|
|
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.encode(output, payload);
|
|
+ return;
|
|
+ }
|
|
+ // Leaves end - protocol core
|
|
this.writeCap(output, value.type(), value);
|
|
}
|
|
|
|
@Override
|
|
public CustomPacketPayload decode(final B input) {
|
|
Identifier identifier = input.readIdentifier();
|
|
- return (CustomPacketPayload)this.findCodec(identifier).decode(input);
|
|
+ // Leaves start - protocol core
|
|
+ var payload = org.leavesmc.leaves.protocol.core.LeavesProtocolManager.decode(identifier, input);
|
|
+ return java.util.Objects.requireNonNullElseGet(payload, () -> (CustomPacketPayload) this.findCodec(identifier).decode(input));
|
|
+ // Leaves end - protocol core
|
|
}
|
|
};
|
|
}
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index e7f7f7927fc1e2ce45ea5dbf7cc9ec19197c599f..1f13f7b016b4256e92989d83003a983d6ba1c750 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -2016,6 +2016,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
|
|
profiler.popPush("server gui refresh");
|
|
|
|
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleTick(); // Leaves - protocol // Lophine - we don't have tickCount to use, remove it
|
|
+
|
|
if (false) for (Runnable tickable : this.tickables) { // Folia - region threading - TODO WTF is this?
|
|
tickable.run();
|
|
}
|
|
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index 010180899d69d0457dcc9feee4f1c062c5354995..279b5072596c062a7c800510ed914a9df8ce0698 100644
|
|
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -57,6 +57,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
public @Nullable String clientBrand;
|
|
public final java.util.Set<String> pluginMessagerChannels;
|
|
// Paper end - retain certain values
|
|
+ public final GameProfile profile; // Leaves - protocol core
|
|
|
|
public ServerCommonPacketListenerImpl(final MinecraftServer server, final Connection connection, final CommonListenerCookie cookie) {
|
|
this.server = server;
|
|
@@ -70,6 +71,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
this.pluginMessagerChannels = cookie.channels();
|
|
this.keepAlive = cookie.keepAlive();
|
|
// Paper end
|
|
+ this.profile = cookie.gameProfile(); // Leaves - protocol core
|
|
}
|
|
|
|
// Paper start - configuration phase API
|
|
@@ -143,6 +145,18 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
|
|
@Override
|
|
public void handleCustomPayload(final ServerboundCustomPayloadPacket packet) {
|
|
+ // Leaves start - protocol
|
|
+ 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.Identifier 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;
|
|
+ }
|
|
+ }
|
|
+ // Leaves end - protocol
|
|
+
|
|
// Paper start
|
|
if (!(packet.payload() instanceof final net.minecraft.network.protocol.common.custom.DiscardedPayload discardedPayload)) {
|
|
return;
|
|
@@ -202,6 +216,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)); // Leaves - protocol
|
|
} else {
|
|
bridge.removeChannel(channel);
|
|
}
|
|
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
|
|
index 8b7e4814b00d6f6c9f25cce5186905f165b97c2f..5bfc986f3d8dc81444be857c857bd91ada8c409d 100644
|
|
--- a/net/minecraft/server/players/PlayerList.java
|
|
+++ b/net/minecraft/server/players/PlayerList.java
|
|
@@ -318,6 +318,8 @@ public abstract class PlayerList {
|
|
//return; // Folia - region threading - must still allow the player to connect, as we must add to chunk map before handling disconnect
|
|
}
|
|
|
|
+ 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
|
|
@@ -514,6 +516,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.@Nullable Component remove(final ServerPlayer player, final 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
|
|
ServerLevel level = player.level();
|
|
player.awardStat(Stats.LEAVE_GAME);
|
|
@@ -1417,6 +1420,7 @@ public abstract class PlayerList {
|
|
player.connection.send(recipes);
|
|
player.getRecipeBook().sendInitialRecipeBook(player);
|
|
}
|
|
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleDataPackReload(); // Leaves - protocol core
|
|
}
|
|
|
|
public boolean isAllowCommandsForAllPlayers() {
|