From 960ad50070381cd721e9846665049c4701752f16 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 5 Jun 2016 19:54:33 +1000 Subject: [PATCH] Use DBFunc instead of dbManager --- .../bukkit/commands/DebugUUID.java | 11 ++---- .../com/intellectualcrafters/plot/PS.java | 2 +- .../plot/commands/Grant.java | 2 +- .../plot/database/DBFunc.java | 37 ++++++++++++++++++- .../plot/object/Plot.java | 2 +- .../plot/object/PlotPlayer.java | 6 +-- .../plot/util/MainUtil.java | 2 +- 7 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java index 990794efa..96048f393 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java @@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.commands.CommandCategory; import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.commands.SubCommand; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.database.AbstractDB; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.Plot; @@ -24,7 +23,6 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; - import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -237,13 +235,12 @@ public class DebugUUID extends SubCommand { } MainUtil.sendMessage(player, "&7 - Deleting database"); - final AbstractDB database = DBFunc.dbManager; - boolean result = database.deleteTables(); + boolean result = DBFunc.deleteTables(); MainUtil.sendMessage(player, "&7 - Creating tables"); try { - database.createTables(); + DBFunc.createTables(); if (!result) { MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery"); for (Plot plot : PS.get().getPlots()) { @@ -252,7 +249,7 @@ public class DebugUUID extends SubCommand { plot.owner = value; } } - database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() { + DBFunc.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() { @Override public void run() { MainUtil.sendMessage(player, "&6Recovery was successful!"); @@ -284,7 +281,7 @@ public class DebugUUID extends SubCommand { @Override public void run() { ArrayList plots = new ArrayList<>(PS.get().getPlots()); - database.createPlotsAndData(plots, new Runnable() { + DBFunc.createPlotsAndData(plots, new Runnable() { @Override public void run() { MainUtil.sendMessage(player, "&aConversion complete!"); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index 22047d161..4d46cbf75 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -252,7 +252,7 @@ public class PS { } else if (!get().checkVersion(PS.this.lastVersion, PS.this.version)) { PS.log("&aThanks for updating from " + StringMan.join(PS.this.lastVersion, ".") + " to " + StringMan .join(PS.this.version, ".") + "!"); - DBFunc.dbManager.updateTables(PS.this.lastVersion); + DBFunc.updateTables(PS.this.lastVersion); } } }); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Grant.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Grant.java index 8e4316370..ed85ae33c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Grant.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Grant.java @@ -47,7 +47,7 @@ public class Grant extends SubCommand { } else { // add int amount = 1 + (array == null ? 0 : ByteArrayUtilities.bytesToInteger(array)); boolean replace = array != null; - DBFunc.dbManager.addPersistentMeta(uuid, "grantedPlots", ByteArrayUtilities.integerToBytes(amount), replace); + DBFunc.addPersistentMeta(uuid, "grantedPlots", ByteArrayUtilities.integerToBytes(amount), replace); } } }); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index 1ee75dd8e..157758d41 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -13,6 +13,7 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; @@ -30,6 +31,40 @@ public class DBFunc { */ public static AbstractDB dbManager; + public static void updateTables(int[] oldVersion) { + if (dbManager != null) { + dbManager.updateTables(oldVersion); + } + } + + public static void addPersistentMeta(UUID uuid, String key, byte[] meta, boolean delete) { + if (dbManager != null) { + dbManager.addPersistentMeta(uuid, key, meta, delete); + } + } + + public static void getPersistentMeta(UUID uuid, RunnableVal> result) { + if (dbManager != null) { + dbManager.getPersistentMeta(uuid, result); + } + } + + public static void removePersistentMeta(UUID uuid, String key) { + if (dbManager != null) { + dbManager.removePersistentMeta(uuid, key); + } + } + + public static void swapPlots(Plot plot1, Plot plot2) { + if (dbManager != null) { + dbManager.swapPlots(plot1, plot2); + } + } + + public static boolean deleteTables() { + return dbManager != null && dbManager.deleteTables(); + } + public static void movePlot(Plot originalPlot, Plot newPlot) { if (originalPlot.temp == -1 || newPlot.temp == -1) { return; @@ -119,7 +154,7 @@ public class DBFunc { * * @throws Exception */ - public static void createTables(String database) throws Exception { + public static void createTables() throws Exception { if (dbManager == null) { return; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 420824ef5..a61b6c469 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -1441,7 +1441,7 @@ public class Plot { this.area.addPlotAbs(this); plot.area.addPlotAbs(plot); // Swap database - DBFunc.dbManager.swapPlots(plot, this); + DBFunc.swapPlots(plot, this); TaskManager.runTaskLater(whenDone, 1); return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 5e40e45be..ef796c9ee 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -405,7 +405,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { } public void populatePersistentMetaMap() { - DBFunc.dbManager.getPersistentMeta(getUUID(), new RunnableVal>() { + DBFunc.getPersistentMeta(getUUID(), new RunnableVal>() { @Override public void run(Map value) { PlotPlayer.this.metaMap = value; @@ -421,13 +421,13 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { if (this.metaMap.containsKey(key)) { this.metaMap.remove(key); } - DBFunc.dbManager.removePersistentMeta(getUUID(), key); + DBFunc.removePersistentMeta(getUUID(), key); } public void setPersistentMeta(String key, byte[] value) { boolean delete = hasPersistentMeta(key); this.metaMap.put(key, value); - DBFunc.dbManager.addPersistentMeta(getUUID(), key, value, delete); + DBFunc.addPersistentMeta(getUUID(), key, value, delete); } public boolean hasPersistentMeta(String key) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 266321656..feda1a1e4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -859,7 +859,7 @@ public class MainUtil { if (player != null) { result.run(player.getPersistentMeta(key)); } else { - DBFunc.dbManager.getPersistentMeta(uuid, new RunnableVal>() { + DBFunc.getPersistentMeta(uuid, new RunnableVal>() { @Override public void run(Map value) { result.run(value.get(key));