mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-28 03:19:22 +00:00
Appleskin Protocol (#12)
This commit is contained in:
173
patches/server/0058-Appleskin-Protocol.patch
Normal file
173
patches/server/0058-Appleskin-Protocol.patch
Normal file
@@ -0,0 +1,173 @@
|
||||
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] Appleskin Protocol
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index f6bc15c331f22aba5cbb41261dbc10a4dc1e2a8d..a611b34058c79383db1be22e9f755e36edfa6ff1 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -1582,6 +1582,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
this.profiler.popPush("server gui refresh");
|
||||
|
||||
top.leavesmc.leaves.protocol.BBORProtocol.tick(); // Leaves - bbor
|
||||
+ top.leavesmc.leaves.protocol.AppleSkinProtocol.tick(); // Leaves - appleskin
|
||||
|
||||
MinecraftTimings.tickablesTimer.startTiming(); // Spigot // Paper
|
||||
for (int i = 0; i < this.tickables.size(); ++i) {
|
||||
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
index 9bd0c11901aa88e9bf5a036711647e1131d995fa..67c6d95e81f0df600916d797af4af552d6e77604 100644
|
||||
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
@@ -340,6 +340,7 @@ public abstract class PlayerList {
|
||||
top.leavesmc.leaves.protocol.PcaSyncProtocol.onJoin(player); // Leaves - pca
|
||||
top.leavesmc.leaves.protocol.BBORProtocol.onPlayerLoggedIn(player); // Leaves - bbor
|
||||
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();
|
||||
|
||||
@@ -583,6 +584,7 @@ public abstract class PlayerList {
|
||||
}
|
||||
public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer, net.kyori.adventure.text.Component leaveMessage) {
|
||||
top.leavesmc.leaves.protocol.BBORProtocol.onPlayerLoggedOut(entityplayer); // Leaves - bbor
|
||||
+ top.leavesmc.leaves.protocol.AppleSkinProtocol.onPlayerLoggedOut(entityplayer); // Leaves - appleskin
|
||||
// Paper end
|
||||
ServerLevel worldserver = entityplayer.getLevel();
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index b69f915226dd9cda4b5f24e307d89c19e739ab8b..1febe4e731356f9470020048bf78b1eb9ab1094f 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1001,6 +1001,13 @@ public final class CraftServer implements Server {
|
||||
top.leavesmc.leaves.protocol.JadeProtocol.enableAllPlayer();
|
||||
}
|
||||
// Leaves end - Jade
|
||||
+ // Leaves start - appleskin
|
||||
+ if (top.leavesmc.leaves.LeavesConfig.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/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
||||
index 17ffd0ae638f44b1bcf945640e430e9b753ba3f9..b3d94da02fb25863c37a385d25bb7acced0a7837 100644
|
||||
--- a/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
||||
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
|
||||
@@ -481,6 +481,11 @@ public final class LeavesConfig {
|
||||
}
|
||||
}
|
||||
|
||||
+ public static boolean appleskinProtocol = false;
|
||||
+ private static void appleskinProtocol() {
|
||||
+ appleskinProtocol = getBoolean("settings.protocol.appleskin-protocol", appleskinProtocol);
|
||||
+ }
|
||||
+
|
||||
public static final class WorldConfig {
|
||||
|
||||
public final String worldName;
|
||||
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..6f0b2140df822dc86e360837780768f2f5203041
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/protocol/AppleSkinProtocol.java
|
||||
@@ -0,0 +1,95 @@
|
||||
+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.LeavesConfig;
|
||||
+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 (LeavesConfig.appleskinProtocol) {
|
||||
+ players.add(player);
|
||||
+ resetPlayerData(player);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public static void onPlayerLoggedOut(@NotNull ServerPlayer player) {
|
||||
+ if (LeavesConfig.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 (LeavesConfig.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);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user