@EventHandler(priority = EventPriority.HIGH) public void onPlayerLogin(PlayerLoginEvent event) { if (event.getResult() != Result.ALLOWED) return; // Define the player Player p = event.getPlayer(); // Pretty sure this isn't even necessary, but I just can't figure out wtf is throwing the NPE if (p == null) return; // Check if player is banned if (!p.isBanned()) return; // Check to see that they have a bantime, and that if they do, if the timestamp is invalid. if (PConfManager.getPVal(p, "bantime") != null && !RUtils.isTimeStampValid(p, "bantime")) { // Set them unbanned p.setBanned(false); // Stop the method return; } // Get the banreason from the player's userdata file String kickMessage = PConfManager.getPValString(p, "banreason"); // Returns string or null // Check if there was none, and if there wasn't, set it to default ban message. if (kickMessage == null) kickMessage = plugin.banMessage; // Set the kick message to the ban reason event.setKickMessage(kickMessage); // Disallow the event event.disallow(Result.KICK_BANNED, kickMessage); }
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { if (event.isCancelled()) return; if (plugin.showcommands) log.info("[PLAYER_COMMAND] " + event.getPlayer().getName() + ": " + event.getMessage()); if (PConfManager.getPValBoolean(event.getPlayer(), "muted")) { if (PConfManager.getPVal(event.getPlayer(), "mutetime") != null && !RUtils.isTimeStampValid(event.getPlayer(), "mutetime")) PConfManager.setPValBoolean(event.getPlayer(), false, "muted"); for (String command : plugin.muteCmds) { if (!(event.getMessage().toLowerCase().startsWith(command.toLowerCase() + " ") || event.getMessage().equalsIgnoreCase(command.toLowerCase()))) continue; event.getPlayer().sendMessage(ChatColor.RED + "You are muted."); log.info( "[RoyalCommands] " + event.getPlayer().getName() + " tried to use that command, but is muted."); event.setCancelled(true); } } if (PConfManager.getPValBoolean(event.getPlayer(), "jailed")) { event.getPlayer().sendMessage(ChatColor.RED + "You are jailed."); log.info( "[RoyalCommands] " + event.getPlayer().getName() + " tried to use that command, but is jailed."); event.setCancelled(true); } }
@EventHandler(priority = EventPriority.LOW) public void onPlayerChat(PlayerChatEvent event) { if (event.isCancelled()) return; if (AFKUtils.isAfk(event.getPlayer())) { AFKUtils.unsetAfk(event.getPlayer()); plugin.getServer().broadcastMessage(event.getPlayer().getName() + " is no longer AFK."); } if (PConfManager.getPValBoolean(event.getPlayer(), "muted")) { if (PConfManager.getPVal(event.getPlayer(), "mutetime") != null && !RUtils.isTimeStampValid(event.getPlayer(), "mutetime")) PConfManager.setPValBoolean(event.getPlayer(), false, "muted"); event.setFormat(""); event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + "You are muted."); plugin.log.info( "[RoyalCommands] " + event.getPlayer().getName() + " tried to speak, but has been muted."); } }