Example #1
0
  @Override
  public void run(Server server, CommandSender sender, String commandLabel, String[] args)
      throws Exception {
    if (args.length < 2 || args[0].trim().isEmpty() || args[1].trim().isEmpty()) {
      throw new NotEnoughArgumentsException();
    }

    String message = getFinalArg(args, 1);
    String translatedMe = Util.i18n("me");

    IReplyTo replyTo =
        sender instanceof Player ? ess.getUser((Player) sender) : Console.getConsoleReplyTo();
    String senderName =
        sender instanceof Player ? ((Player) sender).getDisplayName() : Console.NAME;

    if (args[0].equalsIgnoreCase(Console.NAME)) {
      sender.sendMessage(Util.format("msgFormat", translatedMe, Console.NAME, message));
      CommandSender cs = Console.getCommandSender(server);
      cs.sendMessage(Util.format("msgFormat", senderName, translatedMe, message));
      replyTo.setReplyTo(cs);
      Console.getConsoleReplyTo().setReplyTo(sender);
      return;
    }

    List<Player> matches = server.matchPlayer(args[0]);

    if (matches.isEmpty()) {
      sender.sendMessage(Util.i18n("playerNotFound"));
      return;
    }

    charge(sender);
    for (Player p : matches) {
      sender.sendMessage(Util.format("msgFormat", translatedMe, p.getDisplayName(), message));
      final User u = ess.getUser(p);
      if (sender instanceof Player
          && (u.isIgnoredPlayer(((Player) sender).getName()) || u.isHidden())) {
        continue;
      }
      p.sendMessage(Util.format("msgFormat", senderName, translatedMe, message));
      replyTo.setReplyTo(ess.getUser(p));
      ess.getUser(p).setReplyTo(sender);
    }
  }
 @Override
 public void onPlayerChat(final PlayerChatEvent event) {
   final User user = ess.getUser(event.getPlayer());
   if (user.isMuted()) {
     event.setCancelled(true);
     user.sendMessage(Util.i18n("playerMuted"));
     LOGGER.info(Util.format("mutedUserSpeaks", user.getName()));
   }
   final Iterator<Player> it = event.getRecipients().iterator();
   while (it.hasNext()) {
     final User u = ess.getUser(it.next());
     if (u.isIgnoredPlayer(user.getName())) {
       it.remove();
     }
   }
   user.updateActivity(true);
   if (ess.getSettings().changeDisplayName()) {
     user.setDisplayName(user.getNick());
   }
 }
Example #3
0
	@Override
	public int broadcastMessage(final IUser sender, final String message)
	{
		if (sender == null)
		{
			return getServer().broadcastMessage(message);
		}
		if (sender.isHidden())
		{
			return 0;
		}
		final Player[] players = getServer().getOnlinePlayers();

		for (Player player : players)
		{
			final User user = getUser(player);
			if (!user.isIgnoredPlayer(sender.getName()))
			{
				player.sendMessage(message);
			}
		}

		return players.length;
	}