From 18e6c09fdd95aabafa342d3520282795ec7373f9 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 2 May 2019 04:30:32 +1000 Subject: [PATCH] use paper writeLock --- .../boydti/fawe/bukkit/beta/BukkitQueue.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java index c7803c6c2..18660c6e6 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/beta/BukkitQueue.java @@ -125,12 +125,20 @@ public class BukkitQueue extends SimpleCharQueueExtent { fieldNonEmptyBlockCount = ChunkSection.class.getDeclaredField("nonEmptyBlockCount"); fieldNonEmptyBlockCount.setAccessible(true); - fieldLock = DataPaletteBlock.class.getDeclaredField("j"); - fieldLock.setAccessible(true); - Field modifiersField = Field.class.getDeclaredField("modifiers"); - int modifiers = modifiersField.getInt(fieldLock); - modifiers &= ~Modifier.FINAL; - modifiersField.setInt(fieldLock, modifiers); + { + Field tmp = null; + try { + tmp = DataPaletteBlock.class.getDeclaredField("j"); + } catch (NoSuchFieldException paper) { + tmp = DataPaletteBlock.class.getDeclaredField("writeLock"); + } + fieldLock = tmp; + fieldLock.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + int modifiers = modifiersField.getInt(fieldLock); + int newModifiers = modifiers & (~Modifier.FINAL); + if (newModifiers != modifiers) modifiersField.setInt(fieldLock, newModifiers); + } Unsafe unsafe = UnsafeUtils.getUNSAFE(); CHUNKSECTION_BASE = unsafe.arrayBaseOffset(ChunkSection[].class);