public static String getIp(OfflinePlayer player) { if (player instanceof Player) { return ((Player) player).getAddress().getAddress().getHostAddress().trim(); } final TFM_Player entry = TFM_PlayerList.getEntry(TFM_Util.getUuid(player)); if (entry == null) { return null; } return entry.getIps().get(0); }
public static void autoEject(Player player, String kickMessage) { EjectMethod method = EjectMethod.STRIKE_ONE; final String ip = TFM_Util.getIp(player); if (!TFM_Util.ejectTracker.containsKey(ip)) { TFM_Util.ejectTracker.put(ip, 0); } int kicks = TFM_Util.ejectTracker.get(ip); kicks += 1; TFM_Util.ejectTracker.put(ip, kicks); if (kicks <= 1) { method = EjectMethod.STRIKE_ONE; } else if (kicks == 2) { method = EjectMethod.STRIKE_TWO; } else if (kicks >= 3) { method = EjectMethod.STRIKE_THREE; } TFM_Log.info( "AutoEject -> name: " + player.getName() + " - player ip: " + ip + " - method: " + method.toString()); player.setOp(false); player.setGameMode(GameMode.SURVIVAL); player.getInventory().clear(); switch (method) { case STRIKE_ONE: { final Calendar cal = new GregorianCalendar(); cal.add(Calendar.MINUTE, 1); final Date expires = cal.getTime(); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute."); TFM_BanManager.addIpBan( new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); TFM_BanManager.addUuidBan( new TFM_Ban( TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage)); player.kickPlayer(kickMessage); break; } case STRIKE_TWO: { final Calendar c = new GregorianCalendar(); c.add(Calendar.MINUTE, 3); final Date expires = c.getTime(); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes."); TFM_BanManager.addIpBan( new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); TFM_BanManager.addUuidBan( new TFM_Ban( TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage)); player.kickPlayer(kickMessage); break; } case STRIKE_THREE: { String[] ipAddressParts = ip.split("\\."); TFM_BanManager.addIpBan( new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage)); TFM_BanManager.addIpBan( new TFM_Ban( ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage)); TFM_BanManager.addUuidBan( new TFM_Ban( TFM_Util.getUuid(player), player.getName(), "AutoEject", null, kickMessage)); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned."); player.kickPlayer(kickMessage); break; } } }
public static String formatPlayer(OfflinePlayer player) { return player.getName() + " (" + TFM_Util.getUuid(player) + ")"; }