mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Use DBFunc instead of dbManager
This commit is contained in:
parent
7d44850bb0
commit
960ad50070
@ -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<Plot> 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!");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user