mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
98 lines
5.8 KiB
Diff
98 lines
5.8 KiB
Diff
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
|
|
|
|
Original license: GPLv3
|
|
Original project: https://github.com/LeavesMC/Leaves
|
|
|
|
Commit: f553c53e4230aa032e54a69b6479f1959ed24a60
|
|
|
|
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 93572d8cc3cff757f36387940dd593885b95ff82..ea5ce91b7114149f2e0f77978ecd1bb15062be71 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -1748,6 +1748,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
GameTestTicker.SINGLETON.tick();
|
|
}
|
|
|
|
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleTick(); // Leaves - protocol
|
|
+
|
|
for (int i = 0; i < this.tickables.size(); i++) {
|
|
this.tickables.get(i).run();
|
|
}
|
|
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index 921ad69b699f693e3dfc8d912b0f1a05d8f81743..285af1576d6bef09f094b7e990b5bcd6eafda71f 100644
|
|
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -151,6 +151,11 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
|
|
@Override
|
|
public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
|
|
+ // Leaves start - protocol
|
|
+ if (packet.payload() instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload<?> 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;
|
|
@@ -210,6 +215,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();
|