9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00

Fix async entity tracker (#241)

* Fix Multithreaded Tracker

* [ci skip] Add comments
This commit is contained in:
Creeam
2025-02-27 12:11:28 -08:00
committed by GitHub
parent 68653110bc
commit 2e5ea6957e
2 changed files with 34 additions and 1 deletions

View File

@@ -40,3 +40,34 @@ index 379c2dc1853e45a96dda9b13bf28b7e08f65658a..361f4de9cdf0f7505628a2fed2a3f536
throw new IllegalStateException(event.getEventName() + " may only be triggered synchronously."); throw new IllegalStateException(event.getEventName() + " may only be triggered synchronously.");
} }
// Leaves start - skip photographer // Leaves start - skip photographer
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 56afb317cef0e049aacdd36a1be5f9b7af4d0c77..fbb4dd93c263c898731902b73dbd1c62df1eea4b 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1970,6 +1970,26 @@ public class CraftEventFactory {
}
public static boolean handleBlockFormEvent(Level world, BlockPos pos, net.minecraft.world.level.block.state.BlockState block, int flag, @Nullable Entity entity) {
+ // Leaf start - Multithreaded tracker
+ if (org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled && Thread.currentThread() instanceof org.dreeam.leaf.async.tracker.MultithreadedTracker.MultithreadedTrackerThread) {
+ java.util.concurrent.CompletableFuture<Boolean> future = new java.util.concurrent.CompletableFuture<>();
+ net.minecraft.server.MinecraftServer.getServer().scheduleOnMain(() -> {
+ CraftBlockState blockState = CraftBlockStates.getBlockState(world, pos, flag);
+ blockState.setData(block);
+
+ BlockFormEvent event = (entity == null) ? new BlockFormEvent(blockState.getBlock(), blockState) : new EntityBlockFormEvent(entity.getBukkitEntity(), blockState.getBlock(), blockState);
+ world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (!event.isCancelled()) {
+ blockState.update(true);
+ }
+
+ future.complete(!event.isCancelled());
+ });
+
+ return future.join();
+ }
+ // Leaf end - Multithreaded tracker
CraftBlockState blockState = CraftBlockStates.getBlockState(world, pos, flag);
blockState.setData(block);

View File

@@ -1,5 +1,6 @@
package org.dreeam.leaf.util.map; package org.dreeam.leaf.util.map;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners; import com.google.common.collect.Interners;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator; import it.unimi.dsi.fastutil.objects.ObjectIterator;
@@ -9,11 +10,12 @@ import java.util.function.Function;
public class StringCanonizingOpenHashMap<T> extends Object2ObjectOpenHashMap<String, T> { public class StringCanonizingOpenHashMap<T> extends Object2ObjectOpenHashMap<String, T> {
private static final com.google.common.collect.Interner<String> KEY_INTERNER = Interners.newWeakInterner(); private static final Interner<String> KEY_INTERNER = Interners.newWeakInterner();
private static String intern(String key) { private static String intern(String key) {
return key != null ? KEY_INTERNER.intern(key) : null; return key != null ? KEY_INTERNER.intern(key) : null;
} }
public StringCanonizingOpenHashMap() { public StringCanonizingOpenHashMap() {
super(); super();
} }