Local Chat?

Discussion in 'Plugin Development' started by flyingtacoz, Sep 9, 2012.

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

    flyingtacoz

    Is it possible, to make it so you only see messages from people in a 100x100 or so radius?
     
  2. Offline

    JazzaG

    Yes. The best way I can think of it ATM is;
    1. On PlayerChatEvent, store the message into a variable, along with the display name of who sent it
    2. Set the message to null
    3. Get a list of all nearby players
    4. Send the message to those players
     
  3. Why not cancel the event instead?
     
  4. Offline

    makskay

    Actually, just setting the recipients is a better approach than either of the above.

    Code:
    event.getRecipients().clear();
     
    for (Player player : aCollectionOfNearbyPlayers) {
        event.getRecipients().add(player);
    }
    
    Edit: Ignore this, it's more optimal to do as V10lator said above.
     
  5. makskay So it's better to clear and re-populate the recipients of the event instead of cancelling it and sending it by hand...? Please explain why (hint: have a look here before you reply).
     
  6. Offline

    makskay

    ...good point, you win xP
     
  7. Offline

    JazzaG

    Whoops...wasn't thinking when I wrote that :s
     
  8. Offline

    makskay

    In my defense, there is one reason I can think of to directly alter the senders instead of canceling the event and resending it to each player: to maintain compatibility with other chat plugins that alter message formatting, especially when these plugins are listening at a higher priority than your own.

    Messages sent to players with Player.sendMessage() don't throw AsyncPlayerChatEvents and as such can't be processed by other formatting plugins, which can break compatibility with plugins like EssentialsChat that embed tags in messages early on and replace those tags with color codes at a higher priority.

    Since I'm currently working on a chat plugin and have to maintain compatibility with others while altering message recipients, I'm used to doing it the way I suggested above. If you're not concerned about conflicts with other plugins then V10lator's method is indeed way more optimized.
     
    V10lator likes this.
  9. Offline

    krazyswaggaO

    From some other thread:

    EntityLocation entityloc = new EntityLocation(player);
    for (Player p : player.getWorld().getPlayers()) {
    Integer distance = entityloc.getDistance(p);
    if(distance < (your number here)){
    ....
    }
     
  10. Offline

    Sagacious_Zed Bukkit Docs

  11. Offline

    flyingtacoz

  12. Offline

    Sagacious_Zed Bukkit Docs

    That is also not that much more difficult.
     
Thread Status:
Not open for further replies.

Share This Page