Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package custom;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import net.sf.l2j.L2DatabaseFactory;
- /**
- * @author RnP PC
- *
- */
- public class BanManager
- {
- public static ArrayList<String> ips = new ArrayList<>();
- public static void BanIp(String ip)
- {
- ips.add(ip);
- Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
- final PreparedStatement statement = con.prepareStatement("INSERT INTO banned (ip) VALUES ('"+ip+"')");
- statement.execute();
- statement.close();
- }
- catch (final SQLException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try{con.close();}catch(Exception e){}
- }
- }
- public static boolean UnbanIp(String ip)
- {
- if(!ips.contains(ip))
- return false;
- ips.remove(ip);
- Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
- final PreparedStatement statement = con.prepareStatement("DELETE FROM banned where ip='"+ip+"'");
- statement.execute();
- statement.close();
- }
- catch (final SQLException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try{con.close();}catch(Exception e){}
- }
- return true;
- }
- public static void Load()
- {
- Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
- final PreparedStatement statement = con.prepareStatement("SELECT * FROM banned");
- final ResultSet rset = statement.executeQuery();
- if (rset.next())
- {
- String ip = rset.getString("ip");
- ips.add(ip);
- }
- rset.close();
- statement.close();
- }
- catch (final SQLException e)
- {
- e.printStackTrace();
- }
- finally
- {
- try{con.close();}catch(Exception e){}
- }
- System.out.println("BAN MANAGER: Loaded " + ips.size() + " banned ips");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement