Advertisement
Jnk1296

Possible Listener

Jun 5th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. public class PlayerJoinListener {
  2.  
  3.     public void execute (PlayerJoinEvent e) {
  4.         Player player = e.getPlayer();
  5.         LoginCheck lc = new LoginCheck();
  6.        
  7.         // Construct the IP Address String
  8.         InetSocketAddress a = player.getAddress();
  9.         InetAddress iNetAddress = a.getAddress();
  10.         String address = iNetAddress.getHostAddress();
  11.         StringBuilder ip = new StringBuilder();
  12.         for (int i = 0; i < address.length(); i++) {
  13.             if ((address.charAt(i) >= '0' && address.charAt(i) <= '9') || address.charAt(i) == '.') {
  14.                 ip.append(address.charAt(i));
  15.             } else if (address.charAt(i) == ':') {
  16.                 break;
  17.             }
  18.         }
  19.        
  20.         IPcheck.ipToCheck = ip.toString();
  21.         IPcheck.backend.log(player.getName(), ip.toString());
  22.         IPcheck.shouldCheck = true;
  23.        
  24.         if (Configuration.secureMode) {
  25.             IPcheck.shouldCheck = lc.secureCheck(ip.toString(), e);
  26.         }
  27.        
  28.         LoginReport lp = new LoginReport();
  29.        
  30.         // Do not perform check on operators or players with the "ipcheck.getnotify permission.
  31.         if (!player.isOp() && !player.hasPermission("ipcheck.getnotify")) {
  32.             if (Configuration.notifyLogin && IPcheck.shouldCheck) {
  33.                 int accounts = (IPcheck.backend.getAlts(IPcheck.ipToCheck)).size();
  34.                 Player playerCheck = e.getPlayer();
  35.                 lp.execute(IPcheck.ipToCheck, playerCheck, accounts);
  36.             }
  37.         }
  38.        
  39.         return;
  40.     }
  41.    
  42. }
  43.  
  44. public class LoginCheck {
  45.  
  46.     public boolean secureCheck(String ip, PlayerJoinEvent e) {
  47.         ArrayList<String> players = IPcheck.backend.getAlts(ip);
  48.         int accounts = players.size();
  49.         Player player = e.getPlayer();
  50.         return secureKick(accounts, player.getName(), e, ip);
  51.     }
  52.    
  53.     public boolean secureKick(int accounts, String player, PlayerJoinEvent e, String ip) {
  54.         // If the player was reported to have more than the secure-threshold # of accounts, then kick (if not exempt).
  55.         if (accounts > Configuration.secureThreshold && !Configuration.isExemptPlayer(player) && !Configuration.isExemptIp(ip)) {
  56.            
  57.             if (player != null) {
  58.                 Player kickPlayer = e.getPlayer();
  59.                 kickPlayer.kickPlayer(Configuration.secureKickMsg);
  60.                 return false;
  61.             }
  62.         }
  63.        
  64.         return true;
  65.     }
  66.    
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement