mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 08:59:23 +00:00
175 lines
8.7 KiB
Diff
175 lines
8.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Wed, 25 Jan 2023 11:03:53 +0800
|
|
Subject: [PATCH] Leaves: Appleskin Protocol
|
|
|
|
Original license: GPLv3
|
|
Original project: https://github.com/LeavesMC/Leaves
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 8f6dced165b6b35579f6efe4396864ae40a5a361..916362c7cdef8415b416d21b17d44b713f6e3160 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1587,6 +1587,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
GameTestTicker.SINGLETON.tick();
|
|
}
|
|
|
|
+ top.leavesmc.leaves.protocol.AppleSkinProtocol.tick(); // Leaves - appleskin
|
|
+
|
|
MinecraftTimings.tickablesTimer.startTiming(); // Spigot // Paper
|
|
for (int i = 0; i < this.tickables.size(); ++i) {
|
|
((Runnable) this.tickables.get(i)).run();
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 847db9e18f0eebece00d49076ee8fababcd0c700..16e1bb93dfddb647d3cd11c6b467a16a1b16d5a9 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -359,6 +359,7 @@ public abstract class PlayerList {
|
|
player.didPlayerJoinEvent = true; // Gale - EMC - do not process chat/commands before player has joined
|
|
|
|
top.leavesmc.leaves.protocol.JadeProtocol.onPlayerJoin(player); // Leaves - Jade
|
|
+ top.leavesmc.leaves.protocol.AppleSkinProtocol.onPlayerLoggedIn(player); // Leaves - appleskin
|
|
|
|
final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
|
|
|
|
@@ -609,6 +610,7 @@ public abstract class PlayerList {
|
|
return this.remove(entityplayer, net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : PaperAdventure.asAdventure(entityplayer.getDisplayName())));
|
|
}
|
|
public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer, net.kyori.adventure.text.Component leaveMessage) {
|
|
+ top.leavesmc.leaves.protocol.AppleSkinProtocol.onPlayerLoggedOut(entityplayer); // Leaves - appleskin
|
|
// Paper end
|
|
org.purpurmc.purpur.task.BossBarTask.removeFromAll(entityplayer.getBukkitEntity()); // Purpur
|
|
ServerLevel worldserver = entityplayer.serverLevel();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 98b31a9e7e5bad4cfa1f21afd6eb77dc3ea346ec..5b6c57a0ab0beb0f69ac8f53493ccfab04874cd0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -1083,6 +1083,13 @@ public final class CraftServer implements Server {
|
|
top.leavesmc.leaves.protocol.JadeProtocol.enableAllPlayer();
|
|
}
|
|
// Leaves end - Jade
|
|
+ // Leaves start - appleskin
|
|
+ if (org.dreeam.leaf.LeafConfig.appleskinProtocol) {
|
|
+ top.leavesmc.leaves.protocol.AppleSkinProtocol.enableAllPlayer();
|
|
+ } else {
|
|
+ top.leavesmc.leaves.protocol.AppleSkinProtocol.disableAllPlayer();
|
|
+ }
|
|
+ // Leaves end - appleskin
|
|
for (ServerLevel world : this.console.getAllLevels()) {
|
|
// world.serverLevelData.setDifficulty(config.difficulty); // Paper - per level difficulty
|
|
world.setSpawnSettings(world.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && config.spawnMonsters, config.spawnAnimals); // Paper - per level difficulty (from MinecraftServer#setDifficulty(ServerLevel, Difficulty, boolean))
|
|
diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
|
index 9445177d2cb64ae1cd0bd88d0c0b2ad89ef924f6..56dc6cb0b5659619ec5df42088fbecf758e652c6 100644
|
|
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
|
|
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
|
|
@@ -247,8 +247,10 @@ public class LeafConfig {
|
|
}
|
|
|
|
public static boolean jadeProtocol = false;
|
|
+ public static boolean appleskinProtocol = false;
|
|
private static void network() {
|
|
jadeProtocol = getBoolean("network.protocol.jade-protocol", jadeProtocol);
|
|
+ appleskinProtocol = getBoolean("network.protocol.appleskin-protocol", appleskinProtocol);
|
|
}
|
|
|
|
public static String sentryDsn = "";
|
|
diff --git a/src/main/java/top/leavesmc/leaves/protocol/AppleSkinProtocol.java b/src/main/java/top/leavesmc/leaves/protocol/AppleSkinProtocol.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..e471fb844c34294886b6668b04ec50986c47f9ca
|
|
--- /dev/null
|
|
+++ b/src/main/java/top/leavesmc/leaves/protocol/AppleSkinProtocol.java
|
|
@@ -0,0 +1,94 @@
|
|
+package top.leavesmc.leaves.protocol;
|
|
+
|
|
+import io.netty.buffer.Unpooled;
|
|
+import net.minecraft.network.FriendlyByteBuf;
|
|
+import net.minecraft.resources.ResourceLocation;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
+import net.minecraft.world.food.FoodData;
|
|
+import org.jetbrains.annotations.Contract;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import top.leavesmc.leaves.util.ProtocolUtils;
|
|
+
|
|
+import java.util.HashMap;
|
|
+import java.util.HashSet;
|
|
+import java.util.Map;
|
|
+import java.util.Set;
|
|
+import java.util.UUID;
|
|
+
|
|
+public class AppleSkinProtocol {
|
|
+
|
|
+ public static final String PROTOCOL_ID = "appleskin";
|
|
+
|
|
+ private static final ResourceLocation SATURATION_KEY = id("saturation_sync");
|
|
+ private static final ResourceLocation EXHAUSTION_KEY = id("exhaustion_sync");
|
|
+
|
|
+ private static final Map<UUID, Float> previousSaturationLevels = new HashMap<>();
|
|
+ private static final Map<UUID, Float> previousExhaustionLevels = new HashMap<>();
|
|
+
|
|
+ private static final float MINIMUM_EXHAUSTION_CHANGE_THRESHOLD = 0.01F;
|
|
+
|
|
+ private static final Set<ServerPlayer> players = new HashSet<>();
|
|
+
|
|
+ @Contract("_ -> new")
|
|
+ public static @NotNull ResourceLocation id(String path) {
|
|
+ return new ResourceLocation(PROTOCOL_ID, path);
|
|
+ }
|
|
+
|
|
+ public static void enableAllPlayer() {
|
|
+ for (ServerPlayer player : MinecraftServer.getServer().getPlayerList().getPlayers()) {
|
|
+ onPlayerLoggedIn(player);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void disableAllPlayer() {
|
|
+ for (ServerPlayer player : MinecraftServer.getServer().getPlayerList().getPlayers()) {
|
|
+ onPlayerLoggedOut(player);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void onPlayerLoggedIn(@NotNull ServerPlayer player) {
|
|
+ if (org.dreeam.leaf.LeafConfig.appleskinProtocol) {
|
|
+ players.add(player);
|
|
+ resetPlayerData(player);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void onPlayerLoggedOut(@NotNull ServerPlayer player) {
|
|
+ if (org.dreeam.leaf.LeafConfig.appleskinProtocol) {
|
|
+ players.remove(player);
|
|
+ resetPlayerData(player);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static void resetPlayerData(@NotNull ServerPlayer player) {
|
|
+ previousExhaustionLevels.remove(player.getUUID());
|
|
+ previousSaturationLevels.remove(player.getUUID());
|
|
+ }
|
|
+
|
|
+ public static void tick() {
|
|
+ if (org.dreeam.leaf.LeafConfig.appleskinProtocol) {
|
|
+ for (ServerPlayer player : players) {
|
|
+ FoodData data = player.getFoodData();
|
|
+
|
|
+ float saturation = data.getSaturationLevel();
|
|
+ Float previousSaturation = previousSaturationLevels.get(player.getUUID());
|
|
+ if (previousSaturation == null || saturation != previousSaturation) {
|
|
+ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
|
+ buf.writeFloat(saturation);
|
|
+ ProtocolUtils.sendPayloadPacket(player, SATURATION_KEY, buf);
|
|
+ previousSaturationLevels.put(player.getUUID(), saturation);
|
|
+ }
|
|
+
|
|
+ float exhaustion = data.getExhaustionLevel();
|
|
+ Float previousExhaustion = previousExhaustionLevels.get(player.getUUID());
|
|
+ if (previousExhaustion == null || Math.abs(exhaustion - previousExhaustion) >= MINIMUM_EXHAUSTION_CHANGE_THRESHOLD) {
|
|
+ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
|
+ buf.writeFloat(exhaustion);
|
|
+ ProtocolUtils.sendPayloadPacket(player, EXHAUSTION_KEY, buf);
|
|
+ previousExhaustionLevels.put(player.getUUID(), exhaustion);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+}
|