Use DBFunc instead of dbManager

This commit is contained in:
Jesse Boyd 2016-06-05 19:54:33 +10:00
parent 7d44850bb0
commit 960ad50070
7 changed files with 47 additions and 15 deletions

View File

@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.commands.CommandCategory;
import com.intellectualcrafters.plot.commands.RequiredType; import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.commands.SubCommand; import com.intellectualcrafters.plot.commands.SubCommand;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.AbstractDB;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.Plot; 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.bukkit.uuid.OfflineUUIDWrapper;
import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -237,13 +235,12 @@ public class DebugUUID extends SubCommand {
} }
MainUtil.sendMessage(player, "&7 - Deleting database"); MainUtil.sendMessage(player, "&7 - Deleting database");
final AbstractDB database = DBFunc.dbManager; boolean result = DBFunc.deleteTables();
boolean result = database.deleteTables();
MainUtil.sendMessage(player, "&7 - Creating tables"); MainUtil.sendMessage(player, "&7 - Creating tables");
try { try {
database.createTables(); DBFunc.createTables();
if (!result) { if (!result) {
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery"); MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
for (Plot plot : PS.get().getPlots()) { for (Plot plot : PS.get().getPlots()) {
@ -252,7 +249,7 @@ public class DebugUUID extends SubCommand {
plot.owner = value; plot.owner = value;
} }
} }
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() { DBFunc.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(player, "&6Recovery was successful!"); MainUtil.sendMessage(player, "&6Recovery was successful!");
@ -284,7 +281,7 @@ public class DebugUUID extends SubCommand {
@Override @Override
public void run() { public void run() {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots()); ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
database.createPlotsAndData(plots, new Runnable() { DBFunc.createPlotsAndData(plots, new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(player, "&aConversion complete!"); MainUtil.sendMessage(player, "&aConversion complete!");

View File

@ -252,7 +252,7 @@ public class PS {
} else if (!get().checkVersion(PS.this.lastVersion, PS.this.version)) { } else if (!get().checkVersion(PS.this.lastVersion, PS.this.version)) {
PS.log("&aThanks for updating from " + StringMan.join(PS.this.lastVersion, ".") + " to " + StringMan PS.log("&aThanks for updating from " + StringMan.join(PS.this.lastVersion, ".") + " to " + StringMan
.join(PS.this.version, ".") + "!"); .join(PS.this.version, ".") + "!");
DBFunc.dbManager.updateTables(PS.this.lastVersion); DBFunc.updateTables(PS.this.lastVersion);
} }
} }
}); });

View File

@ -47,7 +47,7 @@ public class Grant extends SubCommand {
} else { // add } else { // add
int amount = 1 + (array == null ? 0 : ByteArrayUtilities.bytesToInteger(array)); int amount = 1 + (array == null ? 0 : ByteArrayUtilities.bytesToInteger(array));
boolean replace = array != null; boolean replace = array != null;
DBFunc.dbManager.addPersistentMeta(uuid, "grantedPlots", ByteArrayUtilities.integerToBytes(amount), replace); DBFunc.addPersistentMeta(uuid, "grantedPlots", ByteArrayUtilities.integerToBytes(amount), replace);
} }
} }
}); });

View File

@ -13,6 +13,7 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -30,6 +31,40 @@ public class DBFunc {
*/ */
public static AbstractDB dbManager; 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<Map<String, byte[]>> 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) { public static void movePlot(Plot originalPlot, Plot newPlot) {
if (originalPlot.temp == -1 || newPlot.temp == -1) { if (originalPlot.temp == -1 || newPlot.temp == -1) {
return; return;
@ -119,7 +154,7 @@ public class DBFunc {
* *
* @throws Exception * @throws Exception
*/ */
public static void createTables(String database) throws Exception { public static void createTables() throws Exception {
if (dbManager == null) { if (dbManager == null) {
return; return;
} }

View File

@ -1441,7 +1441,7 @@ public class Plot {
this.area.addPlotAbs(this); this.area.addPlotAbs(this);
plot.area.addPlotAbs(plot); plot.area.addPlotAbs(plot);
// Swap database // Swap database
DBFunc.dbManager.swapPlots(plot, this); DBFunc.swapPlots(plot, this);
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
return true; return true;
} }

View File

@ -405,7 +405,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
} }
public void populatePersistentMetaMap() { public void populatePersistentMetaMap() {
DBFunc.dbManager.getPersistentMeta(getUUID(), new RunnableVal<Map<String, byte[]>>() { DBFunc.getPersistentMeta(getUUID(), new RunnableVal<Map<String, byte[]>>() {
@Override @Override
public void run(Map<String, byte[]> value) { public void run(Map<String, byte[]> value) {
PlotPlayer.this.metaMap = value; PlotPlayer.this.metaMap = value;
@ -421,13 +421,13 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
if (this.metaMap.containsKey(key)) { if (this.metaMap.containsKey(key)) {
this.metaMap.remove(key); this.metaMap.remove(key);
} }
DBFunc.dbManager.removePersistentMeta(getUUID(), key); DBFunc.removePersistentMeta(getUUID(), key);
} }
public void setPersistentMeta(String key, byte[] value) { public void setPersistentMeta(String key, byte[] value) {
boolean delete = hasPersistentMeta(key); boolean delete = hasPersistentMeta(key);
this.metaMap.put(key, value); this.metaMap.put(key, value);
DBFunc.dbManager.addPersistentMeta(getUUID(), key, value, delete); DBFunc.addPersistentMeta(getUUID(), key, value, delete);
} }
public boolean hasPersistentMeta(String key) { public boolean hasPersistentMeta(String key) {

View File

@ -859,7 +859,7 @@ public class MainUtil {
if (player != null) { if (player != null) {
result.run(player.getPersistentMeta(key)); result.run(player.getPersistentMeta(key));
} else { } else {
DBFunc.dbManager.getPersistentMeta(uuid, new RunnableVal<Map<String, byte[]>>() { DBFunc.getPersistentMeta(uuid, new RunnableVal<Map<String, byte[]>>() {
@Override @Override
public void run(Map<String, byte[]> value) { public void run(Map<String, byte[]> value) {
result.run(value.get(key)); result.run(value.get(key));