From 8e97b3b4b143521ae983b74d93d1db02e99a75a2 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 18 Feb 2020 18:06:19 -0500 Subject: [PATCH] Revert "Lighting and Database changes" This reverts commit 39dfc244 --- .../main/java/com/boydti/fawe/FaweAPI.java | 72 ++++++++++++------- .../com/boydti/fawe/database/DBHandler.kt | 63 ++++++++++------ .../fawe/database/RollbackDatabase.java | 29 ++++---- .../rollback/RollbackOptimizedHistory.java | 2 +- .../fawe/object/brush/InspectBrush.java | 2 +- .../object/changeset/DiskStorageHistory.java | 3 +- .../fawe/object/extent/FaweRegionExtent.java | 55 ++++++++++++++ .../fawe/object/extent/LightingExtent.java | 17 +++++ .../fawe/object/mask/BlockLightMask.java | 9 +-- .../fawe/object/mask/BrightnessMask.java | 9 +-- .../boydti/fawe/object/mask/LightMask.java | 9 +-- .../boydti/fawe/object/mask/OpacityMask.java | 9 +-- .../boydti/fawe/object/mask/SkyLightMask.java | 11 +-- .../boydti/fawe/object/mask/XAxisMask.java | 3 + .../boydti/fawe/object/mask/YAxisMask.java | 3 + .../boydti/fawe/object/mask/ZAxisMask.java | 3 + .../object/progress/ChatProgressTracker.java | 2 +- .../fawe/object/regions/FuzzyRegion.java | 15 ++-- .../worldedit/command/HistorySubCommands.java | 2 +- .../platform/binding/ProvideBindings.java | 2 +- .../extent/AbstractDelegateExtent.java | 53 +++++++++++++- .../java/com/sk89q/worldedit/world/World.java | 5 ++ 22 files changed, 285 insertions(+), 93 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/object/extent/LightingExtent.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java index 3f9b56a28..2d271d472 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -7,6 +7,7 @@ import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.object.changeset.SimpleChangeSetSummary; import com.boydti.fawe.object.exception.FaweException; +import com.boydti.fawe.object.extent.LightingExtent; import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.MainUtil; @@ -112,7 +113,28 @@ public class FaweAPI { // if (parser != null) parser.register(methods); // return parser != null; // } - + + public static T getParser(Class parserClass) { + try { + Field field = AbstractFactory.class.getDeclaredField("parsers"); + field.setAccessible(true); + ArrayList parsers = new ArrayList<>(); + parsers.addAll((List) field.get(WorldEdit.getInstance().getMaskFactory())); + parsers.addAll((List) field.get(WorldEdit.getInstance().getBlockFactory())); + parsers.addAll((List) field.get(WorldEdit.getInstance().getItemFactory())); + parsers.addAll((List) field.get(WorldEdit.getInstance().getPatternFactory())); + for (InputParser parser : parsers) { + if (parserClass.isAssignableFrom(parser.getClass())) { + return (T) parser; + } + } + return null; + } catch (Throwable e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + /** * You can either use a IQueueExtent or an EditSession to change blocks
* - The IQueueExtent skips a bit of overhead so it's marginally faster
@@ -377,30 +399,30 @@ public class FaweAPI { * @return */ public static int fixLighting(World world, Region selection, @Nullable IQueueExtent queue) { -// final BlockVector3 bot = selection.getMinimumPoint(); -// final BlockVector3 top = selection.getMaximumPoint(); -// -// final int minX = bot.getBlockX() >> 4; -// final int minZ = bot.getBlockZ() >> 4; -// -// final int maxX = top.getBlockX() >> 4; -// final int maxZ = top.getBlockZ() >> 4; -// -// int count = 0; -// if (queue == null) queue = createQueue(world, false); -// // Remove existing lighting first -// if (queue instanceof LightingExtent) { -// LightingExtent relighter = (LightingExtent) queue; -// for (int x = minX; x <= maxX; x++) { -// for (int z = minZ; z <= maxZ; z++) { -// relighter.relightChunk(x, z); -// count++; -// } -// } -// } else { -// throw new UnsupportedOperationException("Queue is not " + LightingExtent.class); -// } - return 0; + final BlockVector3 bot = selection.getMinimumPoint(); + final BlockVector3 top = selection.getMaximumPoint(); + + final int minX = bot.getBlockX() >> 4; + final int minZ = bot.getBlockZ() >> 4; + + final int maxX = top.getBlockX() >> 4; + final int maxZ = top.getBlockZ() >> 4; + + int count = 0; + if (queue == null) queue = createQueue(world, false); + // Remove existing lighting first + if (queue instanceof LightingExtent) { + LightingExtent relighter = (LightingExtent) queue; + for (int x = minX; x <= maxX; x++) { + for (int z = minZ; z <= maxZ; z++) { + relighter.relightChunk(x, z); + count++; + } + } + } else { + throw new UnsupportedOperationException("Queue is not " + LightingExtent.class); + } + return count; } /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/database/DBHandler.kt b/worldedit-core/src/main/java/com/boydti/fawe/database/DBHandler.kt index 8e0cd7f45..69bc90310 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/database/DBHandler.kt +++ b/worldedit-core/src/main/java/com/boydti/fawe/database/DBHandler.kt @@ -1,25 +1,48 @@ -package com.boydti.fawe.database +package com.boydti.fawe.database; -import com.boydti.fawe.config.Config -import com.sk89q.worldedit.world.World -import org.slf4j.LoggerFactory -import java.util.concurrent.ConcurrentHashMap +import com.boydti.fawe.config.Config; +import com.sk89q.worldedit.world.World; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -object DBHandler { - private val log = LoggerFactory.getLogger(Config::class.java) - private val databases: MutableMap = ConcurrentHashMap(8, 0.9f, 1) - fun getDatabase(world: World): RollbackDatabase? { - val worldName = world.name - var database = databases[worldName] - return database - ?: try { - database = RollbackDatabase(world) - databases[worldName] = database - database - } catch (e: Throwable) { - log.error("No JDBC driver found!\n TODO: Bundle driver with FAWE (or disable database)", e) - null - } +public class DBHandler { + + private final Logger log = LoggerFactory.getLogger(Config.class); + + public final static DBHandler IMP = new DBHandler(); + + private Map databases = new ConcurrentHashMap<>(8, 0.9f, 1); + + public RollbackDatabase getDatabase(World world) { + String worldName = world.getName(); + RollbackDatabase database = databases.get(worldName); + if (database != null) { + return database; + } + try { + database = new RollbackDatabase(world); + databases.put(worldName, database); + return database; + } catch (Throwable e) { + log.error("No JDBC driver found!\n TODO: Bundle driver with FAWE (or disable database)", e); + return null; + } } + public RollbackDatabase getDatabase(String world) { + RollbackDatabase database = databases.get(world); + if (database != null) { + return database; + } + try { + database = new RollbackDatabase(world); + databases.put(world, database); + return database; + } catch (Throwable e) { + e.printStackTrace(); + return null; + } + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java index a9753eb7b..54f7beea5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java @@ -1,6 +1,7 @@ package com.boydti.fawe.database; import com.boydti.fawe.Fawe; +import com.boydti.fawe.FaweAPI; import com.boydti.fawe.config.Settings; import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory; import com.boydti.fawe.object.collection.YieldIterable; @@ -39,22 +40,26 @@ public class RollbackDatabase extends AsyncNotifyQueue { private final World world; private Connection connection; - private @Language("SQLite") String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS `{0}edits` (`player` BLOB(16) NOT NULL,`id` INT NOT NULL, `time` INT NOT NULL,`x1` INT NOT NULL,`x2` INT NOT NULL,`z1` INT NOT NULL,`z2` INT NOT NULL,`y1` INT NOT NULL, `y2` INT NOT NULL, `size` INT NOT NULL, `command` VARCHAR, PRIMARY KEY (player, id))"; - private @Language("SQLite") String UPDATE_TABLE1 = "ALTER TABLE `{0}edits` ADD COLUMN `command` VARCHAR"; - private @Language("SQLite") String UPDATE_TABLE2 = "alter table `{0}edits` add size int default 0 not null"; - private @Language("SQLite") String INSERT_EDIT = "INSERT OR REPLACE INTO `{0}edits` (`player`,`id`,`time`,`x1`,`x2`,`z1`,`z2`,`y1`,`y2`,`command`,`size`) VALUES(?,?,?,?,?,?,?,?,?,?,?)"; - private @Language("SQLite") String PURGE = "DELETE FROM `{0}edits` WHERE `time`? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` DESC, `id` DESC"; - private @Language("SQLite") String GET_EDITS_USER_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` ASC, `id` ASC"; - private @Language("SQLite") String GET_EDITS = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` DESC, `id` DESC"; - private @Language("SQLite") String GET_EDITS_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` , `id` "; - private @Language("SQLite") String GET_EDIT_USER = "SELECT * FROM `{0}edits` WHERE `player`=? AND `id`=?"; + private @Language("sql") String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS `{0}edits` (`player` BLOB(16) NOT NULL,`id` INT NOT NULL, `time` INT NOT NULL,`x1` INT NOT NULL,`x2` INT NOT NULL,`z1` INT NOT NULL,`z2` INT NOT NULL,`y1` INT NOT NULL, `y2` INT NOT NULL, `size` INT NOT NULL, `command` VARCHAR, PRIMARY KEY (player, id))"; + private @Language("sql") String UPDATE_TABLE1 = "ALTER TABLE `{0}edits` ADD COLUMN `command` VARCHAR"; + private @Language("sql") String UPDATE_TABLE2 = "alter table `{0}edits` add size int default 0 not null"; + private @Language("sql") String INSERT_EDIT = "INSERT OR REPLACE INTO `{0}edits` (`player`,`id`,`time`,`x1`,`x2`,`z1`,`z2`,`y1`,`y2`,`command`,`size`) VALUES(?,?,?,?,?,?,?,?,?,?,?)"; + private @Language("sql") String PURGE = "DELETE FROM `{0}edits` WHERE `time`? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` DESC, `id` DESC"; + private @Language("sql") String GET_EDITS_USER_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? AND `player`=? ORDER BY `time` ASC, `id` ASC"; + private @Language("sql") String GET_EDITS = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` DESC, `id` DESC"; + private @Language("sql") String GET_EDITS_ASC = "SELECT * FROM `{0}edits` WHERE `time`>? AND `x2`>=? AND `x1`<=? AND `z2`>=? AND `z1`<=? AND `y2`>=? AND `y1`<=? ORDER BY `time` , `id` "; + private @Language("sql") String GET_EDIT_USER = "SELECT * FROM `{0}edits` WHERE `player`=? AND `id`=?"; - private @Language("SQLite") String DELETE_EDITS_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `time`>? AND `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?"; - private @Language("SQLite") String DELETE_EDIT_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `id`=?"; + private @Language("sql") String DELETE_EDITS_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `time`>? AND `x2`>=? AND `x1`<=? AND `y2`>=? AND `y1`<=? AND `z2`>=? AND `z1`<=?"; + private @Language("sql") String DELETE_EDIT_USER = "DELETE FROM `{0}edits` WHERE `player`=? AND `id`=?"; private ConcurrentLinkedQueue historyChanges = new ConcurrentLinkedQueue<>(); + public RollbackDatabase(String world) throws SQLException, ClassNotFoundException { + this(FaweAPI.getWorld(world)); + } + public RollbackDatabase(World world) throws SQLException, ClassNotFoundException { super((t, e) -> e.printStackTrace()); this.prefix = ""; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java index 174abefc3..7fbfd7e11 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java @@ -96,7 +96,7 @@ public class RollbackOptimizedHistory extends DiskStorageHistory { public void close() throws IOException { super.close(); // Save to DB - RollbackDatabase db = DBHandler.INSTANCE.getDatabase(getWorld()); + RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld()); if (db != null) { db.logEdit(this); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java index 6724fe6f5..a31a3c543 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java @@ -77,7 +77,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { final int y = target.getBlockY(); final int z = target.getBlockZ(); World world = player.getWorld(); - RollbackDatabase db = DBHandler.INSTANCE.getDatabase(world); + RollbackDatabase db = DBHandler.IMP.getDatabase(world); System.out.println("World " + world.getName()); int count = 0; for (Supplier supplier : db.getEdits(target, false)) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 214625ffb..5c199c326 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -121,9 +121,10 @@ public class DiskStorageHistory extends FaweStreamChangeSet { @Override public void delete() { +// Fawe.debug("Deleting history: " + getWorld().getName() + "/" + uuid + "/" + index); deleteFiles(); if (Settings.IMP.HISTORY.USE_DATABASE) { - RollbackDatabase db = DBHandler.INSTANCE.getDatabase(getWorld()); + RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld()); db.delete(uuid, index); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index d43c38f14..f67b3b3e9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java @@ -133,6 +133,61 @@ public abstract class FaweRegionExtent extends ResettableExtent implements IBatc return super.getBlock(position); } + @Override + public int getBlockLight(int x, int y, int z) { + if (!contains(x, y, z)) { + if (!limit.MAX_FAILS()) { + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); + } + return 0; + } + return super.getBlockLight(x, y, z); + } + + @Override + public int getBrightness(int x, int y, int z) { + if (!contains(x, y, z)) { + if (!limit.MAX_FAILS()) { + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); + } + return 0; + } + return super.getBrightness(x, y, z); + } + + @Override + public int getLight(int x, int y, int z) { + if (!contains(x, y, z)) { + if (!limit.MAX_FAILS()) { + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); + } + return 0; + } + return super.getLight(x, y, z); + } + + @Override + public int getOpacity(int x, int y, int z) { + if (!contains(x, y, z)) { + if (!limit.MAX_FAILS()) { + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); + } + return 0; + } + return super.getOpacity(x, y, z); + } + + @Override + public int getSkyLight(int x, int y, int z) { + if (!contains(x, y, z)) { + if (!limit.MAX_FAILS()) { + WEManager.IMP.cancelEditSafe(this, FaweCache.OUTSIDE_REGION); + } + return 0; + } + return super.getSkyLight(x, y, z); + } + @Nullable @Override public Entity createEntity(Location location, BaseEntity entity) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/LightingExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/LightingExtent.java new file mode 100644 index 000000000..933e277d2 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/LightingExtent.java @@ -0,0 +1,17 @@ +package com.boydti.fawe.object.extent; + +import com.sk89q.worldedit.extent.Extent; + +public interface LightingExtent extends Extent { + int getLight(int x, int y, int z); + + int getSkyLight(int x, int y, int z); + + int getBlockLight(int x, int y, int z); + + int getOpacity(int x, int y, int z); + + int getBrightness(int x, int y, int z); + + public void relightChunk(int chunkX, int chunkZ); +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java index 2d7c08617..e956df9ff 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.math.BlockVector3; @@ -16,10 +17,10 @@ public class BlockLightMask extends AbstractExtentMask { @Override public boolean test(Extent extent, BlockVector3 vector) { -// if (extent instanceof LightingExtent) { -// int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); -// return light >= min && light <= max; -// } + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + return light >= min && light <= max; + } return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java index 1e6f7d937..96692231b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.math.BlockVector3; @@ -16,10 +17,10 @@ public class BrightnessMask extends AbstractExtentMask { @Override public boolean test(Extent extent, BlockVector3 vector) { -// if (extent instanceof LightingExtent) { -// int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); -// return light >= min && light <= max; -// } + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + return light >= min && light <= max; + } return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java index 52e092ab4..5ab2ecfcb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.math.BlockVector3; @@ -16,10 +17,10 @@ public class LightMask extends AbstractExtentMask { @Override public boolean test(Extent extent, BlockVector3 vector) { -// if (extent instanceof LightingExtent) { -// int light = ((LightingExtent) extent).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); -// return light >= min && light <= max; -// } + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + return light >= min && light <= max; + } return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java index a3d673124..76b53938f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.math.BlockVector3; @@ -16,10 +17,10 @@ public class OpacityMask extends AbstractExtentMask { @Override public boolean test(Extent extent, BlockVector3 vector) { -// if (extent instanceof LightingExtent) { -// int light = ((LightingExtent) extent).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); -// return light >= min && light <= max; -// } + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + return light >= min && light <= max; + } return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java index 797ddd55c..bc4bf7ae4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.math.BlockVector3; @@ -17,11 +18,11 @@ public class SkyLightMask extends AbstractExtentMask { @Override public boolean test(Extent extent, BlockVector3 vector) { -// if (extent instanceof LightingExtent) { -// int light = ((LightingExtent) extent) -// .getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); -// return light >= min && light <= max; -// } + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent) + .getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + return light >= min && light <= max; + } return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java index 3e0fe8312..fb5273f78 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java @@ -4,6 +4,9 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; +/** + * Restricts the + */ public class XAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java index 0b53631f2..d698cd421 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java @@ -4,6 +4,9 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; +/** + * Restricts the + */ public class YAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java index 99d90786e..0c4aaddd9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java @@ -4,6 +4,9 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; +/** + * Restricts the + */ public class ZAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/progress/ChatProgressTracker.java b/worldedit-core/src/main/java/com/boydti/fawe/object/progress/ChatProgressTracker.java index 04eb390de..46019908f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/progress/ChatProgressTracker.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/progress/ChatProgressTracker.java @@ -12,6 +12,6 @@ public class ChatProgressTracker extends DefaultProgressTracker { @Override public void sendTile(Component title, Component sub) { - getPlayer().print(TextComponent.builder().append(title).append(TextComponent.newline()).append(sub).build()); + getPlayer().print(TextComponent.builder().append(title).append("\n").append(sub).build()); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java index 85d3652a4..cf1a7122f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java @@ -15,12 +15,11 @@ import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.world.World; import java.util.Iterator; -import org.jetbrains.annotations.NotNull; public class FuzzyRegion extends AbstractRegion { private final Mask mask; - private final BlockVectorSet set = new BlockVectorSet(); + private BlockVectorSet set = new BlockVectorSet(); private int minX, minY, minZ, maxX, maxY, maxZ; private Extent extent; @@ -45,22 +44,24 @@ public class FuzzyRegion extends AbstractRegion { } public void select(int x, int y, int z) { - RecursiveVisitor search = new RecursiveVisitor(mask.withExtent(extent), p -> { - setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ()); - return true; + RecursiveVisitor search = new RecursiveVisitor(mask.withExtent(extent), new RegionFunction() { + @Override + public boolean apply(BlockVector3 p) throws WorldEditException { + setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ()); + return true; + } }, 256); search.setVisited(set); search.visit(BlockVector3.at(x, y, z)); Operations.completeBlindly(search); } - @NotNull @Override public Iterator iterator() { return set.iterator(); } - private void setMinMax(int x, int y, int z) { + private final void setMinMax(int x, int y, int z) { if (x > maxX) { maxX = x; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java index 1f4b6d67f..e632ac1c5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/HistorySubCommands.java @@ -179,7 +179,7 @@ public class HistorySubCommands { BlockVector3 .at(summary.maxX, 255, summary.maxZ)); rollback.setTime(historyFile.lastModified()); - RollbackDatabase db = DBHandler.INSTANCE + RollbackDatabase db = DBHandler.IMP .getDatabase(world); db.logEdit(rollback); actor.print("Logging: " + historyFile); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java index 05537f1f7..1a50ad03f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/binding/ProvideBindings.java @@ -81,7 +81,7 @@ public class ProvideBindings extends Bindings { @Binding public RollbackDatabase database(World world) { - return DBHandler.INSTANCE.getDatabase(world); + return DBHandler.IMP.getDatabase(world); } @AllowedRegion(FaweMaskManager.MaskType.OWNER) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java index 8581b2148..d74001ed7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java @@ -26,6 +26,7 @@ import com.boydti.fawe.beta.IBatchProcessor; import com.boydti.fawe.object.HistoryExtent; import com.boydti.fawe.object.changeset.AbstractChangeSet; import com.boydti.fawe.object.exception.FaweException; +import com.boydti.fawe.object.extent.LightingExtent; import com.boydti.fawe.util.ExtentTraverser; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEditException; @@ -51,7 +52,7 @@ import org.jetbrains.annotations.Range; /** * A base class for {@link Extent}s that merely passes extents onto another. */ -public class AbstractDelegateExtent implements Extent { +public class AbstractDelegateExtent implements Extent, LightingExtent { private final Extent extent; @@ -199,7 +200,55 @@ public class AbstractDelegateExtent implements Extent { public boolean setBiome(BlockVector2 position, BiomeType biome) { return extent.setBiome(position.getX(), 0, position.getZ(), biome); } - + + @Override + public int getSkyLight(int x, int y, int z) { + if (extent instanceof LightingExtent) { + return ((LightingExtent) extent).getSkyLight(x, y, z); + } + return 0; + } + + @Override + public int getBlockLight(int x, int y, int z) { + if (extent instanceof LightingExtent) { + return ((LightingExtent) extent).getBlockLight(x, y, z); + } + return getBrightness(x, y, z); + } + @Override + public int getOpacity(int x, int y, int z) { + if (extent instanceof LightingExtent) { + return ((LightingExtent) extent).getOpacity(x, y, z); + } + return getBlock(x, y, z).getBlockType().getMaterial().getLightOpacity(); + } + + @Override + public int getLight(int x, int y, int z) { + if (extent instanceof LightingExtent) { + return ((LightingExtent) extent).getLight(x, y, z); + } + return 0; + } + + @Override + public int getBrightness(int x, int y, int z) { + if (extent instanceof LightingExtent) { + return ((LightingExtent) extent).getBrightness(x, y, z); + } + return getBlock(x, y, z).getBlockType().getMaterial().getLightValue(); + } + + @Override + public void relightChunk(int chunkX, int chunkZ) { + if (extent instanceof LightingExtent) { + ((LightingExtent) extent).relightChunk(chunkX, chunkZ); + } else { + throw new UnsupportedOperationException("Cannot relight"); + } + } + @Override public String toString() { return super.toString() + ":" + (extent == this ? "" : extent.toString()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index 5c6ba7df3..30f489589 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.world; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.implementation.packet.ChunkPacket; import com.boydti.fawe.beta.IChunkCache; +import com.boydti.fawe.object.extent.LightingExtent; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; @@ -133,6 +134,10 @@ public interface World extends Extent, Keyed, IChunkCache { * @return the light level (0-15) */ default int getBlockLightLevel(BlockVector3 position) { + if (this instanceof LightingExtent) { + LightingExtent extent = (LightingExtent) this; + return extent.getBlockLight(position.getX(), position.getY(), position.getZ()); + } return getBlock(position).getMaterial().getLightValue(); }