public static void saveOwnedPerks(Player p) { if (!(MySQL.mySQLenabled())) { List<String> perkNames = new ArrayList<String>(); for (Perk perk : ownedPerks.get(p)) { perkNames.add("" + perk); } PerksFile.getData().set("Perks.OwnedPerks." + p.getUniqueId(), perkNames); PerksFile.saveData(); PerksFile.reloadData(); } else { try { Connection conn = MySQL.getConnection(); String INSERT = "INSERT INTO CODPerks (uuid, list) VALUES(?, ?) ON DUPLICATE KEY UPDATE list=?"; PreparedStatement ps = conn.prepareStatement(INSERT); ps.setString(1, p.getUniqueId().toString()); ArrayList<String> perkNames = new ArrayList<String>(); for (Perk perk : ownedPerks.get(p)) { perkNames.add("" + perk); } Clob clob = MySQL.stringToClob(MySQL.listToString(perkNames), conn); ps.setClob(2, clob); ps.setClob(3, clob); ps.executeUpdate(); ps.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } } }
public static void saveClans() { if (!(MySQL.mySQLenabled())) { HashMap<Integer, String> Owner = new HashMap<Integer, String>(); int next = 0; while (ClansFile.getData().get("Clans." + next) != null) { Owner.put(next, ClansFile.getData().getString("Clans." + next + ".Owner")); next++; } ClansFile.getData().set("Clans", null); ClansFile.saveData(); ClansFile.reloadData(); for (int i = 0; i < clans.size(); i++) { ClansFile.getData().set("Clans." + i + ".Name", clans.get(i)); if (clan.get(clans.get(i)) != null) { ClansFile.getData().set(("Clans." + i + ".Players"), clan.get(clans.get(i))); } if (admins.get(clans.get(i)) != null) { ClansFile.getData().set("Clans." + i + ".Admins", admins.get(clans.get(i))); } ClansFile.getData().set(("Clans." + i + ".Owner"), Owner.get(i)); } ClansFile.saveData(); ClansFile.reloadData(); loadClans(); } else { try { HashMap<String, String> Owner = new HashMap<String, String>(); Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT clan,owner FROM CODClans"); ResultSet rs = ps.executeQuery(); while (rs.next()) { Owner.put(rs.getString("clan"), rs.getString("owner")); } ps = conn.prepareStatement("DELETE FROM CODClans"); ps.executeUpdate(); for (int i = 0; i < clans.size(); i++) { String INSERT = "INSERT INTO CODClans (clan, owner, players, admins) VALUES(?, ?, ?, ?) ON DUPLICATE KEY UPDATE owner=?,players=?,admins=?"; ps = conn.prepareStatement(INSERT); ps.setString(1, clans.get(i)); if (clan.get(clans.get(i)) != null) { Clob clob = MySQL.stringToClob(MySQL.listToString(clan.get(clans.get(i))), conn); ps.setClob(3, clob); ps.setClob(6, clob); } else { Clob clob = MySQL.stringToClob(MySQL.listToString(new ArrayList<String>()), conn); ps.setClob(3, clob); ps.setClob(6, clob); } if (admins.get(clans.get(i)) != null) { Clob clob = MySQL.stringToClob(MySQL.listToString(admins.get(clans.get(i))), conn); ps.setClob(4, clob); ps.setClob(7, clob); } else { Clob clob = MySQL.stringToClob(MySQL.listToString(new ArrayList<String>()), conn); ps.setClob(4, clob); ps.setClob(7, clob); } ps.setString(2, Owner.get(clans.get(i))); ps.setString(5, Owner.get(clans.get(i))); ps.executeUpdate(); ps.close(); conn.close(); } } catch (Exception e) { e.printStackTrace(); } } }