@Override
 @Localized({
   "CRAZYCHATS.CHANNEL.CHANGED $Channel$",
   "CRAZYCHATS.COMMAND.CHANNEL.PRIVATE.TARGET.REMOVED $Players$"
 })
 public void command(final Player player, final String[] args) throws CrazyException {
   final ChatPlayerData data = plugin.getPlayerData(player);
   final PrivateChannel channel = data.getPrivateChannel();
   final Set<Player> targets = channel.getTargets(null);
   if (args.length == 0) throw new CrazyCommandUsageException("<Player...>");
   else {
     final List<Player> targetList = new ArrayList<Player>();
     for (final String arg : args) {
       final Player target = Bukkit.getPlayerExact(arg);
       if (target == null || !player.canSee(target))
         throw new CrazyCommandNoSuchException("Player", arg);
       targetList.add(target);
     }
     targets.removeAll(targetList);
     if (data.getCurrentChannel() != channel) {
       data.setCurrentChannel(channel);
       plugin.sendLocaleMessage("CHANNEL.CHANGED", player, channel.getName());
     }
     plugin.sendLocaleMessage(
         "COMMAND.CHANNEL.PRIVATE.TARGET.REMOVED",
         player,
         ChatHelper.listingString(OfflinePlayerParamitrisable.getPlayerNames(targetList)));
   }
 }
Exemple #2
0
	private String getLocal(final IUser user, final long radius)
	{
		final Location loc = user.getPlayer().getLocation();
		final World world = loc.getWorld();
		final StringBuilder output = new StringBuilder();
		final long radiusSquared = radius * radius;
		Player userPlayer = user.getPlayer();

		for (Player onlinePlayer : server.getOnlinePlayers())
		{
			if (!onlinePlayer.getName().equals(user.getName()) && userPlayer.canSee(onlinePlayer))
			{
				final Location playerLoc = onlinePlayer.getLocation();
				if (playerLoc.getWorld() != world)
				{
					continue;
				}

				final long delta = (long)playerLoc.distanceSquared(loc);
				if (delta < radiusSquared)
				{
					if (output.length() > 0)
					{
						output.append(", ");
					}
					output.append(onlinePlayer.getDisplayName()).append("§f(§4").append((long)Math.sqrt(delta)).append("m§f)");
				}
			}
		}
		return output.length() > 1 ? output.toString() : _("none");
	}
  @Override
  public Boolean get(Player player, EventData data) throws BailException {
    Player otherPlayer = otherPlayerDP.get(data);
    if (otherPlayer == null) return null;

    return player.canSee(otherPlayer);
  }
  /**
   * Executed on tab completion for this command, returning a list of options the player can tab
   * through.
   *
   * @param sender Source object which is executing this command
   * @param alias the alias being used
   * @param args All arguments passed to the command, split via ' '
   * @return a list of tab-completions for the specified arguments. This will never be null. List
   *     may be immutable.
   * @throws IllegalArgumentException if sender, alias, or args is null
   */
  public List<String> tabComplete(CommandSender sender, String alias, String[] args)
      throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 0) {
      return ImmutableList.of();
    }

    String lastWord = args[args.length - 1];

    Player senderPlayer = sender instanceof Player ? (Player) sender : null;

    ArrayList<String> matchedPlayers = new ArrayList<String>();
    for (Player player : sender.getServer().getOnlinePlayers()) {
      String name = player.getName();
      if ((senderPlayer == null || senderPlayer.canSee(player))
          && StringUtil.startsWithIgnoreCase(name, lastWord)) {
        matchedPlayers.add(name);
      }
    }

    Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
    return matchedPlayers;
  }
	@Override
	protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		final String whois = args[0].toLowerCase(Locale.ENGLISH);
		boolean foundUser = false;
		final Player player = sender instanceof IUser ? ((IUser)sender).getPlayer() : null;
		final IUserMap userMap = ess.getUserMap();
		for (Player onlinePlayer : server.getOnlinePlayers())
		{
			final IUser u = userMap.getUser(onlinePlayer);
			if (player != null && !player.canSee(onlinePlayer))
			{
				continue;
			}
			final Player realPlayer = u.getPlayer();
			final String displayName = FormatUtil.stripFormat(realPlayer.getDisplayName()).toLowerCase(Locale.ENGLISH);
			if (displayName.contains(whois))
			{
				foundUser = true;
				sender.sendMessage(realPlayer.getDisplayName() + " " + _("is") + " " + u.getName());
			}
		}
		if (!foundUser)
		{
			throw new NoSuchFieldException(_("Player not found."));
		}
	}
Exemple #6
0
  /**
   * Checks that player is not trying to combatlog/is allowed to teleport Returns an error message
   * to be displayed if the player is not allowed to teleport Returns null if the player is allowed
   * to teleport
   */
  private static String teleportCheck(Player player) {

    Location pLoc = player.getLocation();

    World world = player.getWorld();

    /* Check if there are any players within 50 blocks */
    for (Player p : world.getPlayers()) {

      if (!p.equals(player)
          && p.getLocation().distance(pLoc) < 50
          && player.canSee(p)
          && !p.isDead()) {
        return ChatColor.RED
            + "You cannot use this command while within 50 blocks of any other players.";
      }
    }

    /* Check if there are any hostile mobs within 5 blocks */
    for (Entity entity :
        world.getEntitiesByClasses(
            Blaze.class,
            CaveSpider.class,
            Creeper.class,
            Enderman.class,
            Ghast.class,
            MagmaCube.class,
            PigZombie.class,
            Skeleton.class,
            Silverfish.class,
            Slime.class,
            Spider.class,
            Witch.class,
            Zombie.class)) {

      if (entity.getLocation().distance(pLoc) < 5) {
        return ChatColor.RED
            + "You cannot use this command while within 5 blocks of any hostile mobs.";
      }
    }

    /* Check if the player is falling */
    if (player.getVelocity().getY() < -0.079 || player.getVelocity().getY() > 0.08) {
      return ChatColor.RED + "You cannot use this command while falling.";
    }

    /* Check if the player is burning */
    if (player.getFireTicks() > 0 && !player.hasPotionEffect(PotionEffectType.FIRE_RESISTANCE)) {
      return ChatColor.RED + "You cannot use this command while on fire.";
    }

    /* Default to allow teleport */
    return null;
  }
Exemple #7
0
 public static void sendPacketsNearby(
     Player from, Location location, Collection<Packet> packets, double radius) {
   radius *= radius;
   final org.bukkit.World world = location.getWorld();
   for (Player ply : Bukkit.getServer().getOnlinePlayers()) {
     if (ply == null || world != ply.getWorld() || (from != null && !ply.canSee(from))) {
       continue;
     }
     if (location.distanceSquared(ply.getLocation(PACKET_CACHE_LOCATION)) > radius) {
       continue;
     }
     for (Packet packet : packets) {
       sendPacket(ply, packet);
     }
   }
 }
Exemple #8
0
  /** Have player send msg to target */
  public static void sendPM(Player player, Player target, String msg, boolean is_target_server) {

    /* String of the player, in case it's null and it should
     * be 'Server' */
    String splayer;
    UUID uplayer = null;
    if (player == null) {
      splayer = "Server";
    } else {
      splayer = player.getName();
      uplayer = player.getUniqueId();
    }

    if (target == null && !is_target_server) {
      /* Yes this is confusing, but the message is
       * imitating default (Notchian) behavior */
      send_msg(player, "[" + splayer + ": That player cannot be found]", ChatColor.GRAY);
      return;
    }

    String starget;
    UUID utarget = null;
    if (target == null) {
      starget = "Server";
    } else {
      starget = target.getName();
      utarget = target.getUniqueId();
    }

    /* Don't let people figure out if a vanished admin is
     * online or not */
    if (player == null || target == null || player.canSee(target)) {
      send_msg(player, "-->" + starget + ": " + msg, ChatColor.GRAY);
      PMCommands.mPlayerList.put(uplayer, utarget);
    } else {
      send_msg(player, "[" + splayer + ": That player cannot be found]", ChatColor.GRAY);
    }

    /* Only actually send the message to the recipient if they're
     * not ignoring the sender */
    if (player == null || !Storage.getIsIgnoring(target, player)) {
      send_msg(target, "<--" + splayer + ": " + msg, ChatColor.GRAY);
      PMCommands.rPlayerList.put(utarget, uplayer);
    }

    return;
  }
Exemple #9
0
 /**
  * Flicker the player for anyone who can see him.
  *
  * @param player
  */
 public static void refreshPlayer(Player player) {
   TagAPI.check();
   if (player == null) {
     throw new TagAPIException("Can't submit null player!");
   }
   if (!player.isOnline()) {
     throw new TagAPIException("Can't submit offline player!");
   }
   final ShowBomb bomb = TagAPI.instance.new ShowBomb();
   for (final Player otherGuy : player.getWorld().getPlayers()) {
     if ((!otherGuy.equals(player)) && otherGuy.canSee(player)) {
       otherGuy.hidePlayer(player);
       bomb.queue(TagAPI.instance.new RefreshPair(otherGuy, player));
     }
   }
   TagAPI.instance.getServer().getScheduler().scheduleSyncDelayedTask(TagAPI.instance, bomb, 2);
 }
 public List<String> onTabComplete(
     CommandSender sender, Command command, String label, String[] args) {
   if ((args.length != 2) || (!(sender instanceof Player))) {
     return Collections.emptyList();
   }
   if (args[1].isEmpty()) {
     return null;
   }
   Player player = (Player) sender;
   List<String> results =
       new ArrayList(this.plugin.getFactionManager().getFactionNameMap().keySet());
   for (Player target : Bukkit.getOnlinePlayers()) {
     if ((player.canSee(target)) && (!results.contains(target.getName()))) {
       results.add(target.getName());
     }
   }
   return results;
 }
Exemple #11
0
 /**
  * Flicker the player for a player who can see him.
  *
  * @param player
  * @param forWhom
  */
 public static void refreshPlayer(Player player, Player forWhom) {
   TagAPI.check();
   if (player == null) {
     throw new TagAPIException("Can't submit null player!");
   }
   if (forWhom == null) {
     throw new TagAPIException("Can't submit null forWhom!");
   }
   if (player.equals(forWhom)) {
     throw new TagAPIException("Can't submit player on self!");
   }
   final ShowBomb bomb = TagAPI.instance.new ShowBomb();
   if (forWhom.canSee(player) && player.getWorld().equals(forWhom.getWorld())) {
     forWhom.hidePlayer(player);
     bomb.queue(TagAPI.instance.new RefreshPair(forWhom, player));
   }
   TagAPI.instance.getServer().getScheduler().scheduleSyncDelayedTask(TagAPI.instance, bomb, 2);
 }
Exemple #12
0
 public boolean isHidden(final Player player) {
   return hidden || !player.canSee(getBase());
 }