@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerDrinkPotion(PlayerItemConsumeEvent event) { Player player = event.getPlayer(); if (event.getItem().getType() == Material.POTION && !FOPM_TFM_Util.isHighRank(player)) { player.sendMessage(ChatColor.GREEN + "Please use /potion to add potion effects, thank you!"); event.setCancelled(true); } }
@EventHandler public void onPlayerHurt(EntityDamageEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); if (FOPM_TFM_Util.inGod(player)) { event.setCancelled(true); } } }
@EventHandler public void doubleJump(PlayerToggleFlightEvent event) { final Player player = event.getPlayer(); if (event.isFlying() && FOPM_TFM_Util.isDoubleJumper(player)) { player.setFlying(false); Vector jump = player.getLocation().getDirection().multiply(2).setY(1.1); player.setVelocity(player.getVelocity().add(jump)); event.setCancelled(true); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJump(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); if (to.getBlockY() > from.getBlockY()) { Player player = event.getPlayer(); if (FOPM_TFM_Util.isDoubleJumper(player)) { player.setAllowFlight(true); } } }
// Disable GM/GOD PVP @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (event.getEntity() instanceof Player) { if (event.getDamager() instanceof Player) { Player player = (Player) event.getDamager(); if (player.getGameMode() == GameMode.CREATIVE || FOPM_TFM_Util.inGod(player)) { TFM_Util.playerMsg(player, "NO GM / GOD PVP!", ChatColor.DARK_RED); event.setCancelled(true); } } if (event.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) event.getDamager(); if (arrow.getShooter() instanceof Player) { Player player = (Player) arrow.getShooter(); if (player.getGameMode() == GameMode.CREATIVE || FOPM_TFM_Util.inGod(player)) { TFM_Util.playerMsg(player, "NO GM / GOD PVP!", ChatColor.DARK_RED); event.setCancelled(true); } } } } }
@EventHandler(priority = EventPriority.HIGHEST) @SuppressWarnings("null") public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String command = event.getMessage(); final Player player = event.getPlayer(); if ((command.contains("&k") || command.contains("&m") || command.contains("&o") || command.contains("&n")) && !TFM_AdminList.isSuperAdmin(player)) { event.setCancelled(true); TFM_Util.playerMsg(player, ChatColor.RED + "You are not permitted to use &o, &k, &n or &m!"); } final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); playerdata.setLastCommand(command); if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) { TFM_Util.bcastMsg( player.getName() + " was automatically kicked for spamming commands.", ChatColor.RED); TFM_Util.autoEject(player, "Kicked for spamming commands."); playerdata.resetMsgCount(); TFM_Util.TFM_EntityWiper.wipeEntities(true, true); event.setCancelled(true); return; } if (playerdata.allCommandsBlocked()) { TFM_Util.playerMsg(player, "Your commands have been blocked by an admin.", ChatColor.RED); event.setCancelled(true); return; } // Block commands if player is muted if (playerdata.isMuted()) { if (!TFM_AdminList.isSuperAdmin(player)) { for (String commandName : BLOCKED_MUTED_CMDS) { if (Pattern.compile("^/" + commandName.toLowerCase() + " ") .matcher(command.toLowerCase()) .find()) { player.sendMessage(ChatColor.RED + "That command is blocked while you are muted."); event.setCancelled(true); return; } } } else { playerdata.setMuted(false); } } if (TFM_ConfigEntry.ENABLE_PREPROCESS_LOG.getBoolean()) { if (!command.contains("purple") && !command.contains("deop") && !command.contains("ban") && !command.contains("unban") && !command.contains("optroll") && !command.contains("blowup")) { TFM_Log.info( String.format( "[PREPROCESS_COMMAND] %s(%s): %s", player.getName(), ChatColor.stripColor(player.getDisplayName()), command), true); } } // Blocked commands if (TFM_CommandBlocker.isCommandBlocked(command, player, true)) { // CommandBlocker handles messages and broadcasts event.setCancelled(true); } if (command.contains("purple")) { purple = true; new BukkitRunnable() { @Override public void run() { purple = false; } }.runTaskLater(TotalFreedomMod.plugin, 20L * 1L); } if (command.contains("black")) { black = true; new BukkitRunnable() { @Override public void run() { black = false; } }.runTaskLater(TotalFreedomMod.plugin, 20L * 1L); } if (command.contains("175:") || command.contains("double_plant:")) { event.setCancelled(true); TFM_Util.autoEject( player, ChatColor.DARK_RED + "Do not attempt to use any command involving the crash item!"); } ChatColor colour = ChatColor.GRAY; if (command.contains("//")) { colour = ChatColor.RED; } if (!TFM_AdminList.isSuperAdmin(player)) { for (Player pl : Bukkit.getOnlinePlayers()) { if (TFM_AdminList.isSuperAdmin(pl) && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) { if (!command.contains("purple") && !command.contains("deop") && !command.contains("ban") && !command.contains("unban") && !command.contains("optroll") && !command.contains("blowup")) { TFM_Util.playerMsg(pl, colour + player.getName() + ": " + command); } } } } else { for (Player pl : Bukkit.getOnlinePlayers()) { if (FOPM_TFM_Util.isHighRank(pl) && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled() && player != pl) { if (!command.contains("purple") && !command.contains("deop") && !command.contains("ban") && !command.contains("unban") && !command.contains("optroll") && !command.contains("blowup")) { TFM_Util.playerMsg(pl, colour + player.getName() + ": " + command); } } } } }
@EventHandler(priority = EventPriority.NORMAL) @SuppressWarnings("UseSpecificCatch") public void onPlayerChat(AsyncPlayerChatEvent event) { try { final Player player = event.getPlayer(); String message = event.getMessage().trim(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerDataSync(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_Sync.bcastMsg( player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); TFM_Sync.autoEject(player, "Kicked for spamming chat."); playerdata.resetMsgCount(); event.setCancelled(true); return; } } // Check for message repeat if (playerdata.getLastMessage().equalsIgnoreCase(message)) { TFM_Sync.playerMsg(player, "Please do not repeat messages."); event.setCancelled(true); return; } playerdata.setLastMessage(message); // Check for muted if (playerdata.isMuted()) { if (!TFM_AdminList.isSuperAdminSync(player)) { TFM_Sync.playerMsg( player, ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes."); 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_Sync.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++; } } // Compute a ratio so that longer sentences can have more caps. if (((float) caps / (float) message.length()) > 0.65) { message = message.toLowerCase(); } } // Check for adminchat if (playerdata.inAdminChat()) { TFM_Sync.adminChatMessage(player, message, false); event.setCancelled(true); return; } if (playerdata.inTelnetAdminChat()) { FOPM_TFM_Util.TelnetAdminChatMessage(player, message, false); event.setCancelled(true); return; } if (playerdata.inDevChat()) { FOPM_TFM_Util.DevChatMessage(player, message, false); event.setCancelled(true); return; } if (playerdata.inSeniorAdminChat()) { FOPM_TFM_Util.SeniorAdminChatMessage(player, message, false); event.setCancelled(true); return; } // Finally, set message event.setMessage(message); // Set the tag if (playerdata.getTag() != null) { event.setFormat("<" + playerdata.getTag().replaceAll("%", "%%") + " %1$s> %2$s"); } } catch (Exception ex) { TFM_Log.severe(ex); } }