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

@ -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);
}
}
});

View File

@ -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);
}
}
});

View File

@ -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<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) {
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;
}

View File

@ -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;
}

View File

@ -405,7 +405,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
}
public void populatePersistentMetaMap() {
DBFunc.dbManager.getPersistentMeta(getUUID(), new RunnableVal<Map<String, byte[]>>() {
DBFunc.getPersistentMeta(getUUID(), new RunnableVal<Map<String, byte[]>>() {
@Override
public void run(Map<String, byte[]> 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) {

View File

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