public static void setOwner(Player p, String clanName) { saveClans(); if (clanExists(clanName)) { if (!(MySQL.mySQLenabled())) { ClansFile.getData().set("Clans." + getClanNumber(clanName) + ".Owner", p.getUniqueId()); ClansFile.saveData(); ClansFile.reloadData(); loadClans(); } else { try { Connection conn = MySQL.getConnection(); String INSERT = "INSERT INTO CODClans (clan, owner) VALUES(?, ?) ON DUPLICATE KEY UPDATE owner=?"; PreparedStatement ps = conn.prepareStatement(INSERT); ps.setString(1, clanName); ps.setString(2, p.getUniqueId().toString()); ps.setString(3, p.getUniqueId().toString()); ps.executeUpdate(); ps.close(); conn.close(); loadClans(); } catch (Exception e) { e.printStackTrace(); } } } }
public static void loadClans() { clans.clear(); clan.clear(); admins.clear(); if (!(MySQL.mySQLenabled())) { int i = 0; while (ClansFile.getData().get("Clans." + i) != null) { clans.add(ClansFile.getData().getString("Clans." + i + ".Name")); getClanMembers(ClansFile.getData().getString("Clans." + i + ".Name")); getClanAdmins(ClansFile.getData().getString("Clan." + i + ".Name")); i++; } } else { try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT clan FROM CODClans"); ResultSet rs = ps.executeQuery(); while (rs.next()) { clans.add(rs.getString("clan")); getClanMembers(rs.getString("clan")); getClanAdmins(rs.getString("clan")); } rs.close(); ps.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } } }
public static String getOwner(String clanName) { /** Returns the UUID of the player */ if (!(MySQL.mySQLenabled())) { saveClans(); if ((clanExists(clanName)) && (getClanNumber(clanName) != -1)) { return (String) ClansFile.getData().get("Clans." + getClanNumber(clanName) + ".Owner"); } } else { try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT clan,owner FROM CODClans"); ResultSet rs = ps.executeQuery(); while (rs.next()) { if (rs.getString("clan").equals(clanName)) { return rs.getString("owner"); } } rs.close(); ps.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } return null; }
public static ArrayList<String> getClanAdmins(String clanName) { /** Returns uuids of players */ if (clanExists(clanName)) { ArrayList<String> Admins = new ArrayList<String>(); if (!(MySQL.mySQLenabled())) { Admins = (ArrayList<String>) ClansFile.getData().getStringList("Clans." + getClanNumber(clanName) + ".Admins"); } else { try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT clan,admins FROM CODClans"); ResultSet rs = ps.executeQuery(); while (rs.next()) { if (rs.getString("clan").equals(clanName)) { Admins = MySQL.stringToList(MySQL.clobToString(rs.getClob("admins"))); break; } } } catch (Exception e) { e.printStackTrace(); } } admins.put(clanName, Admins); return Admins; } ArrayList<String> newList = new ArrayList<String>(); admins.put(clanName, newList); return newList; }
public static void loadOwnedPerks(Player p) { if (!(MySQL.mySQLenabled())) { List<String> perkNames = PerksFile.getData().getStringList("Perks.OwnedPerks." + p.getUniqueId()); ownedPerks.put(p, new ArrayList<Perk>()); for (int i = 0; i < perkNames.size(); i++) { String name = perkNames.get(i); if (getPerk(name) == Perk.NO_PERK) continue; ownedPerks.get(p).add(getPerk(name)); } } else { try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT uuid,list FROM CODPerks"); ResultSet rs = ps.executeQuery(); while (rs.next()) { if (rs.getString("uuid").equals(p.getUniqueId().toString())) { ArrayList<String> perkNames = MySQL.stringToList(MySQL.clobToString(rs.getClob("list"))); if ((perkNames == null) || (perkNames.isEmpty())) { ownedPerks.put(p, new ArrayList<Perk>()); } else { ownedPerks.put(p, new ArrayList<Perk>()); for (int i = 0; i < perkNames.size(); i++) { String name = perkNames.get(i); if (getPerk(name) == Perk.NO_PERK) continue; ownedPerks.get(p).add(getPerk(name)); } } break; } } if (ownedPerks.get(p) == null) { ownedPerks.put(p, new ArrayList<Perk>()); } rs.close(); ps.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } } }
public static int getClanNumber(String clan) { if (!(MySQL.mySQLenabled())) { if (clanExists(clan)) { int i = 0; while (ClansFile.getData().get("Clans." + i) != null) { if (ClansFile.getData().getString("Clans." + i + ".Name").equals(clan)) return i; i++; } return -1; } } return -1; }
public static void createClan(String ClanName, Player owner) { if (!(MySQL.mySQLenabled())) { int nextNum = 0; while (ClansFile.getData().get("Clans." + nextNum) != null) { nextNum++; } ArrayList<String> players = new ArrayList<String>(); String uuid = "" + owner.getUniqueId(); players.add(uuid); ClansFile.getData().set("Clans." + nextNum + ".Owner", uuid); clans.add(ClanName); clan.put(ClanName, players); saveClans(); } else { try { Connection conn = MySQL.getConnection(); String INSERT = "INSERT INTO CODClans (clan, owner) VALUES(?, ?) ON DUPLICATE KEY UPDATE owner=?"; PreparedStatement ps = conn.prepareStatement(INSERT); ps.setString(1, ClanName); ps.setString(2, owner.getUniqueId().toString()); ps.setString(3, owner.getUniqueId().toString()); ArrayList<String> players = new ArrayList<String>(); String uuid = "" + owner.getUniqueId(); players.add(uuid); clans.add(ClanName); clan.put(ClanName, players); ps.executeUpdate(); saveClans(); ps.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } } }
public static boolean clanExists(String clan) { if (!(MySQL.mySQLenabled())) { ArrayList<String> c = new ArrayList<String>(); ClansFile.saveData(); ClansFile.reloadData(); int i = 0; while (ClansFile.getData().get("Clans." + i) != null) { c.add(ClansFile.getData().getString("Clans." + i + ".Name")); i++; } if (c.isEmpty()) { return false; } if (c.contains(clan)) { return true; } return false; } else { try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT clan FROM CODClans"); ResultSet rs = ps.executeQuery(); while (rs.next()) { if (rs.getString("clan").equals(clan)) return true; } rs.close(); ps.close(); conn.close(); return false; } catch (Exception e) { e.printStackTrace(); } return false; } }
public static boolean deleteClan(String ClanName) { if (!(MySQL.mySQLenabled())) { if (getClanNumber(ClanName) != -1) { if (clans.contains(ClanName)) clans.remove(ClanName); if (clan.get(ClanName) != null) clan.put(ClanName, null); if (admins.get(ClanName) != null) admins.put(ClanName, null); ClansFile.getData().set("Clans", null); saveClans(); return true; } return false; } else { try { if (clanExists(ClanName)) { if (clans.contains(ClanName)) clans.remove(ClanName); if (clan.get(ClanName) != null) clan.put(ClanName, null); if (admins.get(ClanName) != null) admins.put(ClanName, null); Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("DELETE FROM CODClans WHERE clan=?"); ps.executeUpdate(); ps.setString(1, ClanName); ps.close(); conn.close(); return true; } return false; } catch (Exception e) { e.printStackTrace(); } } return false; }
public static void saveKit(final Player p) { if (kit.get(p) != null) { ItemStack five = kit.get(p).getItem(5); ItemStack six = kit.get(p).getItem(6); kit.get(p).setItem(5, null); kit.get(p).setItem(6, null); if (!(MySQL.mySQLenabled())) { KitFile.getData().set("Kit." + p.getUniqueId(), SaveAndLoad.toString(kit.get(p))); KitFile.saveData(); KitFile.reloadData(); } else { String INSERT = "INSERT INTO CODKits VALUES(?, ?) ON DUPLICATE KEY UPDATE list=?"; try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement(INSERT); ps.setString(1, p.getUniqueId().toString()); Clob clob = conn.createClob(); ArrayList<String> list = SaveAndLoad.toString(kit.get(p)); clob.setString(1, MySQL.listToString(list)); ps.setClob(2, clob); ps.setClob(3, clob); ps.executeUpdate(); ps.close(); conn.close(); } catch (Exception e) { e.printStackTrace(); } } kit.get(p).setItem(5, five); kit.get(p).setItem(6, six); } else { return; } }
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 loadPerk(Player p) { if (!(MySQL.mySQLenabled())) { String name = PerksFile.getData().getString("Perks.CurrentlyUsing." + p.getUniqueId()); if (name != null) { perk.put(p, getPerk(name)); } else { perk.put(p, Perk.NO_PERK); } } else { try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT uuid,currentperk FROM CODPerks"); ResultSet result = ps.executeQuery(); while (result.next()) { if (result.getString("uuid").equals(p.getUniqueId().toString())) { if ((result.getString("currentperk") == null) || (result.getString("currentperk").equals(""))) { perk.put(p, Perk.NO_PERK); } else { perk.put(p, getPerk(result.getString("currentperk"))); } break; } } result.close(); ps.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
public static void savePerk(Player p) { if (!(MySQL.mySQLenabled())) { PerksFile.getData().set("Perks.CurrentlyUsing." + p.getUniqueId(), "" + perk.get(p)); PerksFile.saveData(); PerksFile.reloadData(); } else { try { Connection conn = MySQL.getConnection(); String INSERT = "INSERT INTO CODPerks (uuid, currentperk) VALUES(?, ?) ON DUPLICATE KEY UPDATE currentperk=?"; PreparedStatement ps = conn.prepareStatement(INSERT); ps.setString(1, p.getUniqueId().toString()); ps.setString(2, "" + perk.get(p)); ps.setString(3, "" + perk.get(p)); ps.executeUpdate(); ps.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
public static Inventory loadKit(Player p) { if (!(MySQL.mySQLenabled())) { if (KitFile.getData().getString("Kit." + p.getUniqueId()) != null && !KitFile.getData().getString("Kit." + p.getUniqueId()).isEmpty()) { Inventory inv = Bukkit.getServer().createInventory(p, 27, "Loadout"); kit.put( p, SaveAndLoad.fromString(inv, KitFile.getData().getList("Kit." + p.getUniqueId()))); return kit.get(p); } else { Inventory inv = Bukkit.getServer().createInventory(p, 27, "Loadout"); kit.put(p, inv); return inv; } } else { try { Connection conn = MySQL.getConnection(); PreparedStatement ps = conn.prepareStatement("SELECT uuid,list FROM CODKits"); ResultSet result = ps.executeQuery(); boolean UUIDexists = false; boolean isEmpty = false; while (result.next()) { String s = result.getString("uuid"); if (s.equals(p.getUniqueId().toString())) { UUIDexists = true; String stringList = MySQL.clobToString(result.getClob("list")); if (stringList == null || stringList.equals("")) isEmpty = true; break; } } conn.close(); ps.close(); result.close(); if ((UUIDexists) && (!(isEmpty))) { Inventory inv = Bukkit.getServer().createInventory(p, 27, "Loadout"); conn = MySQL.getConnection(); ps = conn.prepareStatement("SELECT uuid,list FROM CODKits"); result = ps.executeQuery(); String stringList = ""; while (result.next()) { String s = result.getString("uuid"); if (s.equals(p.getUniqueId().toString())) { stringList = MySQL.clobToString(result.getClob("list")); break; } } ArrayList<String> kits = (ArrayList<String>) MySQL.stringToList(stringList); inv = SaveAndLoad.fromString(inv, kits); kit.put(p, inv); conn.close(); ps.close(); result.close(); return inv; } else { Inventory inv = Bukkit.getServer().createInventory(p, 27, "Loadout"); kit.put(p, inv); return inv; } } catch (Exception e) { e.printStackTrace(); } } return null; }
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(); } } }