Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Patch for misuse of isBanned bit in the SQL/SQLite Databases.
- * This code is responsible for synchronizing the isBanned bit
- * of the database with the boolean value of the isBanned()
- * method in Bukkit for every player which exists in the
- * plugin's database.
- */
- if(!IPcheck.Instance.Configuration.banStateSynchronized) {
- ArrayList<UserObject> userIndex = this.fetchAllPlayers();
- if (userIndex.size() > 0) {
- Bukkit.getLogger().log(Level.INFO, "[IP-Check] Performing Ban Synchronization...");
- ArrayList<StringBuilder> sb_ban = new ArrayList<StringBuilder>();
- ArrayList<StringBuilder> sb_unban = new ArrayList<StringBuilder>();
- StringBuilder ban_string = new StringBuilder();
- StringBuilder unban_string = new StringBuilder();
- for (UserObject upo:userIndex) {
- OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(upo.getUser());
- if (offPlayer == null) continue;
- if (upo.getBannedStatus() == offPlayer.isBanned()) continue;
- if (upo.getBannedStatus() == true) {
- unban_string.append(upo.getUser()+"' or WHERE lower(username) = '");
- if (unban_string.length() >= 50000) {
- sb_unban.add(unban_string);
- unban_string = new StringBuilder();
- }
- } else {
- ban_string.append(upo.getUser()+"' or WHERE lower(username) = '");
- if (ban_string.length() >= 50000) {
- sb_ban.add(ban_string);
- ban_string = new StringBuilder();
- }
- }
- }
- sb_unban.add(unban_string);
- sb_ban.add(ban_string);
- if (sb_ban.get(0).length() > 0) {
- for (StringBuilder sb:sb_ban) {
- String input = sb.toString().substring(0, (sb.toString().length() - 29));
- try {
- connection.query("UPDATE ipcheck_users SET isbanned = 1 WHERE lower(username) = '" + input);
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- }
- if (sb_unban.get(0).length() > 0) {
- for (StringBuilder sb:sb_unban) {
- String input = sb.toString().substring(0, (sb.toString().length() - 29));
- try {
- connection.query("UPDATE ipcheck_users SET isbanned = 0 WHERE lower(username) = '" + input);
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- }
- Bukkit.getLogger().log(Level.INFO, "[IP-Check] Ban Synchronization Complete.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement