public static void setChamp(God g, OfflinePlayer p) { String s = new String( "update £.gods set champ=" + ((p == null) ? "NULL" : "'" + p.getName() + "'") + " where idGod=" + (new Integer(Utility.getDBNumberFromGodType(g.getGodType())))); Bukkit.getServer().broadcastMessage(s); (new SQLQuery(s, msqlc)).excecuteUpdate(); }
public static void loadChamps() { for (int i = 1; i <= GodManager.getActiveGods(); i++) { GodType t = Utility.getGodTypeFromDBNumber(i); ResultSet r = null; try { r = (new SQLQuery( new String("select lastActivated,champ from £.gods where idGod=" + i + ";"), msqlc)) .excecuteQuery(); } catch (MySQLSyntaxErrorException e1) { e1.printStackTrace(); } try { while (r.next()) { GregorianCalendar c = null; Date d = r.getDate(1); if (d != null) { c = new GregorianCalendar(); c.setTime(r.getDate(1)); } God g = GodManager.getGod(t); if (g != null) { g.setLastActivated(c); String s = r.getString(2); if (s != null) { OfflinePlayer p = Bukkit.getOfflinePlayer(r.getString(2)); g.setChamp(p); } } } } catch (SQLException e) { e.printStackTrace(); } } }
public static ArrayList<Entry<String, Integer>> getTopFollowers(God g) { ArrayList<Entry<String, Integer>> list = new ArrayList<>(); ResultSet r = null; try { r = (new SQLQuery( "select follower,reputation from £.followers f where god=" + Utility.getDBNumberFromGodType(g.getGodType()) + " order by f.reputation limit 10;", msqlc)) .excecuteQuery(); } catch (MySQLSyntaxErrorException e1) { e1.printStackTrace(); } try { while (r.next()) { list.add( new AbstractMap.SimpleEntry<String, Integer>(r.getString(1), new Integer(r.getInt(2)))); } } catch (SQLException e) { e.printStackTrace(); } return list; }
public static void saveThrones() { for (int i = 1; i < 5; i++) { God g = GodManager.getGod(Utility.getGodTypeFromDBNumber(i)); if (g != null) { if (g.hasThrone()) { if (AltarManager.getAltar(g.getThrone()).getDBId() == 0) { Location l = g.getThrone().getLocation(); String s = "insert into £.locations(world,chunkx,chunkz,x,y,z) values('" + l.getWorld().getName() + "'," + l.getChunk().getX() + "," + l.getChunk().getZ() + "," + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ() + ")"; (new SQLQuery(s, msqlc)).excecuteUpdate(); ResultSet r = null; try { r = (new SQLQuery("select max(id) from £.locations", msqlc)).excecuteQuery(); } catch (MySQLSyntaxErrorException e1) { e1.printStackTrace(); } try { r.first(); s = "update £.thrones set hasThrone=true, location=" + r.getInt(1) + " where god=" + i; (new SQLQuery(s, msqlc)).excecuteUpdate(); } catch (SQLException e) { e.printStackTrace(); } } } else { Bukkit.getConsoleSender().sendMessage("2"); String s = "select location from £.thrones where god=" + i + ";"; ResultSet r = null; try { r = (new SQLQuery(s, msqlc)).excecuteQuery(); } catch (MySQLSyntaxErrorException e1) { e1.printStackTrace(); } s = "update £.thrones set hasThrone=false, location=NULL where god=" + i + ";"; (new SQLQuery(s, msqlc)).excecuteUpdate(); try { while (r.next()) { s = "delete from £.locations where id=" + r.getInt(1) + ";"; (new SQLQuery(s, msqlc)).excecuteUpdate(); } } catch (SQLException e) { e.printStackTrace(); } } GregorianCalendar gc = g.getLastActivated(); if (gc != null) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String s = "update £.gods set lastActivated='" + df.format(gc.getTime()) + "' where idGod=" + i + ";"; (new SQLQuery(s, msqlc)).excecuteUpdate(); } } } }
public static void saveFollower( Player p, int rep, int points, God g, GregorianCalendar lastPrayed, GregorianCalendar lastHealed) { String sr = new String("select id from £.followers where follower like '" + p.getName() + "';"); ResultSet r = null; try { r = (new SQLQuery(sr, msqlc)).excecuteQuery(); } catch (MySQLSyntaxErrorException e) { e.printStackTrace(); } boolean empty = true; try { String s; while (r.next()) { empty = false; } if (empty) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); s = new String( "insert into £.followers(follower,reputation,points,god,lastpray,lastheal) values('" + p.getName()) + "'," + rep + "," + points + "," + Utility.getDBNumberFromGodType(g.getGodType()) + ",'" + df.format(lastPrayed.getTime()) + "','" + df.format(lastHealed.getTime()).toString() + "');"; } else if (rep == -1) { s = new String("delete from £.followers where id=" + r.getInt(1) + ";"); } else { r.first(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); s = new String( "update £.followers set lastpray='" + df.format(lastPrayed.getTime()) + "', points=" + points + ", reputation=" + rep + ", god=" + Utility.getDBNumberFromGodType(g.getGodType()) + ", lastheal='" + df.format(lastHealed.getTime()) + "' where id=" + r.getInt(1) + ";"); } new SQLQuery(s, msqlc).excecuteUpdate(); } catch (SQLException e2) { e2.printStackTrace(); } }