Guest User

Untitled

a guest
Feb 2nd, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. package custom;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.ArrayList;
  8.  
  9. import net.sf.l2j.L2DatabaseFactory;
  10.  
  11. /**
  12. * @author RnP PC
  13. *
  14. */
  15. public class BanManager
  16. {
  17. public static ArrayList<String> ips = new ArrayList<>();
  18.  
  19. @SuppressWarnings("null")
  20. public static void BanIp(String ip)
  21. {
  22. ips.add(ip);
  23. Connection con = null;
  24. try
  25. {
  26. con = L2DatabaseFactory.getInstance().getConnection();
  27. final PreparedStatement statement = con.prepareStatement("INSERT INTO banned (ip) VALUES ('"+ip+"')");
  28. statement.execute();
  29. statement.close();
  30. }
  31. catch (final SQLException e)
  32. {
  33. e.printStackTrace();
  34. }
  35. finally
  36. {
  37. try{con.close();}catch(Exception e){}
  38. }
  39. }
  40.  
  41. @SuppressWarnings("null")
  42. public static boolean UnbanIp(String ip)
  43. {
  44. if(!ips.contains(ip))
  45. return false;
  46. ips.remove(ip);
  47. Connection con = null;
  48. try
  49. {
  50. con = L2DatabaseFactory.getInstance().getConnection();
  51. final PreparedStatement statement = con.prepareStatement("DELETE FROM banned where ip='"+ip+"'");
  52. statement.execute();
  53. statement.close();
  54. }
  55. catch (final SQLException e)
  56. {
  57. e.printStackTrace();
  58. }
  59. finally
  60. {
  61. try{con.close();}catch(Exception e){}
  62. }
  63. return true;
  64. }
  65.  
  66. @SuppressWarnings("null")
  67. public static void Load()
  68. {
  69. Connection con = null;
  70. try
  71. {
  72. con = L2DatabaseFactory.getInstance().getConnection();
  73. final PreparedStatement statement = con.prepareStatement("SELECT * FROM banned");
  74. final ResultSet rset = statement.executeQuery();
  75. while (rset.next())
  76. {
  77. String ip = rset.getString("ip");
  78. ips.add(ip);
  79. }
  80. rset.close();
  81. statement.close();
  82. }
  83. catch (final SQLException e)
  84. {
  85. e.printStackTrace();
  86. }
  87. finally
  88. {
  89. try{con.close();}catch(Exception e){}
  90. }
  91. System.out.println("BAN MANAGER: Loaded " + ips.size() + " banned ips");
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment