From 1ede11b12910b288fe8d63c0d68a9e6dcdc48e6b Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 19 Jun 2023 15:34:02 +0200 Subject: [PATCH] fix: use new array when creating palette (#2305) - Fixes #2291 --- .../bukkit/adapter/NMSAdapter.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java index a69d7865f..b41da1679 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/NMSAdapter.java @@ -30,7 +30,8 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { ordinal = BlockTypesCache.ReservedIDs.AIR; nonAir--; } - case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--; + case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> + nonAir--; } int palette = blockToPalette[ordinal]; if (palette == Integer.MAX_VALUE) { @@ -73,6 +74,8 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { CachedBukkitAdapter adapter, short[] nonEmptyBlockCount ) { + // Write to new array to avoid editing SET array + char[] copy = new char[set.length]; short nonAir = 4096; int num_palette = 0; char[] getArr = null; @@ -83,23 +86,19 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { if (getArr == null) { getArr = get.apply(layer); } - // write to set array as this should be a copied array, and will be important when the changes are written - // to the GET chunk cached by FAWE - set[i] = switch (ordinal = getArr[i]) { + switch (ordinal = getArr[i]) { case BlockTypesCache.ReservedIDs.__RESERVED__ -> { nonAir--; - yield (ordinal = BlockTypesCache.ReservedIDs.AIR); + ordinal = BlockTypesCache.ReservedIDs.AIR; } - case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, - BlockTypesCache.ReservedIDs.VOID_AIR -> { - nonAir--; - yield ordinal; - } - default -> ordinal; - }; + case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> + nonAir--; + } } - case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> nonAir--; + case BlockTypesCache.ReservedIDs.AIR, BlockTypesCache.ReservedIDs.CAVE_AIR, BlockTypesCache.ReservedIDs.VOID_AIR -> + nonAir--; } + copy[i] = ordinal; int palette = blockToPalette[ordinal]; if (palette == Integer.MAX_VALUE) { blockToPalette[ordinal] = num_palette; @@ -117,7 +116,7 @@ public class NMSAdapter implements FAWEPlatformAdapterImpl { System.arraycopy(adapter.getOrdinalToIbdID(), 0, blockToPalette, 0, adapter.getOrdinalToIbdID().length); } for (int i = 0; i < 4096; i++) { - char ordinal = set[i]; + char ordinal = copy[i]; if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) { LOGGER.error("Empty (__RESERVED__) ordinal given where not expected, default to air."); ordinal = BlockTypesCache.ReservedIDs.AIR;