From 652a98390799af7ecd08d816246743005386f7b1 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 21 Apr 2016 09:40:14 +1000 Subject: [PATCH] Workaround for CoreProtect logging --- .../main/java/com/boydti/fawe/util/MainUtil.java | 4 ++-- .../com/boydti/fawe/wrappers/WorldWrapper.java | 4 ++++ .../main/java/com/sk89q/worldedit/EditSession.java | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/boydti/fawe/util/MainUtil.java b/core/src/main/java/com/boydti/fawe/util/MainUtil.java index 08c2d5d2..30ec7561 100644 --- a/core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -57,7 +57,7 @@ public class MainUtil { public void run(File file) { long age = now - file.lastModified(); if (age > timeDiff) { - System.out.println("Deleting file: " + file); + Fawe.debug("Deleting file: " + file); file.delete(); } } @@ -73,7 +73,7 @@ public class MainUtil { if (file.isDirectory()) { deleteDirectory(files[i]); } else { - System.out.println("Deleting file: " + file); + Fawe.debug("Deleting file: " + file); file.delete(); } } diff --git a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java index b0fb0a7d..329c4b14 100644 --- a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java +++ b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java @@ -40,6 +40,10 @@ public class WorldWrapper extends AbstractWorld { this.parent = parent; } + public AbstractWorld getParent() { + return parent instanceof WorldWrapper ? ((WorldWrapper) parent).getParent() : parent; + } + @Override public boolean useItem(Vector position, BaseItem item, Direction face) { return parent.useItem(position, item, face); diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index a6773c38..3b35e26a 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -118,6 +118,7 @@ import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; +import java.lang.reflect.Field; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; @@ -235,6 +236,19 @@ public class EditSession implements Extent { } this.actor = event.getActor(); this.queue = SetQueue.IMP.getNewQueue(world.getName(), true); + // Set the world of the event to the actual world (workaround for CoreProtect) + try { + Class eventClass = event.getClass(); + Field fieldWorld = eventClass.getDeclaredField("world"); + fieldWorld.setAccessible(true); + if (world instanceof WorldWrapper) { + fieldWorld.set(event, ((WorldWrapper) world).getParent()); + } else { + fieldWorld.set(event, world); + } + } catch (Throwable e) { + e.printStackTrace(); + } this.world = (world = new WorldWrapper((AbstractWorld) world)); this.wrapper = Fawe.imp().getEditSessionWrapper(this); // Not a player; bypass history