Let's try to load a jail from MySQL, #18.
This commit is contained in:
parent
1b2ed8bec4
commit
7f79f82636
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -327,6 +328,35 @@ public class JailIO {
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//load the jails from mysql
|
//load the jails from mysql
|
||||||
|
pl.debug("Time Now (str): " + System.currentTimeMillis());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(con == null) this.prepareStorage(false);
|
||||||
|
PreparedStatement ps = con.prepareStatement("SELECT * FROM " + prefix + "jails");
|
||||||
|
ResultSet set = ps.executeQuery();
|
||||||
|
|
||||||
|
while(set.next()) {
|
||||||
|
Jail j = new Jail(pl, set.getString("name"));
|
||||||
|
|
||||||
|
j.setWorld(set.getString("world"));
|
||||||
|
j.setMaxPoint(new int[] { set.getInt("top.x"), set.getInt("top.y"), set.getInt("top.z") });
|
||||||
|
j.setMinPoint(new int[] { set.getInt("bottom.x"), set.getInt("bottom.y"), set.getInt("bottom.z") });
|
||||||
|
j.setTeleportIn(new SimpleLocation(j.getWorldName(), set.getDouble("tps.in.x"),
|
||||||
|
set.getDouble("tps.in.y"), set.getDouble("tps.in.z"),
|
||||||
|
set.getFloat("tps.in.yaw"), set.getFloat("tps.in.pitch")));
|
||||||
|
j.setTeleportFree(new SimpleLocation(set.getString("tps.free.world"), set.getDouble("tps.free.x"),
|
||||||
|
set.getDouble("tps.free.y"), set.getDouble("tps.free.z"),
|
||||||
|
set.getFloat("tps.free.yaw"), set.getFloat("tps.free.pitch")));
|
||||||
|
pl.getJailManager().addJail(j, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
set.close();
|
||||||
|
ps.close();
|
||||||
|
}catch (SQLException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pl.debug("Time Now (end): " + System.currentTimeMillis());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//load the jails from flatfile
|
//load the jails from flatfile
|
||||||
@ -334,7 +364,7 @@ public class JailIO {
|
|||||||
Set<String> jails = flat.getConfigurationSection("jails").getKeys(false);
|
Set<String> jails = flat.getConfigurationSection("jails").getKeys(false);
|
||||||
if(!jails.isEmpty()) {
|
if(!jails.isEmpty()) {
|
||||||
for(String name : jails) {
|
for(String name : jails) {
|
||||||
loadJail(name);
|
loadJailFromFlatFile(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -579,111 +609,104 @@ public class JailIO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadJail(String name) {
|
private void loadJailFromFlatFile(String name) {
|
||||||
switch(storage) {
|
String node = "jails." + name + ".";
|
||||||
case 1:
|
String cNode = node + "cells.";
|
||||||
case 2:
|
Jail j = new Jail(pl, name);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
String node = "jails." + name + ".";
|
|
||||||
String cNode = node + "cells.";
|
|
||||||
Jail j = new Jail(pl, name);
|
|
||||||
|
|
||||||
j.setWorld(flat.getString(node + "world"));
|
j.setWorld(flat.getString(node + "world"));
|
||||||
j.setMaxPoint(new int[] {flat.getInt(node + "top.x"), flat.getInt(node + "top.y"), flat.getInt(node + "top.z")});
|
j.setMaxPoint(new int[] {flat.getInt(node + "top.x"), flat.getInt(node + "top.y"), flat.getInt(node + "top.z")});
|
||||||
j.setMinPoint(new int[] {flat.getInt(node + "bottom.x"), flat.getInt(node + "bottom.y"), flat.getInt(node + "bottom.z")});
|
j.setMinPoint(new int[] {flat.getInt(node + "bottom.x"), flat.getInt(node + "bottom.y"), flat.getInt(node + "bottom.z")});
|
||||||
|
|
||||||
j.setTeleportIn(new SimpleLocation(
|
j.setTeleportIn(new SimpleLocation(
|
||||||
flat.getString(node + "world"),
|
flat.getString(node + "world"),
|
||||||
flat.getDouble(node + "tps.in.x"),
|
flat.getDouble(node + "tps.in.x"),
|
||||||
flat.getDouble(node + "tps.in.y"),
|
flat.getDouble(node + "tps.in.y"),
|
||||||
flat.getDouble(node + "tps.in.z"),
|
flat.getDouble(node + "tps.in.z"),
|
||||||
(float) flat.getDouble(node + "tps.in.yaw"),
|
(float) flat.getDouble(node + "tps.in.yaw"),
|
||||||
(float) flat.getDouble(node + "tps.in.pitch")));
|
(float) flat.getDouble(node + "tps.in.pitch")));
|
||||||
j.setTeleportFree(new SimpleLocation(
|
j.setTeleportFree(new SimpleLocation(
|
||||||
flat.getString(node + "tps.free.world"),
|
flat.getString(node + "tps.free.world"),
|
||||||
flat.getDouble(node + "tps.free.x"),
|
flat.getDouble(node + "tps.free.x"),
|
||||||
flat.getDouble(node + "tps.free.y"),
|
flat.getDouble(node + "tps.free.y"),
|
||||||
flat.getDouble(node + "tps.free.z"),
|
flat.getDouble(node + "tps.free.z"),
|
||||||
(float) flat.getDouble(node + "tps.free.yaw"),
|
(float) flat.getDouble(node + "tps.free.yaw"),
|
||||||
(float) flat.getDouble(node + "tps.free.pitch")));
|
(float) flat.getDouble(node + "tps.free.pitch")));
|
||||||
|
|
||||||
if(flat.isConfigurationSection(node + "cells")) {
|
if(flat.isConfigurationSection(node + "cells")) {
|
||||||
Set<String> cells = flat.getConfigurationSection(node + "cells").getKeys(false);
|
Set<String> cells = flat.getConfigurationSection(node + "cells").getKeys(false);
|
||||||
if(!cells.isEmpty()) {
|
if(!cells.isEmpty()) {
|
||||||
for(String cell : cells) {
|
for(String cell : cells) {
|
||||||
Cell c = new Cell(cell);
|
Cell c = new Cell(cell);
|
||||||
String cellNode = cNode + cell + ".";
|
String cellNode = cNode + cell + ".";
|
||||||
|
|
||||||
c.setTeleport(new SimpleLocation(j.getTeleportIn().getWorld().getName(),
|
c.setTeleport(new SimpleLocation(j.getTeleportIn().getWorld().getName(),
|
||||||
flat.getDouble(cellNode + "tp.x"),
|
flat.getDouble(cellNode + "tp.x"),
|
||||||
flat.getDouble(cellNode + "tp.y"),
|
flat.getDouble(cellNode + "tp.y"),
|
||||||
flat.getDouble(cellNode + "tp.z"),
|
flat.getDouble(cellNode + "tp.z"),
|
||||||
(float) flat.getDouble(cellNode + "tp.yaw"),
|
(float) flat.getDouble(cellNode + "tp.yaw"),
|
||||||
(float) flat.getDouble(cellNode + "tp.pitch")));
|
(float) flat.getDouble(cellNode + "tp.pitch")));
|
||||||
c.setChestLocation(new Location(j.getTeleportIn().getWorld(),
|
c.setChestLocation(new Location(j.getTeleportIn().getWorld(),
|
||||||
flat.getInt(cellNode + "chest.x"),
|
flat.getInt(cellNode + "chest.x"),
|
||||||
flat.getInt(cellNode + "chest.y"),
|
flat.getInt(cellNode + "chest.y"),
|
||||||
flat.getInt(cellNode + "chest.z")));
|
flat.getInt(cellNode + "chest.z")));
|
||||||
|
|
||||||
for(String sign : flat.getStringList(cellNode + "signs")) {
|
for(String sign : flat.getStringList(cellNode + "signs")) {
|
||||||
String[] arr = sign.split(",");
|
String[] arr = sign.split(",");
|
||||||
c.addSign(new SimpleLocation(arr[0],
|
c.addSign(new SimpleLocation(arr[0],
|
||||||
Double.valueOf(arr[1]),
|
Double.valueOf(arr[1]),
|
||||||
Double.valueOf(arr[2]),
|
Double.valueOf(arr[2]),
|
||||||
Double.valueOf(arr[3]),
|
Double.valueOf(arr[3]),
|
||||||
Float.valueOf(arr[4]),
|
Float.valueOf(arr[4]),
|
||||||
Float.valueOf(arr[5])));
|
Float.valueOf(arr[5])));
|
||||||
}
|
|
||||||
|
|
||||||
if(flat.contains(cellNode + "prisoner")) {
|
|
||||||
Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.name"),
|
|
||||||
flat.getBoolean(cellNode + "prisoner.muted"),
|
|
||||||
flat.getLong(cellNode + "prisoner.time"),
|
|
||||||
flat.getString(cellNode + "prisoner.jailer"),
|
|
||||||
flat.getString(cellNode + "prisoner.reason"));
|
|
||||||
p.setOfflinePending(flat.getBoolean(cellNode + "prisoner.offlinePending"));
|
|
||||||
p.setToBeTransferred(flat.getBoolean(cellNode + "prisoner.toBeTransferred"));
|
|
||||||
p.setPreviousPosition(flat.getString(cellNode + "prisoner.previousLocation"));
|
|
||||||
p.setPreviousGameMode(flat.getString(cellNode + "prisoner.previousGameMode"));
|
|
||||||
p.setInventory(flat.getString(cellNode + "prisoner.inventory", ""));
|
|
||||||
p.setArmor(flat.getString(cellNode + "prisoner.armor", ""));
|
|
||||||
c.setPrisoner(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
j.addCell(c, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(flat.isConfigurationSection(node + "prisoners")) {
|
if(flat.contains(cellNode + "prisoner")) {
|
||||||
Set<String> prisoners = flat.getConfigurationSection(node + "prisoners").getKeys(false);
|
Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.name"),
|
||||||
if(!prisoners.isEmpty()) {
|
flat.getBoolean(cellNode + "prisoner.muted"),
|
||||||
for(String prisoner : prisoners) {
|
flat.getLong(cellNode + "prisoner.time"),
|
||||||
String pNode = node + "prisoners." + prisoner + ".";
|
flat.getString(cellNode + "prisoner.jailer"),
|
||||||
Prisoner pris = new Prisoner(prisoner,
|
flat.getString(cellNode + "prisoner.reason"));
|
||||||
flat.getBoolean(pNode + "muted"),
|
p.setOfflinePending(flat.getBoolean(cellNode + "prisoner.offlinePending"));
|
||||||
flat.getLong(pNode + "time"),
|
p.setToBeTransferred(flat.getBoolean(cellNode + "prisoner.toBeTransferred"));
|
||||||
flat.getString(pNode + "jailer"),
|
p.setPreviousPosition(flat.getString(cellNode + "prisoner.previousLocation"));
|
||||||
flat.getString(pNode + "reason"));
|
p.setPreviousGameMode(flat.getString(cellNode + "prisoner.previousGameMode"));
|
||||||
pris.setOfflinePending(flat.getBoolean(pNode + "offlinePending"));
|
p.setInventory(flat.getString(cellNode + "prisoner.inventory", ""));
|
||||||
pris.setToBeTransferred(flat.getBoolean(pNode + "toBeTransferred"));
|
p.setArmor(flat.getString(cellNode + "prisoner.armor", ""));
|
||||||
pris.setPreviousPosition(flat.getString(pNode + "previousLocation"));
|
c.setPrisoner(p);
|
||||||
pris.setPreviousGameMode(flat.getString(pNode + "previousGameMode"));
|
|
||||||
pris.setInventory(flat.getString(pNode + "inventory", ""));
|
|
||||||
pris.setArmor(flat.getString(pNode + "armor", ""));
|
|
||||||
j.addPrisoner(pris);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(pl.getServer().getWorld(j.getWorldName()) != null) {
|
j.addCell(c, false);
|
||||||
pl.getJailManager().addJail(j, false);
|
}
|
||||||
pl.getLogger().info("Loaded jail " + j.getName() + " with " + j.getAllPrisoners().size() + " prisoners and " + j.getCellCount() + " cells.");
|
}
|
||||||
} else
|
|
||||||
pl.getLogger().severe("Failed to load the jail " + j.getName() + " as the world '" + j.getWorldName() + "' does not exist (is null). Did you remove this world?");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(flat.isConfigurationSection(node + "prisoners")) {
|
||||||
|
Set<String> prisoners = flat.getConfigurationSection(node + "prisoners").getKeys(false);
|
||||||
|
if(!prisoners.isEmpty()) {
|
||||||
|
for(String prisoner : prisoners) {
|
||||||
|
String pNode = node + "prisoners." + prisoner + ".";
|
||||||
|
Prisoner pris = new Prisoner(prisoner,
|
||||||
|
flat.getBoolean(pNode + "muted"),
|
||||||
|
flat.getLong(pNode + "time"),
|
||||||
|
flat.getString(pNode + "jailer"),
|
||||||
|
flat.getString(pNode + "reason"));
|
||||||
|
pris.setOfflinePending(flat.getBoolean(pNode + "offlinePending"));
|
||||||
|
pris.setToBeTransferred(flat.getBoolean(pNode + "toBeTransferred"));
|
||||||
|
pris.setPreviousPosition(flat.getString(pNode + "previousLocation"));
|
||||||
|
pris.setPreviousGameMode(flat.getString(pNode + "previousGameMode"));
|
||||||
|
pris.setInventory(flat.getString(pNode + "inventory", ""));
|
||||||
|
pris.setArmor(flat.getString(pNode + "armor", ""));
|
||||||
|
j.addPrisoner(pris);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pl.getServer().getWorld(j.getWorldName()) != null) {
|
||||||
|
pl.getJailManager().addJail(j, false);
|
||||||
|
pl.getLogger().info("Loaded jail " + j.getName() + " with " + j.getAllPrisoners().size() + " prisoners and " + j.getCellCount() + " cells.");
|
||||||
|
} else
|
||||||
|
pl.getLogger().severe("Failed to load the jail " + j.getName() + " as the world '" + j.getWorldName() + "' does not exist (is null). Did you remove this world?");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user