Compare commits

...

2 Commits

Author SHA1 Message Date
M2ke4U
1d4276694e Update 0045-Leaves-PCA-sync-protocol.patch 2023-12-24 16:33:23 +08:00
M2ke4U
3bca6a9846 Fix threading issue in PCA sync protocol 2023-12-24 14:51:16 +08:00

View File

@@ -3,7 +3,19 @@ From: M2ke4U <79621885+MrHua269@users.noreply.github.com>
Date: Sun, 17 Dec 2023 21:01:59 +0800
Subject: [PATCH] Leaves PCA sync protocol
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 2c3e1b420303a3c3a9315983fbc7e47423f7d9e4..29a8331e498eba333283b41c3e6a87a7ad97747c 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -45,7 +45,7 @@ import org.bukkit.scheduler.BukkitWorker;
*/
public class CraftScheduler implements BukkitScheduler {
- static Plugin MINECRAFT = new MinecraftInternalPlugin();
+ public static Plugin MINECRAFT = new MinecraftInternalPlugin();
/**
* The start ID for the counter.
*/
diff --git a/src/main/java/me/earthme/luminol/LuminolConfig.java b/src/main/java/me/earthme/luminol/LuminolConfig.java
index a62680768068b611fe723fedeb617d42c643e59e..cfe9a8eb705039ee7e2dc9262e1355c4b0f664bb 100644
--- a/src/main/java/me/earthme/luminol/LuminolConfig.java
@@ -306,10 +318,10 @@ index 1fa22445a4ecc8c08dbcf0cc6bd39dc5003604c4..c1492fce06cdc00a8e82977f0c474a54
return ShulkerBoxBlockEntity.SLOTS;
diff --git a/src/main/java/top/leavesmc/leaves/protocol/PcaSyncProtocol.java b/src/main/java/top/leavesmc/leaves/protocol/PcaSyncProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..946b4183c7ae438bff5938115961057759c77dac
index 0000000000000000000000000000000000000000..ebd28033ddf0fe6a354585dc2818a9b481d90ed4
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/protocol/PcaSyncProtocol.java
@@ -0,0 +1,382 @@
@@ -0,0 +1,384 @@
+package top.leavesmc.leaves.protocol;
+
+import net.minecraft.core.BlockPos;
@@ -331,6 +343,7 @@ index 0000000000000000000000000000000000000000..946b4183c7ae438bff59381159610577
+import org.apache.commons.lang3.tuple.MutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.logging.log4j.LogManager;
+import org.bukkit.craftbukkit.scheduler.CraftScheduler;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
@@ -344,6 +357,7 @@ index 0000000000000000000000000000000000000000..946b4183c7ae438bff59381159610577
+import java.util.Set;
+import java.util.concurrent.locks.ReentrantLock;
+
+import static org.bukkit.craftbukkit.scheduler.CraftScheduler.MINECRAFT;
+import static top.leavesmc.leaves.protocol.core.LeavesProtocolManager.EmptyPayload;
+
+@LeavesProtocol(namespace = "pca")
@@ -413,7 +427,7 @@ index 0000000000000000000000000000000000000000..946b4183c7ae438bff59381159610577
+ BlockPos pos = payload.pos;
+ ServerLevel world = player.serverLevel();
+
+ server.execute(() -> {
+ player.getBukkitEntity().getScheduler().execute(MINECRAFT,() -> {
+ BlockState blockState = world.getBlockState(pos);
+ clearPlayerWatchData(player);
+
@@ -444,7 +458,7 @@ index 0000000000000000000000000000000000000000..946b4183c7ae438bff59381159610577
+ }
+ blockPosWatchPlayerSet.get(pair).add(player);
+ lock.unlock();
+ });
+ },null,1);
+ }
+
+ @ProtocolHandler.PayloadReceiver(payload = SyncEntityPayload.class, payloadId = "sync_entity")
@@ -455,7 +469,7 @@ index 0000000000000000000000000000000000000000..946b4183c7ae438bff59381159610577
+ MinecraftServer server = MinecraftServer.getServer();
+ int entityId = payload.entityId;
+ ServerLevel world = player.serverLevel();
+ server.execute(() -> {
+ player.getBukkitEntity().getScheduler().execute(MINECRAFT,() -> {
+ Entity entity = world.getEntity(entityId);
+ if (entity != null) {
+ clearPlayerWatchData(player);
@@ -488,7 +502,7 @@ index 0000000000000000000000000000000000000000..946b4183c7ae438bff59381159610577
+ entityWatchPlayerSet.get(pair).add(player);
+ lock.unlock();
+ }
+ });
+ },null,1);
+ }
+
+ public static void enablePcaSyncProtocol(@NotNull ServerPlayer player) {