Skip to content

Commit

Permalink
perf: Appleskin protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Oct 16, 2023
1 parent 42ad296 commit 3f2d80d
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions patches/server/0053-Appleskin-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Appleskin Protocol

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..a4ed856d458a231a758d58fc62227a1130410d05
index 0000000000000000000000000000000000000000..6fd6a1c9ef54c95e452e08a69f9ddb1d6600e651
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/protocol/AppleSkinProtocol.java
@@ -0,0 +1,112 @@
@@ -0,0 +1,106 @@
+package top.leavesmc.leaves.protocol;
+
+import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -52,7 +52,6 @@ index 0000000000000000000000000000000000000000..a4ed856d458a231a758d58fc62227a11
+ @ProtocolHandler.PlayerJoin
+ public static void onPlayerLoggedIn(@NotNull ServerPlayer player) {
+ if (LeavesConfig.appleskinProtocol) {
+ players.add(player);
+ resetPlayerData(player);
+ }
+ }
Expand All @@ -65,14 +64,17 @@ index 0000000000000000000000000000000000000000..a4ed856d458a231a758d58fc62227a11
+ }
+ }
+
+ @ProtocolHandler.MinecraftRegister(ignoreId = true)
+ public static void onPlayerSubscribed(@NotNull ServerPlayer player) {
+ if (LeavesConfig.appleskinProtocol) {
+ players.add(player);
+ }
+ }
+
+ @ProtocolHandler.Ticker
+ public static void tick() {
+ if (LeavesConfig.appleskinProtocol) {
+ for (ServerPlayer player : players) {
+ if (!player.getBukkitEntity().getListeningPluginChannels().contains(SATURATION_KEY.toString())) {
+ continue;
+ }
+
+ FoodData data = player.getFoodData();
+
+ float saturation = data.getSaturationLevel();
Expand All @@ -98,19 +100,11 @@ index 0000000000000000000000000000000000000000..a4ed856d458a231a758d58fc62227a11
+
+ @ProtocolHandler.ReloadServer
+ public static void onServerReload() {
+ if (LeavesConfig.appleskinProtocol) {
+ enableAllPlayer();
+ } else {
+ if (!LeavesConfig.appleskinProtocol) {
+ disableAllPlayer();
+ }
+ }
+
+ 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);
Expand Down

0 comments on commit 3f2d80d

Please sign in to comment.