Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package pl.easyage.core.managers;
  2.  
  3. import java.util.*;
  4. import pl.easyage.api.*;
  5. import org.apache.commons.lang.*;
  6. import pl.easyage.api.utils.*;
  7. import java.sql.*;
  8.  
  9. public final class NickManager
  10. {
  11. private static final HashMap<UUID, String> blackListed;
  12.  
  13. static {
  14. blackListed = new HashMap<UUID, String>();
  15. }
  16.  
  17. public static void addBlackListed(final UUID uuid, final String reason) {
  18. if (!isNickListed(uuid)) {
  19. NickManager.blackListed.put(uuid, reason);
  20. API.getStore().update(false, "INSERT INTO `mh_nicklisted`(`id`, `uuid`, `reason`) VALUES (NULL,'" + uuid + "','" + StringEscapeUtils.escapeSql(reason) + "')");
  21. }
  22. }
  23.  
  24. public static boolean isNickListed(final UUID uuid) {
  25. return NickManager.blackListed.containsKey(uuid);
  26. }
  27.  
  28. public static void removeNickListed(final UUID uuid) {
  29. NickManager.blackListed.remove(uuid);
  30. API.getStore().update(false, "DELETE FROM `mh_nicklisted` WHERE `uuid` = '" + uuid + "'");
  31. }
  32.  
  33. public static String getNickListed(final UUID uuid) {
  34. return NickManager.blackListed.get(uuid);
  35. }
  36.  
  37. public static void setup() {
  38. final ResultSet rs = API.getStore().query("SELECT * FROM `mh_nicklisted`");
  39. try {
  40. while (rs.next()) {
  41. NickManager.blackListed.put(UUID.fromString(rs.getString("uuid")), rs.getString("reason"));
  42. }
  43. Logger.info(new String[] { "Loaded " + NickManager.blackListed.size() + " nickcolor users!" });
  44. }
  45. catch (SQLException sqlexception) {
  46. Logger.warning(new String[] { "An error occurred while loading blacklisted users!", "Error: " + sqlexception.getMessage() });
  47. sqlexception.printStackTrace();
  48. }
  49. }
  50.  
  51. public static HashMap<UUID, String> getBlackListed() {
  52. return NickManager.blackListed;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement