@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.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); }
@Override public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("muteall")) { if (!plugin.isAuthorized(cs, "rcmds.muteall")) { RUtils.dispNoPerms(cs); return true; } Player[] ps = plugin.getServer().getOnlinePlayers(); for (Player p : ps) { if (plugin.isVanished(p) || plugin.isAuthorized(p, "rcmds.exempt.mute")) continue; if (cs instanceof Player) { if (p == cs) continue; } if (!allMuted) { PConfManager.setPValBoolean(p, true, "muted"); p.sendMessage(ChatColor.RED + "You have been muted!"); } else { PConfManager.setPValBoolean(p, false, "muted"); p.sendMessage(ChatColor.BLUE + "You have been unmuted!"); } } if (!allMuted) { cs.sendMessage(ChatColor.BLUE + "You have muted all players."); allMuted = true; } else { cs.sendMessage(ChatColor.BLUE + "You have unmuted all players."); allMuted = false; } return true; } return false; }
@EventHandler(priority = EventPriority.HIGHEST) public void vipLogin(PlayerLoginEvent e) { if (e.getResult() != Result.KICK_FULL) return; if (!PConfManager.getPConfExists(e.getPlayer())) return; if (e.getPlayer().isBanned()) return; if (PConfManager.getPVal(e.getPlayer(), "vip") != null && PConfManager.getPValBoolean(e.getPlayer(), "vip")) e.allow(); }
@EventHandler() public void onChat(PlayerChatEvent e) { if (PConfManager.getPVal(e.getPlayer(), "ignoredby") == null) return; Set<Player> recpts = e.getRecipients(); ArrayList<String> ignores = (ArrayList<String>) PConfManager.getPValStringList(e.getPlayer(), "ignoredby"); Set<Player> ignore = new HashSet<Player>(); for (Player p : recpts) for (String ignoree : ignores) if (p.getName().equalsIgnoreCase(ignoree.toLowerCase())) ignore.add(p); e.getRecipients().removeAll(ignore); }
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerInteract(PlayerInteractEvent event) { if (PConfManager.getPValBoolean(event.getPlayer(), "jailed")) event.setCancelled(true); Action act = event.getAction(); if (act.equals(Action.PHYSICAL)) return; ItemStack id = event.getItem(); if (id == null) return; int idn = id.getTypeId(); if (idn == 0) return; List<String> cmds = PConfManager.getPValStringList(event.getPlayer(), "assign." + idn); if (cmds == null) return; for (String s : cmds) { if (s.toLowerCase().trim().startsWith("c:")) event.getPlayer().chat(s.trim().substring(2)); else event.getPlayer().performCommand(s.trim()); } }
@EventHandler public void commandCooldown(PlayerCommandPreprocessEvent e) { if (e.isCancelled()) return; String command = e.getMessage().split(" ")[0].toLowerCase().substring(1); if (plugin.getCommand(command) != null) command = plugin.getCommand(command).getName(); Player p = e.getPlayer(); if (plugin.isAuthorized(p, "rcmds.exempt.cooldown.commands")) return; Long currentcd = PConfManager.getPValLong(p, "command_cooldowns." + command); if (currentcd != null) { if (currentcd <= new Date().getTime()) { setCooldown(command, p); return; } p.sendMessage( ChatColor.RED + "You can't use that command for" + ChatColor.GRAY + RUtils.formatDateDiff(currentcd) + ChatColor.RED + "."); e.setCancelled(true); return; } setCooldown(command, p); }
@EventHandler(priority = EventPriority.HIGH) public void onPlayerMove(PlayerMoveEvent event) { if (event.isCancelled()) return; if (AFKUtils.isAfk(event.getPlayer())) { AFKUtils.unsetAfk(event.getPlayer()); plugin.getServer().broadcastMessage(event.getPlayer().getName() + " is no longer AFK."); return; } if (PConfManager.getPValBoolean(event.getPlayer(), "frozen")) 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."); } }
@EventHandler(priority = EventPriority.HIGH) public void onPlayerJoin(PlayerJoinEvent event) { File datafile = new File( plugin.getDataFolder() + File.separator + "userdata" + File.separator + event.getPlayer().getName().toLowerCase() + ".yml"); if (!datafile.exists()) { log.info("[RoyalCommands] Creating userdata for user " + event.getPlayer().getName() + "."); try { FileConfiguration out = YamlConfiguration.loadConfiguration(datafile); out.set("name", event.getPlayer().getName()); String dispname = event.getPlayer().getDisplayName(); if (dispname == null || dispname.equals("")) dispname = event.getPlayer().getName(); out.set("dispname", dispname); out.set("ip", event.getPlayer().getAddress().getAddress().toString().replace("/", "")); out.set("banreason", ""); out.set("allow-tp", true); out.save(datafile); log.info("[RoyalCommands] Userdata creation finished."); } catch (Exception e) { log.severe( "[RoyalCommands] Could not create userdata for user " + event.getPlayer().getName() + "!"); e.printStackTrace(); } if (plugin.useWelcome) { String welcomemessage = plugin.welcomeMessage; welcomemessage = welcomemessage.replace("{name}", event.getPlayer().getName()); String dispname = event.getPlayer().getDisplayName(); if (dispname == null || dispname.equals("")) dispname = event.getPlayer().getName(); welcomemessage = welcomemessage.replace("{dispname}", dispname); welcomemessage = welcomemessage.replace("{world}", event.getPlayer().getWorld().getName()); plugin.getServer().broadcastMessage(welcomemessage); } if (plugin.stsNew) event.getPlayer().teleport(event.getPlayer().getWorld().getSpawnLocation()); } else { log.info("[RoyalCommands] Updating the IP for " + event.getPlayer().getName() + "."); String playerip = event.getPlayer().getAddress().getAddress().toString(); playerip = playerip.replace("/", ""); PConfManager.setPValString(event.getPlayer(), playerip, "ip"); } if (plugin.motdLogin) CmdMotd.showMotd(event.getPlayer()); if (plugin.sendToSpawn) { if (plugin.stsBack) CmdBack.backdb.put(event.getPlayer(), event.getPlayer().getLocation()); event.getPlayer().teleport(event.getPlayer().getWorld().getSpawnLocation()); } }
@EventHandler public void displayNames(PlayerLoginEvent e) { if (e.getResult() != Result.ALLOWED) return; Player p = e.getPlayer(); if (p == null) return; String dispname = PConfManager.getPValString(p, "dispname"); if (dispname == null || dispname.equals("")) dispname = p.getName().trim(); dispname = dispname.trim(); if (dispname == null) return; p.setDisplayName(dispname); if (dispname.length() <= 16) p.setPlayerListName(dispname); }
@EventHandler(priority = EventPriority.HIGH) public void onTeleport(PlayerTeleportEvent e) { if (e.isCancelled()) return; if (PConfManager.getPValBoolean(e.getPlayer(), "jailed")) { e.getPlayer().sendMessage(ChatColor.RED + "You are jailed and may not teleport."); e.setCancelled(true); return; } if (CmdBack.backdb.containsKey(e.getPlayer())) if (CmdBack.backdb.get(e.getPlayer()).equals(e.getFrom())) return; CmdBack.backdb.put(e.getPlayer(), e.getFrom()); }
public void setCooldown(String command, OfflinePlayer p) { ConfigurationSection cmdCds = plugin.getConfig().getConfigurationSection("command_cooldowns"); if (cmdCds == null) return; boolean contains = cmdCds.getKeys(false).contains(command); if (plugin.cooldownAliases) if (plugin.getCommand(command) != null) for (String alias : plugin.getCommand(command).getAliases()) if (cmdCds.getKeys(false).contains(alias)) { contains = true; break; } if (contains) { long cooldown = cmdCds.getLong(command); PConfManager.setPValLong( p, new Date().getTime() + (cooldown * 1000), "command_cooldowns." + command); } }
@EventHandler(priority = EventPriority.LOW) public void teleCooldown(PlayerTeleportEvent e) { if (e.isCancelled()) return; Player p = e.getPlayer(); if (plugin.isAuthorized(p, "rcmds.exempt.cooldown.teleports")) return; Long currentcd = PConfManager.getPValLong(p, "teleport_cooldown"); if (currentcd != null) { if (currentcd <= new Date().getTime()) { setTeleCooldown(p); return; } p.sendMessage( ChatColor.RED + "You can't teleport for" + ChatColor.GRAY + RUtils.formatDateDiff(currentcd) + ChatColor.RED + "."); e.setCancelled(true); return; } setTeleCooldown(p); }
public void setTeleCooldown(OfflinePlayer p) { double seconds = plugin.gTeleCd; if (seconds <= 0) return; PConfManager.setPValDouble(p, (seconds * 1000) + new Date().getTime(), "teleport_cooldown"); }
@EventHandler public void onKick(PlayerKickEvent e) { PConfManager.setPValLong(e.getPlayer(), new Date().getTime(), "seen"); if (AFKUtils.isAfk(e.getPlayer())) AFKUtils.unsetAfk(e.getPlayer()); if (AFKUtils.moveTimesContains(e.getPlayer())) AFKUtils.removeLastMove(e.getPlayer()); }
@EventHandler public void onPInt(PlayerInteractEvent event) { if (PConfManager.getPValBoolean(event.getPlayer(), "frozen")) event.setCancelled(true); if (plugin.buildPerm) if (!plugin.isAuthorized(event.getPlayer(), "rcmds.build")) event.setCancelled(true); }