How to do so that players could see what is written on chat in the distance 5 or 25 meters?

Discussion in 'Plugin Development' started by Growl, Mar 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Growl

    Hello, I need a help! How to do so that could players see what is written by other players in a chat, in the distance 5 and 25 meters?
     
  2. Offline

    StealerSlain

    All you need:
    some magic with AsyncPlayerChatEvent
    and this code
    Code:java
    1. Player p = e.getPlayer();
    2. double maxDist = 25;
    3. for (Player other : Bukkit.getOnlinePlayers()) {
    4. if (other.getLocation().distance(player.getLocation()) <= maxDist) {
    5. other.sendMessage("your message here");
    6. }
    7. }
     
    Growl likes this.
  3. Offline

    willeb96

    Cancel the chat event, loop through all players, check distance, send separate message if the player is within a radius.
     
  4. Offline

    drtshock

    No :c

    You can just modify the recipients in the AsyncPlayerChatEvent.
     
  5. Offline

    Barinade

  6. Offline

    willeb96

    Hmm, didn't know that.
    So would it be
    Code:java
    1.  
    2. for (Player player : Bukkit.getOnlinePlayers()) {
    3. if (event.getPlayer().getLocation().distance(player.getLocation()) > 25) {
    4. event.getRecipients().remove(player);
    5. }
    6. }

    ?
     
    drtshock likes this.
  7. Offline

    drtshock

    Yep! That way if another plugin is trying to handle the event, you won't break it :)
     
    willeb96 likes this.
  8. Offline

    Barinade

    "The set returned is not guaranteed to be mutable"
    How true is that?
     
  9. Offline

    drtshock

    Not sure but I've never had an issue with it. It's how I've always done things like per-arena chat.
     
  10. Offline

    Barinade

    Even if it didn't work there's probably a workaround to either make sure it did or use an alternate method.
    Experience matters, I guess.
     
Thread Status:
Not open for further replies.

Share This Page