@Override
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();

    String[] split = event.getMessage().split(" ");
    int numParams = split.length - 1;
    if (!(plugin.optionsMap.containsKey("oncommand|" + split[0])
        || plugin.optionsMap.containsKey("oncommand|" + split[0] + "|" + numParams)
        || plugin.optionsMap.containsKey("oncommand|" + split[0] + "|override")
        || plugin.optionsMap.containsKey("oncommand|" + split[0] + "|override|" + numParams)))
      return;

    List<String> replaceThese = new LinkedList<String>();
    List<String> withThese = new LinkedList<String>();
    /* Build parameter list */
    StringBuilder params = new StringBuilder();
    StringBuilder reverseParams = new StringBuilder();
    String prefix = "";
    int max = split.length;
    for (int i = 1; i < max; i++) {
      params.append(prefix + split[i]);
      reverseParams.insert(0, split[max - i] + prefix);
      prefix = " ";

      replaceThese.add("<<param" + Integer.toString(i) + ">>");
      withThese.add(split[i]);

      replaceThese.add("<<param" + Integer.toString(i) + "->>");
      withThese.add(params.toString());

      replaceThese.add("<<param" + Integer.toString(max - i) + "\\+>>");
      withThese.add(reverseParams.toString());
    }
    replaceThese.add("<<params>>");
    withThese.add(params.toString());
    String[] replaceTheseArray = replaceThese.toArray(new String[replaceThese.size()]);
    String[] withTheseArray = withThese.toArray(new String[withThese.size()]);

    plugin.triggerMessages(player, "oncommand|" + split[0], replaceTheseArray, withTheseArray);

    if (split[0].equalsIgnoreCase("/rTriggers")) {
      plugin.triggerMessages(player, "onrTriggers", replaceTheseArray, withTheseArray);
      event.setCancelled(true);
    }

    if (plugin.triggerMessages(
            player, "oncommand|" + split[0] + "|override", replaceTheseArray, withTheseArray)
        || plugin.triggerMessages(
            player,
            "oncommand|" + split[0] + "|override|" + numParams,
            replaceTheseArray,
            withTheseArray)) {
      event.setCancelled(true);
    }

    return;
  }
 @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);
 }
示例#3
0
  private void handleCommand(String s) {
    // CraftBukkit start
    CraftPlayer player = (CraftPlayer) getPlayer();

    PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(player, s);
    server.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
      return;
    }

    try {
      if (server.dispatchCommand(player, s.substring(1))) {
        return;
      }
    } catch (CommandException ex) {
      player.sendMessage(
          ChatColor.RED + "An internal error occurred while attempting to perform this command");
      Logger.getLogger(NetServerHandler.class.getName()).log(Level.SEVERE, null, ex);
      return;
    }
    // CraftBukkit end

    if (s.toLowerCase().startsWith("/me ")) {
      s = "* " + this.player.name + " " + s.substring(s.indexOf(" ")).trim();
      a.info(s);
      this.minecraftServer.serverConfigurationManager.sendAll(new Packet3Chat(s));
    } else if (s.toLowerCase().startsWith("/kill")) {
      this.player.damageEntity((Entity) null, 1000);
    } else if (s.toLowerCase().startsWith("/tell ")) {
      String[] astring = s.split(" ");

      if (astring.length >= 3) {
        s = s.substring(s.indexOf(" ")).trim();
        s = s.substring(s.indexOf(" ")).trim();
        s = "\u00A77" + this.player.name + " whispers " + s;
        a.info(s + " to " + astring[1]);
        if (!this.minecraftServer.serverConfigurationManager.a(
            astring[1], (Packet) (new Packet3Chat(s)))) {
          this.sendPacket(new Packet3Chat("\u00A7cThere\'s no player by that name online."));
        }
      }

      /* CraftBukkit start - No longer neaded av we have already handled it server.dispatchCommand above.
      } else {
          String s1;

          if (this.minecraftServer.serverConfigurationManager.isOp(this.player.name)) {
              s1 = s.substring(1);
              a.info(this.player.name + " issued server command: " + s1);
              this.minecraftServer.issueCommand(s1, this);
          } else {
              s1 = s.substring(1);
              a.info(this.player.name + " tried command: " + s1);
          }
      */
      // CraftBukkit end
    }
  }
	@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
	public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());
		final String cmd = spaceSplit.split(event.getMessage().toLowerCase(Locale.ENGLISH))[0].replace("/", "").toLowerCase(Locale.ENGLISH);
		if (ess.getSettings().getData().getCommands().getSocialspy().getSocialspyCommands().contains(cmd))
		{
			for (Player player : ess.getServer().getOnlinePlayers())
			{
				IUser spyer = userMap.getUser(player);
				if (spyer.getData().isSocialspy() && !user.equals(spyer))
				{
					player.sendMessage(user.getPlayer().getDisplayName() + " : " + event.getMessage());
				}
			}
		}
		if (!cmd.equalsIgnoreCase("afk"))
		{
			user.updateActivity(true);
		}
	}
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String command = event.getMessage();
    Player p = event.getPlayer();

    TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
    playerdata.incrementMsgCount();
    playerdata.setLastCommand(command);

    if (playerdata.getMsgCount() > 10) {
      TFM_Util.bcastMsg(
          p.getName() + " was automatically kicked for spamming commands.", ChatColor.RED);
      TFM_Util.autoEject(p, "Kicked for spamming commands.");

      playerdata.resetMsgCount();

      TFM_Util.TFM_EntityWiper.wipeEntities(true, true);

      event.setCancelled(true);
      return;
    }

    if (playerdata.allCommandsBlocked()) {
      TFM_Util.playerMsg(p, "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_SuperadminList.isUserSuperadmin(p)) {
        for (String test_command : BLOCKED_MUTED_CMDS) {
          if (Pattern.compile("^/" + test_command.toLowerCase() + " ").matcher(command).find()) {
            p.sendMessage(ChatColor.RED + "That command is blocked while you are muted.");
            event.setCancelled(true);
            return;
          }
        }
      } else {
        playerdata.setMuted(false);
      }
    }

    if (TotalFreedomMod.preprocessLogEnabled) {
      TFM_Log.info(
          String.format(
              "[PREPROCESS_COMMAND] %s(%s): %s",
              p.getName(), ChatColor.stripColor(p.getDisplayName()), command),
          true);
    }

    command = command.toLowerCase().trim();

    // Blocked commands
    if (TFM_CommandBlockerNew.getInstance().isCommandBlocked(command, event.getPlayer())) {
      // CommandBlocker handles messages and broadcasts
      event.setCancelled(true);
    }

    if (!TFM_SuperadminList.isUserSuperadmin(p)) {
      for (Player pl : Bukkit.getOnlinePlayers()) {
        if (TFM_SuperadminList.isUserSuperadmin(pl)
            && TFM_PlayerData.getPlayerData(pl).cmdspyEnabled()) {
          TFM_Util.playerMsg(pl, p.getName() + ": " + command);
        }
      }
    }
  }
  @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);
    }
  }