From 28079e81299d3fc5cc20c902a01fb7cfc63638aa Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 23 Dec 2021 15:59:05 +0100 Subject: [PATCH] refactor: Also deprecated `IMP` for DBHandler --- .../fastasyncworldedit/core/FaweCache.java | 2 +- .../core/command/tool/brush/InspectBrush.java | 2 +- .../core/database/DBHandler.java | 22 ++++++++++++++++--- .../platform/binding/ProvideBindings.java | 2 +- .../core/history/DiskStorageHistory.java | 2 +- .../history/RollbackOptimizedHistory.java | 2 +- .../core/util/WEManager.java | 4 ---- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java index e0f840a3f..087402810 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweCache.java @@ -67,7 +67,7 @@ public enum FaweCache implements Trimable { /** * @since 2.0.0 */ - INSTANCE;// singleton + INSTANCE; private static final Logger LOGGER = LogManagerCompat.getLogger(); diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/InspectBrush.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/InspectBrush.java index 82d99c416..f0de661a1 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/InspectBrush.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/command/tool/brush/InspectBrush.java @@ -81,7 +81,7 @@ public class InspectBrush extends BrushTool { final int y = target.getBlockY(); final int z = target.getBlockZ(); World world = player.getWorld(); - RollbackDatabase db = DBHandler.IMP.getDatabase(world); + RollbackDatabase db = DBHandler.dbHandler().getDatabase(world); int count = 0; for (Supplier supplier : db.getEdits(target, false)) { count++; diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/database/DBHandler.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/database/DBHandler.java index d160c24c8..fd1263b11 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/database/DBHandler.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/database/DBHandler.java @@ -9,12 +9,28 @@ import java.util.concurrent.ConcurrentHashMap; public class DBHandler { - private static final Logger LOGGER = LogManagerCompat.getLogger(); - + /** + * @deprecated Use {@link #dbHandler()} instead. + */ + @Deprecated(forRemoval = true, since = "2.0.0") public static final DBHandler IMP = new DBHandler(); - + private static final Logger LOGGER = LogManagerCompat.getLogger(); + private static DBHandler INSTANCE; private final Map databases = new ConcurrentHashMap<>(8, 0.9f, 1); + /** + * Get an instance of the DBHandler. + * + * @return an instance of the DBHandler. + * @since 2.0.0 + */ + public static DBHandler dbHandler() { + if (INSTANCE == null) { + INSTANCE = new DBHandler(); + } + return INSTANCE; + } + public RollbackDatabase getDatabase(World world) { RollbackDatabase database = databases.get(world); if (database != null) { diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/platform/binding/ProvideBindings.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/platform/binding/ProvideBindings.java index b296b5577..8a5b25058 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/platform/binding/ProvideBindings.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extension/platform/binding/ProvideBindings.java @@ -68,7 +68,7 @@ public class ProvideBindings extends Bindings { @Binding public RollbackDatabase database(World world) { - return DBHandler.IMP.getDatabase(world); + return DBHandler.dbHandler().getDatabase(world); } @AllowedRegion(FaweMaskManager.MaskType.OWNER) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java index 5adeb0c91..7d0bfe76e 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/DiskStorageHistory.java @@ -121,7 +121,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { public void delete() { deleteFiles(); if (Settings.settings().HISTORY.USE_DATABASE) { - RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld()); + RollbackDatabase db = DBHandler.dbHandler().getDatabase(getWorld()); db.delete(uuid, index); } } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/RollbackOptimizedHistory.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/RollbackOptimizedHistory.java index ee2862cdf..6e7e4068b 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/RollbackOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/RollbackOptimizedHistory.java @@ -99,7 +99,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.dbHandler().getDatabase(getWorld()); if (db != null) { db.logEdit(this); } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/WEManager.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/WEManager.java index 9839d84e6..cf7e4f4de 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/WEManager.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/WEManager.java @@ -35,10 +35,6 @@ public class WEManager { public static WEManager IMP = new WEManager(); private final ArrayDeque managers = new ArrayDeque<>(); - private WEManager() { - INSTANCE = this; - } - /** * Get an instance of the WEManager. *