refactor: Also deprecated IMP for DBHandler

This commit is contained in:
NotMyFault 2021-12-23 15:59:05 +01:00
parent ca5ad58f01
commit 28079e8129
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C
7 changed files with 24 additions and 12 deletions

View File

@ -67,7 +67,7 @@ public enum FaweCache implements Trimable {
/** /**
* @since 2.0.0 * @since 2.0.0
*/ */
INSTANCE;// singleton INSTANCE;
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();

View File

@ -81,7 +81,7 @@ public class InspectBrush extends BrushTool {
final int y = target.getBlockY(); final int y = target.getBlockY();
final int z = target.getBlockZ(); final int z = target.getBlockZ();
World world = player.getWorld(); World world = player.getWorld();
RollbackDatabase db = DBHandler.IMP.getDatabase(world); RollbackDatabase db = DBHandler.dbHandler().getDatabase(world);
int count = 0; int count = 0;
for (Supplier<RollbackOptimizedHistory> supplier : db.getEdits(target, false)) { for (Supplier<RollbackOptimizedHistory> supplier : db.getEdits(target, false)) {
count++; count++;

View File

@ -9,12 +9,28 @@ import java.util.concurrent.ConcurrentHashMap;
public class DBHandler { 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(); public static final DBHandler IMP = new DBHandler();
private static final Logger LOGGER = LogManagerCompat.getLogger();
private static DBHandler INSTANCE;
private final Map<World, RollbackDatabase> databases = new ConcurrentHashMap<>(8, 0.9f, 1); private final Map<World, RollbackDatabase> 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) { public RollbackDatabase getDatabase(World world) {
RollbackDatabase database = databases.get(world); RollbackDatabase database = databases.get(world);
if (database != null) { if (database != null) {

View File

@ -68,7 +68,7 @@ public class ProvideBindings extends Bindings {
@Binding @Binding
public RollbackDatabase database(World world) { public RollbackDatabase database(World world) {
return DBHandler.IMP.getDatabase(world); return DBHandler.dbHandler().getDatabase(world);
} }
@AllowedRegion(FaweMaskManager.MaskType.OWNER) @AllowedRegion(FaweMaskManager.MaskType.OWNER)

View File

@ -121,7 +121,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
public void delete() { public void delete() {
deleteFiles(); deleteFiles();
if (Settings.settings().HISTORY.USE_DATABASE) { if (Settings.settings().HISTORY.USE_DATABASE) {
RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld()); RollbackDatabase db = DBHandler.dbHandler().getDatabase(getWorld());
db.delete(uuid, index); db.delete(uuid, index);
} }
} }

View File

@ -99,7 +99,7 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
public void close() throws IOException { public void close() throws IOException {
super.close(); super.close();
// Save to DB // Save to DB
RollbackDatabase db = DBHandler.IMP.getDatabase(getWorld()); RollbackDatabase db = DBHandler.dbHandler().getDatabase(getWorld());
if (db != null) { if (db != null) {
db.logEdit(this); db.logEdit(this);
} }

View File

@ -35,10 +35,6 @@ public class WEManager {
public static WEManager IMP = new WEManager(); public static WEManager IMP = new WEManager();
private final ArrayDeque<FaweMaskManager> managers = new ArrayDeque<>(); private final ArrayDeque<FaweMaskManager> managers = new ArrayDeque<>();
private WEManager() {
INSTANCE = this;
}
/** /**
* Get an instance of the WEManager. * Get an instance of the WEManager.
* *