Let's try to load a jail from MySQL, #18.

This commit is contained in:
graywolf336 2014-02-20 21:29:29 -06:00
parent 1b2ed8bec4
commit 7f79f82636

View File

@ -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,12 +609,7 @@ public class JailIO {
} }
} }
private void loadJail(String name) { private void loadJailFromFlatFile(String name) {
switch(storage) {
case 1:
case 2:
break;
default:
String node = "jails." + name + "."; String node = "jails." + name + ".";
String cNode = node + "cells."; String cNode = node + "cells.";
Jail j = new Jail(pl, name); Jail j = new Jail(pl, name);
@ -682,8 +707,6 @@ public class JailIO {
pl.getLogger().info("Loaded jail " + j.getName() + " with " + j.getAllPrisoners().size() + " prisoners and " + j.getCellCount() + " cells."); pl.getLogger().info("Loaded jail " + j.getName() + " with " + j.getAllPrisoners().size() + " prisoners and " + j.getCellCount() + " cells.");
} else } 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?"); 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;
}
} }
/** /**