diff --git a/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java b/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java index e44f7f14..2cfc7ce4 100644 --- a/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java +++ b/DynmapCore/src/main/java/org/dynmap/common/chunk/GenericMapChunkCache.java @@ -39,7 +39,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache { private int snapcnt; private GenericChunk[] snaparray; /* Index = (x-x_min) + ((z-z_min)*x_dim) */ private boolean[][] isSectionNotEmpty; /* Indexed by snapshot index, then by section index */ - private AtomicInteger loadingChunks = new AtomicInteger(0); //the amount of threads loading threads at this moment, used by async loading + private AtomicInteger loadingChunks = new AtomicInteger(0); //the amount of threads loading chunks at this moment, used by async loading private static final BlockStep unstep[] = { BlockStep.X_MINUS, BlockStep.Y_MINUS, BlockStep.Z_MINUS, BlockStep.X_PLUS, BlockStep.Y_PLUS, BlockStep.Z_PLUS }; @@ -924,7 +924,7 @@ public abstract class GenericMapChunkCache extends MapChunkCache { } public void readChunksAsync() { - class SimplePair { + class SimplePair { //pair of the chunk and the data which is readed async private final Supplier supplier; private final DynmapChunk chunk; diff --git a/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/AsyncChunkProvider118_2.java b/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/AsyncChunkProvider118_2.java index ef1df618..9c21562d 100644 --- a/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/AsyncChunkProvider118_2.java +++ b/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/AsyncChunkProvider118_2.java @@ -16,10 +16,10 @@ import java.util.function.Predicate; * Because paper libs need java 17 we can't interact with them directly */ public class AsyncChunkProvider118_2 { - private static final Thread ioThread; - private static final Method getChunk; - private static final Predicate ifFailed; - static { + private final Thread ioThread; + private final Method getChunk; + private final Predicate ifFailed; + AsyncChunkProvider118_2 () { try { Predicate ifFailed1 = null; Method getChunk1 = null; diff --git a/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/MapChunkCache118_2.java b/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/MapChunkCache118_2.java index 236fe894..3971de10 100644 --- a/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/MapChunkCache118_2.java +++ b/bukkit-helper-118-2/src/main/java/org/dynmap/bukkit/helper/v118_2/MapChunkCache118_2.java @@ -26,7 +26,7 @@ import java.util.function.Supplier; * Container for managing chunks - dependent upon using chunk snapshots, since rendering is off server thread */ public class MapChunkCache118_2 extends GenericMapChunkCache { - private final AsyncChunkProvider118_2 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider118_2(); + private static final AsyncChunkProvider118_2 provider = BukkitVersionHelper.helper.isUnsafeAsync() ? null : new AsyncChunkProvider118_2(); private World w; /** * Construct empty cache @@ -52,9 +52,8 @@ public class MapChunkCache118_2 extends GenericMapChunkCache { NBTTagCompound compound = nbt.join(); return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound)); }; - } catch (InvocationTargetException | IllegalAccessException e) { - e.printStackTrace(); - return () -> loadChunk(chunk); + } catch (InvocationTargetException | IllegalAccessException ignored) { + return () -> null; } } @@ -63,9 +62,12 @@ public class MapChunkCache118_2 extends GenericMapChunkCache { if (!cw.isChunkLoaded(chunk.x, chunk.z)) return () -> null; Chunk c = cw.getHandle().getChunkIfLoaded(chunk.x, chunk.z); //already safe async on vanilla if ((c == null) || c.o) return () -> null; // c.loaded - if (async) { //idk why, but paper uses this only sync, so I won't be smarter + if (async) { //the data of the chunk may change while we write, better to write it sync CompletableFuture nbt = CompletableFuture.supplyAsync(() -> ChunkRegionLoader.a(cw.getHandle(), c), ((CraftServer) Bukkit.getServer()).getServer()); - return () -> parseChunkFromNBT(new NBT.NBTCompound(nbt.join())); + return () -> { + NBTTagCompound compound = nbt.join(); + return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound)); + }; } else { NBTTagCompound nbt = ChunkRegionLoader.a(cw.getHandle(), c); GenericChunk genericChunk; diff --git a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index 9ac97138..a426a840 100644 --- a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -482,7 +482,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { boolean rslt = permissions.hasOfflinePermission(player, perm); return rslt; } - private final Object[] lock = {}; /** * Render processor helper - used by code running on render threads to request chunk snapshot cache from server/sync thread */