Local Chat.

Discussion in 'Plugin Development' started by bkleinman1, Nov 13, 2013.

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

    bkleinman1

    I am trying to make a local chat plugin, i have tried a few things with the AsyncPlayerChatEvent but none have actually worked, if anyone could help me with some code i would be very grateful, so far this is what i have done, it doesnt work:

    Code:java
    1. @EventHandler
    2. public void onPlayerChat(AsyncPlayerChatEvent event) {
    3. Player player = event.getPlayer();
    4. if (localchat.contains(player.getName())) {
    5. List<Entity> near = player.getNearbyEntities(5, 5, 5);
    6. for (Player p : getServer().getOnlinePlayers()){
    7. if (near.contains(p)) {
    8. event.setCancelled(true);
    9. }
    10. }
    11.  
    12. }
    13. }


    I also dont think canceling the event will work to well, as that would end up in the player not even saying it, would there be a way to only show the message for some people.
     
  2. Offline

    adam753

    One option is to cancel the event, and then send a custom-made message to nearby players. Something like, "[LocalChat]PlayerName: message".

    bkleinman1
    I would get rid of this part:
    Code:
    for (Player p : getServer().getOnlinePlayers()){
        if (near.contains(p)) {
            event.setCancelled(true);
    
    Just replace that with a loop through all nearby entities.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page