From 39dfc2444bbd4daf6ffab976e44ba4b2e5171b1a Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Tue, 18 Feb 2020 17:21:09 -0500 Subject: [PATCH] Lighting and Database changes --- .../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, 93 insertions(+), 285 deletions(-) delete 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 2d271d472..3f9b56a28 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -7,7 +7,6 @@ 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; @@ -113,28 +112,7 @@ 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
@@ -399,30 +377,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 count; +// 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; } /** 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 69bc90310..8e0cd7f45 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,48 +1,25 @@ -package com.boydti.fawe.database; +package com.boydti.fawe.database -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; +import com.boydti.fawe.config.Config +import com.sk89q.worldedit.world.World +import org.slf4j.LoggerFactory +import java.util.concurrent.ConcurrentHashMap -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; - } +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 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 54f7beea5..a9753eb7b 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,7 +1,6 @@ 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; @@ -40,26 +39,22 @@ public class RollbackDatabase extends AsyncNotifyQueue { private final World world; private Connection connection; - 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 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 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 @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 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 7fbfd7e11..174abefc3 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.IMP.getDatabase(getWorld()); + RollbackDatabase db = DBHandler.INSTANCE.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 a31a3c543..6724fe6f5 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.IMP.getDatabase(world); + RollbackDatabase db = DBHandler.INSTANCE.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 5c199c326..214625ffb 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,10 +121,9 @@ 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.IMP.getDatabase(getWorld()); + RollbackDatabase db = DBHandler.INSTANCE.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 f67b3b3e9..d43c38f14 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,61 +133,6 @@ 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 deleted file mode 100644 index 933e277d2..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/LightingExtent.java +++ /dev/null @@ -1,17 +0,0 @@ -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 e956df9ff..2d7c08617 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,6 +1,5 @@ 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,10 +16,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 96692231b..1e6f7d937 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,6 +1,5 @@ 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,10 +16,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 5ab2ecfcb..52e092ab4 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,6 +1,5 @@ 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,10 +16,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 76b53938f..a3d673124 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,6 +1,5 @@ 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,10 +16,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 bc4bf7ae4..797ddd55c 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,6 +1,5 @@ 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; @@ -18,11 +17,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 fb5273f78..3e0fe8312 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,9 +4,6 @@ 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 d698cd421..0b53631f2 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,9 +4,6 @@ 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 0c4aaddd9..99d90786e 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,9 +4,6 @@ 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 46019908f..04eb390de 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("\n").append(sub).build()); + getPlayer().print(TextComponent.builder().append(title).append(TextComponent.newline()).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 cf1a7122f..85d3652a4 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,11 +15,12 @@ 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 BlockVectorSet set = new BlockVectorSet(); + private final BlockVectorSet set = new BlockVectorSet(); private int minX, minY, minZ, maxX, maxY, maxZ; private Extent extent; @@ -44,24 +45,22 @@ public class FuzzyRegion extends AbstractRegion { } public void select(int x, int y, int z) { - 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; - } + RecursiveVisitor search = new RecursiveVisitor(mask.withExtent(extent), p -> { + 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 final void setMinMax(int x, int y, int z) { + private 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 e632ac1c5..1f4b6d67f 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.IMP + RollbackDatabase db = DBHandler.INSTANCE .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 1a50ad03f..05537f1f7 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.IMP.getDatabase(world); + return DBHandler.INSTANCE.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 d74001ed7..8581b2148 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,7 +26,6 @@ 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; @@ -52,7 +51,7 @@ import org.jetbrains.annotations.Range; /** * A base class for {@link Extent}s that merely passes extents onto another. */ -public class AbstractDelegateExtent implements Extent, LightingExtent { +public class AbstractDelegateExtent implements Extent { private final Extent extent; @@ -200,55 +199,7 @@ public class AbstractDelegateExtent implements Extent, LightingExtent { 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 30f489589..5c6ba7df3 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,7 +22,6 @@ 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; @@ -134,10 +133,6 @@ 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(); }