@EventHandler(priority = EventPriority.HIGH) public void onPlayerLogin(final PlayerLoginEvent event) { switch (event.getResult()) { case ALLOWED: case KICK_FULL: case KICK_BANNED: break; default: return; } userMap.addPrejoinedPlayer(event.getPlayer()); final IUser user = userMap.getUser(event.getPlayer()); userMap.removePrejoinedPlayer(event.getPlayer()); user.getData().setNpc(false); final long currentTime = System.currentTimeMillis(); final boolean banExpired = user.checkBanTimeout(currentTime); user.checkMuteTimeout(currentTime); user.checkJailTimeout(currentTime); if (!banExpired && (user.isBanned() || event.getResult() == Result.KICK_BANNED)) { String banReason = user.getData().getBan().getReason(); if (banReason == null || banReason.isEmpty() || banReason.equalsIgnoreCase("ban")) { banReason = _("The Ban Hammer has spoken!"); } if (user.getData().getBan().getTimeout() > 0) { //TODO: TL This banReason += "\n\n" + "Expires in " + DateUtil.formatDateDiff(user.getData().getBan().getTimeout()); } event.disallow(Result.KICK_BANNED, banReason); return; } if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !Permissions.JOINFULLSERVER.isAuthorized(user)) { event.disallow(Result.KICK_FULL, _("Server is full!")); return; } event.allow(); user.setTimestamp(TimestampType.LOGIN, System.currentTimeMillis()); user.updateCompass(); user.queueSave(); }
@EventHandler public void onPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); String prefix = ChatColor.translateAlternateColorCodes( '&', Core.chat.getGroupPrefix(Bukkit.getWorlds().get(0), Core.chat.getPrimaryGroup(player))); player.setDisplayName(prefix + player.getName()); event.setFormat( ChatColor.translateAlternateColorCodes( '&', ConfigUtil.get().getConfig().getString("chat-format")) .replaceAll("%DISPLAYNAME%", "%s") .replaceAll("%MESSAGE%", "%s")); if (!player.hasPermission(ConfigUtil.get().getConfig().getString("chat-delay.permission"))) { if (!delay.containsKey(player.getUniqueId())) { event.setCancelled(false); delay.put(player.getUniqueId(), System.currentTimeMillis()); } else { long timestamp = delay.get(player.getUniqueId()); long currentTime = System.currentTimeMillis(); if (currentTime - timestamp > ConfigUtil.get().getConfig().getInt("chat-delay.delay") * 1000) { event.setCancelled(false); delay.remove(player.getUniqueId()); delay.put(player.getUniqueId(), System.currentTimeMillis()); } else { event.setCancelled(true); player.sendMessage( ChatColor.translateAlternateColorCodes( '&', ConfigUtil.get().getConfig().getString("chat-delay.message"))); } } } }
public void delayedJoin(final Player player) { if (!player.isOnline()) { return; } ess.getBackup().startTask(); final IUser user = userMap.getUser(player); user.setDisplayNick(); user.updateCompass(); user.getData().setTimestamp(TimestampType.LOGIN, System.currentTimeMillis()); user.updateActivity(false); if (!ess.getVanishedPlayers().isEmpty() && !Permissions.VANISH_SEE_OTHERS.isAuthorized(user)) { for (String p : ess.getVanishedPlayers()) { final Player toVanish = userMap.getUser(p).getPlayer(); if (toVanish.isOnline()) { user.setVanished(true); } } } if (Permissions.SLEEPINGIGNORED.isAuthorized(user)) { ess.getPlugin().scheduleSyncDelayedTask( new Runnable() { @Override public void run() { user.getPlayer().setSleepingIgnored(true); } }); } final Commands settings = ess.getSettings().getData().getCommands(); if (!settings.isDisabled("motd") && Permissions.MOTD.isAuthorized(user)) { try { final IText input = new TextInput(user, "motd", true, ess); final IText output = new KeywordReplacer(input, user, ess); final TextPager pager = new TextPager(output, true); pager.showPage("1", null, "motd", user); } catch (IOException ex) { if (ess.getSettings().isDebug()) { ess.getLogger().log(Level.WARNING, ex.getMessage(), ex); } else { ess.getLogger().log(Level.WARNING, ex.getMessage()); } } } if (!settings.isDisabled("mail") && Permissions.MAIL.isAuthorized(user)) { final List<String> mail = user.getMails(); if (mail.isEmpty()) { final String msg = _("§6You have no new mail."); if (!msg.isEmpty()) { user.sendMessage(msg); } } else { user.sendMessage(_("§6You have§c {0} §6messages! Type §c/mail read§6 to view your mail.", mail.size())); } } if (Permissions.FLY_SAFELOGIN.isAuthorized(user)) { final Location loc = user.getPlayer().getLocation(); final World world = loc.getWorld(); final int x = loc.getBlockX(); int y = loc.getBlockY(); final int z = loc.getBlockZ(); while (LocationUtil.isBlockUnsafe(world, x, y, z) && y > -1) { y--; } if (loc.getBlockY() - y > 1 || y < 0) { user.getPlayer().setAllowFlight(true); user.getPlayer().setFlying(true); user.sendMessage(_("§6Set fly mode§c {0} §6for {1}§6.", _("enabled"), user.getPlayer().getDisplayName())); } } }
@EventHandler(priority = EventPriority.NORMAL) public void onPlayerChat(AsyncPlayerChatEvent event) { try { final Player player = event.getPlayer(); String message = event.getMessage().trim(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); // Check for spam final Long lastRan = TFM_Heartbeat.getLastRan(); if (lastRan == null || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis()) { // TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates."); } else { if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) { TFM_Util.bcastMsg( player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); TFM_Util.autoEject(player, "Kicked for spamming chat."); playerdata.resetMsgCount(); event.setCancelled(true); return; } } // Check for message repeat if (playerdata.getLastMessage().equalsIgnoreCase(message)) { TFM_Util.playerMsg(player, "Please do not repeat messages."); event.setCancelled(true); return; } playerdata.setLastMessage(message); // Check for muted if (playerdata.isMuted()) { if (!TFM_AdminList.isSuperAdmin(player)) { player.sendMessage(ChatColor.RED + "You are muted, STFU!"); event.setCancelled(true); return; } playerdata.setMuted(false); } // Strip color from messages message = ChatColor.stripColor(message); // Truncate messages that are too long - 100 characters is vanilla client max if (message.length() > 100) { message = message.substring(0, 100); TFM_Util.playerMsg(player, "Message was shortened because it was too long to send."); } // Check for caps if (message.length() >= 6) { int caps = 0; for (char c : message.toCharArray()) { if (Character.isUpperCase(c)) { caps++; } } if (((float) caps / (float) message.length()) > 0.65) // Compute a ratio so that longer sentences can have more caps. { message = message.toLowerCase(); } } // Check for adminchat if (playerdata.inAdminChat()) { TFM_Util.adminChatMessage(player, message, false); event.setCancelled(true); return; } // Finally, set message event.setMessage(message); // Set the tag if (playerdata.getTag() != null) { player.setDisplayName( (playerdata.getTag() + " " + player.getDisplayName().replaceAll(" ", ""))); } } catch (Exception ex) { TFM_Log.severe(ex); } }
public void onPlayerChat(PlayerMoveEvent event) { Player player = event.getPlayer(); String playerName = player.getName(); plugin.users.put(playerName, System.currentTimeMillis()); }
public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); String playerName = player.getName(); plugin.users.put(playerName, (System.currentTimeMillis())); if (NoAFK.perm((Player) player, "noafk.admin")) plugin.checkVersion(player); }