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:
|
j.setWorld(flat.getString(node + "world"));
|
||||||
String node = "jails." + name + ".";
|
j.setMaxPoint(new int[] {flat.getInt(node + "top.x"), flat.getInt(node + "top.y"), flat.getInt(node + "top.z")});
|
||||||
String cNode = node + "cells.";
|
j.setMinPoint(new int[] {flat.getInt(node + "bottom.x"), flat.getInt(node + "bottom.y"), flat.getInt(node + "bottom.z")});
|
||||||
Jail j = new Jail(pl, name);
|
|
||||||
|
j.setTeleportIn(new SimpleLocation(
|
||||||
j.setWorld(flat.getString(node + "world"));
|
flat.getString(node + "world"),
|
||||||
j.setMaxPoint(new int[] {flat.getInt(node + "top.x"), flat.getInt(node + "top.y"), flat.getInt(node + "top.z")});
|
flat.getDouble(node + "tps.in.x"),
|
||||||
j.setMinPoint(new int[] {flat.getInt(node + "bottom.x"), flat.getInt(node + "bottom.y"), flat.getInt(node + "bottom.z")});
|
flat.getDouble(node + "tps.in.y"),
|
||||||
|
flat.getDouble(node + "tps.in.z"),
|
||||||
j.setTeleportIn(new SimpleLocation(
|
(float) flat.getDouble(node + "tps.in.yaw"),
|
||||||
flat.getString(node + "world"),
|
(float) flat.getDouble(node + "tps.in.pitch")));
|
||||||
flat.getDouble(node + "tps.in.x"),
|
j.setTeleportFree(new SimpleLocation(
|
||||||
flat.getDouble(node + "tps.in.y"),
|
flat.getString(node + "tps.free.world"),
|
||||||
flat.getDouble(node + "tps.in.z"),
|
flat.getDouble(node + "tps.free.x"),
|
||||||
(float) flat.getDouble(node + "tps.in.yaw"),
|
flat.getDouble(node + "tps.free.y"),
|
||||||
(float) flat.getDouble(node + "tps.in.pitch")));
|
flat.getDouble(node + "tps.free.z"),
|
||||||
j.setTeleportFree(new SimpleLocation(
|
(float) flat.getDouble(node + "tps.free.yaw"),
|
||||||
flat.getString(node + "tps.free.world"),
|
(float) flat.getDouble(node + "tps.free.pitch")));
|
||||||
flat.getDouble(node + "tps.free.x"),
|
|
||||||
flat.getDouble(node + "tps.free.y"),
|
if(flat.isConfigurationSection(node + "cells")) {
|
||||||
flat.getDouble(node + "tps.free.z"),
|
Set<String> cells = flat.getConfigurationSection(node + "cells").getKeys(false);
|
||||||
(float) flat.getDouble(node + "tps.free.yaw"),
|
if(!cells.isEmpty()) {
|
||||||
(float) flat.getDouble(node + "tps.free.pitch")));
|
for(String cell : cells) {
|
||||||
|
Cell c = new Cell(cell);
|
||||||
if(flat.isConfigurationSection(node + "cells")) {
|
String cellNode = cNode + cell + ".";
|
||||||
Set<String> cells = flat.getConfigurationSection(node + "cells").getKeys(false);
|
|
||||||
if(!cells.isEmpty()) {
|
c.setTeleport(new SimpleLocation(j.getTeleportIn().getWorld().getName(),
|
||||||
for(String cell : cells) {
|
flat.getDouble(cellNode + "tp.x"),
|
||||||
Cell c = new Cell(cell);
|
flat.getDouble(cellNode + "tp.y"),
|
||||||
String cellNode = cNode + cell + ".";
|
flat.getDouble(cellNode + "tp.z"),
|
||||||
|
(float) flat.getDouble(cellNode + "tp.yaw"),
|
||||||
c.setTeleport(new SimpleLocation(j.getTeleportIn().getWorld().getName(),
|
(float) flat.getDouble(cellNode + "tp.pitch")));
|
||||||
flat.getDouble(cellNode + "tp.x"),
|
c.setChestLocation(new Location(j.getTeleportIn().getWorld(),
|
||||||
flat.getDouble(cellNode + "tp.y"),
|
flat.getInt(cellNode + "chest.x"),
|
||||||
flat.getDouble(cellNode + "tp.z"),
|
flat.getInt(cellNode + "chest.y"),
|
||||||
(float) flat.getDouble(cellNode + "tp.yaw"),
|
flat.getInt(cellNode + "chest.z")));
|
||||||
(float) flat.getDouble(cellNode + "tp.pitch")));
|
|
||||||
c.setChestLocation(new Location(j.getTeleportIn().getWorld(),
|
for(String sign : flat.getStringList(cellNode + "signs")) {
|
||||||
flat.getInt(cellNode + "chest.x"),
|
String[] arr = sign.split(",");
|
||||||
flat.getInt(cellNode + "chest.y"),
|
c.addSign(new SimpleLocation(arr[0],
|
||||||
flat.getInt(cellNode + "chest.z")));
|
Double.valueOf(arr[1]),
|
||||||
|
Double.valueOf(arr[2]),
|
||||||
for(String sign : flat.getStringList(cellNode + "signs")) {
|
Double.valueOf(arr[3]),
|
||||||
String[] arr = sign.split(",");
|
Float.valueOf(arr[4]),
|
||||||
c.addSign(new SimpleLocation(arr[0],
|
Float.valueOf(arr[5])));
|
||||||
Double.valueOf(arr[1]),
|
|
||||||
Double.valueOf(arr[2]),
|
|
||||||
Double.valueOf(arr[3]),
|
|
||||||
Float.valueOf(arr[4]),
|
|
||||||
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.contains(cellNode + "prisoner")) {
|
||||||
if(flat.isConfigurationSection(node + "prisoners")) {
|
Prisoner p = new Prisoner(flat.getString(cellNode + "prisoner.name"),
|
||||||
Set<String> prisoners = flat.getConfigurationSection(node + "prisoners").getKeys(false);
|
flat.getBoolean(cellNode + "prisoner.muted"),
|
||||||
if(!prisoners.isEmpty()) {
|
flat.getLong(cellNode + "prisoner.time"),
|
||||||
for(String prisoner : prisoners) {
|
flat.getString(cellNode + "prisoner.jailer"),
|
||||||
String pNode = node + "prisoners." + prisoner + ".";
|
flat.getString(cellNode + "prisoner.reason"));
|
||||||
Prisoner pris = new Prisoner(prisoner,
|
p.setOfflinePending(flat.getBoolean(cellNode + "prisoner.offlinePending"));
|
||||||
flat.getBoolean(pNode + "muted"),
|
p.setToBeTransferred(flat.getBoolean(cellNode + "prisoner.toBeTransferred"));
|
||||||
flat.getLong(pNode + "time"),
|
p.setPreviousPosition(flat.getString(cellNode + "prisoner.previousLocation"));
|
||||||
flat.getString(pNode + "jailer"),
|
p.setPreviousGameMode(flat.getString(cellNode + "prisoner.previousGameMode"));
|
||||||
flat.getString(pNode + "reason"));
|
p.setInventory(flat.getString(cellNode + "prisoner.inventory", ""));
|
||||||
pris.setOfflinePending(flat.getBoolean(pNode + "offlinePending"));
|
p.setArmor(flat.getString(cellNode + "prisoner.armor", ""));
|
||||||
pris.setToBeTransferred(flat.getBoolean(pNode + "toBeTransferred"));
|
c.setPrisoner(p);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
j.addCell(c, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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?");
|
|
||||||
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