mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Merge remote-tracking branch 'origin/1.15' into 1.15
This commit is contained in:
commit
e1b946d0da
@ -1,5 +1,6 @@
|
|||||||
package com.boydti.fawe.util;
|
package com.boydti.fawe.util;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.reflect.AccessibleObject;
|
import java.lang.reflect.AccessibleObject;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -32,26 +33,15 @@ public class ReflectionUtils {
|
|||||||
// letting us modify the static final field
|
// letting us modify the static final field
|
||||||
if (Modifier.isFinal(field.getModifiers())) {
|
if (Modifier.isFinal(field.getModifiers())) {
|
||||||
try {
|
try {
|
||||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
Field lookupField = MethodHandles.Lookup.class.getDeclaredField("IMPL_LOOKUP");
|
||||||
modifiersField.setAccessible(true);
|
lookupField.setAccessible(true);
|
||||||
int modifiers = modifiersField.getInt(field);
|
|
||||||
|
|
||||||
// blank out the final bit in the modifiers int
|
// blank out the final bit in the modifiers int
|
||||||
modifiers &= ~Modifier.FINAL;
|
((MethodHandles.Lookup) lookupField.get(null))
|
||||||
modifiersField.setInt(field, modifiers);
|
.findSetter(Field.class, "modifiers", int.class)
|
||||||
} catch (NoSuchFieldException e) {
|
.invokeExact(field, field.getModifiers() & ~Modifier.FINAL);
|
||||||
// Java 12+ compatibility - search fields with hidden method for modifiers
|
} catch (Throwable e) {
|
||||||
// same concept as above, just with a more hacky way of getting to the modifiers
|
e.printStackTrace();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -820,6 +820,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
* @throws WorldEditException thrown on a set error
|
* @throws WorldEditException thrown on a set error
|
||||||
*/
|
*/
|
||||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException {
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException {
|
||||||
|
if (position.getBlockY() < 0 || position.getBlockY() > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.changes++;
|
this.changes++;
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
case BEFORE_HISTORY:
|
case BEFORE_HISTORY:
|
||||||
@ -841,6 +845,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
* @return whether the block changed
|
* @return whether the block changed
|
||||||
*/
|
*/
|
||||||
public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) {
|
public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) {
|
||||||
|
if (position.getBlockY() < 0 || position.getBlockY() > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.changes++;
|
this.changes++;
|
||||||
try {
|
try {
|
||||||
return bypassAll.setBlock(position, block);
|
return bypassAll.setBlock(position, block);
|
||||||
@ -857,6 +865,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
* @return whether the block changed
|
* @return whether the block changed
|
||||||
*/
|
*/
|
||||||
public <B extends BlockStateHolder<B>> boolean smartSetBlock(BlockVector3 position, B block) {
|
public <B extends BlockStateHolder<B>> boolean smartSetBlock(BlockVector3 position, B block) {
|
||||||
|
if (position.getBlockY() < 0 || position.getBlockY() > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.changes++;
|
this.changes++;
|
||||||
try {
|
try {
|
||||||
return setBlock(position, block, Stage.BEFORE_REORDER);
|
return setBlock(position, block, Stage.BEFORE_REORDER);
|
||||||
@ -867,6 +879,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException {
|
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws MaxChangedBlocksException {
|
||||||
|
if (position.getBlockY() < 0 || position.getBlockY() > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.changes++;
|
this.changes++;
|
||||||
try {
|
try {
|
||||||
return this.getExtent().setBlock(position, block);
|
return this.getExtent().setBlock(position, block);
|
||||||
@ -879,7 +895,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <B extends BlockStateHolder<B>> boolean setBlock(int x, @Range(from = 0, to = 255) int y, int z, B block) {
|
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
|
||||||
|
if (y < 0 || y > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.changes++;
|
this.changes++;
|
||||||
try {
|
try {
|
||||||
return this.getExtent().setBlock(x, y, z, block);
|
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
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||||
*/
|
*/
|
||||||
public boolean setBlock(int x, int y, int z, Pattern pattern) {
|
public boolean setBlock(int x, int y, int z, Pattern pattern) {
|
||||||
|
if (y < 0 || y > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.changes++;
|
this.changes++;
|
||||||
try {
|
try {
|
||||||
BlockVector3 bv = mutablebv.setComponents(x, y, z);
|
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
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||||
*/
|
*/
|
||||||
public boolean setBlock(BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException {
|
public boolean setBlock(BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException {
|
||||||
|
if (position.getBlockY() < 0 || position.getBlockY() > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.changes++;
|
this.changes++;
|
||||||
try {
|
try {
|
||||||
return pattern.apply(this.getExtent(), position, position);
|
return pattern.apply(this.getExtent(), position, position);
|
||||||
|
Loading…
Reference in New Issue
Block a user