From b3e0125c7166ef946493d8efafbec0187686e820 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 7 Jun 2017 07:34:11 +1000 Subject: [PATCH] Possible fix for VS entity brushes close #564 close #565 close #566 --- .../fawe/bukkit/v0/BukkitQueue_All.java | 4 +- .../fawe/bukkit/wrapper/AsyncBlock.java | 18 ++--- .../fawe/bukkit/wrapper/AsyncChunk.java | 65 +++++++++++++++++-- .../fawe/bukkit/wrapper/AsyncWorld.java | 4 ++ .../main/java/com/boydti/fawe/FaweCache.java | 12 ++++ .../com/thevoxelbox/voxelsniper/Sniper.java | 15 ++++- 6 files changed, 100 insertions(+), 18 deletions(-) diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index ebc4a51e..bcd993f8 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -85,13 +85,13 @@ public class BukkitQueue_All extends BukkitQueue_0() { + @Override + public void run(ChunkSnapshot value) { + this.value = world.getChunkAt(x, z).getChunkSnapshot(includeBiome, includeBiome, includeBiomeTempRain); + } + }); + } + + private T whenLoaded(RunnableVal task) { + if (Thread.currentThread() == Fawe.get().getMainThread()) { + task.run(); + return task.value; + } + if (queue instanceof BukkitQueue_0) { + BukkitQueue_0 bq = (BukkitQueue_0) queue; + if (world.isChunkLoaded(x, z)) { + long pair = MathMan.pairInt(x, z); + Long originalKeep = bq.keepLoaded.get(pair); + bq.keepLoaded.put(pair, Long.MAX_VALUE); + if (world.isChunkLoaded(x, z)) { + task.run(); + if (originalKeep != null) { + bq.keepLoaded.put(pair, originalKeep); + } else { + bq.keepLoaded.remove(pair); + } + return task.value; + } + } + } + return TaskManager.IMP.sync(task); } @Override public Entity[] getEntities() { - throw new UnsupportedOperationException("NOT IMPLEMENTED"); + if (!isLoaded()) { + return new Entity[0]; + } + return whenLoaded(new RunnableVal() { + @Override + public void run(Entity[] value) { + world.getChunkAt(x, z).getEntities(); + } + }); } @Override public BlockState[] getTileEntities() { - throw new UnsupportedOperationException("NOT IMPLEMENTED"); + if (!isLoaded()) { + return new BlockState[0]; + } + return TaskManager.IMP.sync(new RunnableVal() { + @Override + public void run(BlockState[] value) { + this.value = world.getChunkAt(x, z).getTileEntities(); + } + }); } @Override diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java index 97a970e0..7e387d75 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncWorld.java @@ -1043,4 +1043,8 @@ public class AsyncWorld extends DelegateFaweQueue implements World, HasFaweQueue public Set getListeningPluginChannels() { return parent.getListeningPluginChannels(); } + + public BukkitImplAdapter getAdapter() { + return adapter; + } } diff --git a/core/src/main/java/com/boydti/fawe/FaweCache.java b/core/src/main/java/com/boydti/fawe/FaweCache.java index 754cf941..12a16cd9 100644 --- a/core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/core/src/main/java/com/boydti/fawe/FaweCache.java @@ -295,6 +295,18 @@ public class FaweCache { } } + public static boolean isLiquid(int id) { + switch (id) { + case 8: + case 9: + case 10: + case 11: + return true; + default: + return false; + } + } + public static LightType getLight(int id) { switch (id) { // Lighting case 0: diff --git a/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java b/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java index 6f95c63b..1c043168 100644 --- a/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java +++ b/favs/src/main/java/com/thevoxelbox/voxelsniper/Sniper.java @@ -11,6 +11,7 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.MaskedFaweQueue; import com.boydti.fawe.object.RegionWrapper; +import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.changeset.FaweChangeSet; import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.TaskManager; @@ -325,7 +326,19 @@ public class Sniper { performerBrush.initP(snipeData); } - boolean result = brush.perform(snipeAction, snipeData, targetBlock, lastBlock); + switch (brush.getClass().getSimpleName()) { + case "JockeyBrush": + TaskManager.IMP.sync(new RunnableVal() { + @Override + public void run(Object value) { + brush.perform(snipeAction, snipeData, targetBlock, lastBlock); + } + }); + break; + default: + brush.perform(snipeAction, snipeData, targetBlock, lastBlock); + break; + } if (Fawe.isMainThread()) { SetQueue.IMP.flush(changeQueue); } else {