From 4095786bbebedc6a997584bfddc7d7e153884824 Mon Sep 17 00:00:00 2001 From: mathiascode Date: Sat, 22 Feb 2020 05:53:25 +0200 Subject: [PATCH 1/2] Add support for OpenJ9 13 --- .../com/boydti/fawe/util/ReflectionUtils.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index a167f468f..8b46cbe3f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -1,5 +1,6 @@ package com.boydti.fawe.util; +import java.lang.invoke.MethodHandles; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -32,26 +33,15 @@ public class ReflectionUtils { // letting us modify the static final field if (Modifier.isFinal(field.getModifiers())) { try { - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - int modifiers = modifiersField.getInt(field); + Field lookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP"); + lookupField.setAccessible(true); // blank out the final bit in the modifiers int - modifiers &= ~Modifier.FINAL; - modifiersField.setInt(field, modifiers); - } catch (NoSuchFieldException e) { - // Java 12+ compatibility - search fields with hidden method for modifiers - // same concept as above, just with a more hacky way of getting to the modifiers - Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class); - getDeclaredFields0.setAccessible(true); - Field[] fields = (Field[]) getDeclaredFields0.invoke(Field.class, false); - for (Field classField : fields) { - if ("modifiers".equals(classField.getName())) { - classField.setAccessible(true); - classField.set(field, field.getModifiers() & ~Modifier.FINAL); - break; - } - } + ((MethodHandles.Lookup) lookupField.get(null)) + .findSetter(Field.class, "modifiers", int.class) + .invokeExact(field, field.getModifiers() & ~Modifier.FINAL); + } catch (Throwable e) { + e.printStackTrace(); } } } From 9043692dbdf015de1cb070882633071fbecdc1aa Mon Sep 17 00:00:00 2001 From: BrodyBeckwith Date: Sat, 29 Feb 2020 17:42:00 -0500 Subject: [PATCH 2/2] Don't attempt to set blocks below 0 and above 255 Fixes #307 --- .../java/com/sk89q/worldedit/EditSession.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 4e4e9f333..e4b8cfd1e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -820,6 +820,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @throws WorldEditException thrown on a set error */ public > boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException { + if (position.getBlockY() < 0 || position.getBlockY() > 255) { + return false; + } + this.changes++; switch (stage) { case BEFORE_HISTORY: @@ -841,6 +845,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @return whether the block changed */ public > boolean rawSetBlock(BlockVector3 position, B block) { + if (position.getBlockY() < 0 || position.getBlockY() > 255) { + return false; + } + this.changes++; try { return bypassAll.setBlock(position, block); @@ -857,6 +865,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @return whether the block changed */ public > boolean smartSetBlock(BlockVector3 position, B block) { + if (position.getBlockY() < 0 || position.getBlockY() > 255) { + return false; + } + this.changes++; try { return setBlock(position, block, Stage.BEFORE_REORDER); @@ -867,6 +879,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Override public > boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException { + if (position.getBlockY() < 0 || position.getBlockY() > 255) { + return false; + } + this.changes++; try { return this.getExtent().setBlock(position, block); @@ -879,7 +895,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Override - public > boolean setBlock(int x, @Range(from = 0, to = 255) int y, int z, B block) { + public > boolean setBlock(int x, int y, int z, B block) { + if (y < 0 || y > 255) { + return false; + } + this.changes++; try { return this.getExtent().setBlock(x, y, z, block); @@ -899,6 +919,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public boolean setBlock(int x, int y, int z, Pattern pattern) { + if (y < 0 || y > 255) { + return false; + } + this.changes++; try { BlockVector3 bv = mutablebv.setComponents(x, y, z); @@ -917,6 +941,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public boolean setBlock(BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException { + if (position.getBlockY() < 0 || position.getBlockY() > 255) { + return false; + } + this.changes++; try { return pattern.apply(this.getExtent(), position, position);