How to make Worlds have separate Chat in Code?

Discussion in 'Plugin Development' started by TheWolfBadger, Jul 23, 2014.

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

    TheWolfBadger

    I am wondering how I would make Worlds have separate Chat. For instance: Bob is in World1 and is talking to Jake. John is in World2 and does not see their messages. How would I do this? I've tried it once before with precipitants and it didn't work by removing the ones I didn't want getting the message. Thanks. - Jack
     
  2. Offline

    Dragonphase

  3. Offline

    AoH_Ruthless

    TheWolfBadger
    Sorry about the indentation but I hope it helps! Please don't just copy and paste blindly.

    Code:java
    1. private void shoutToWorld(Player player, String message) {
    2. for (Player p : player.getWorld().getPlayers()) { // Loop through all players in the world
    3. p.sendMessage(message);
    4. }
    5. }
    6.  
    7. // AsyncPlayerChatEvent
    8. // Get the player who sent the message, and pass them through with the event message through #shoutToWorld(Player, String)
    9.  
     
  4. Offline

    1Rogue

    Here's a method that won't break the API conventions:

    Code:java
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent event) {
    3. for(Iterator<Player> itr = event.getRecipients().iterator(); itr.hasNext();) {
    4. if (!itr.next().getWorld().equals(event.getPlayer().getWorld())) {
    5. itr.remove();
    6. }
    7. }
    8. }


    You simply remove anyone from the recipient list that isn't in their world.
     
    Dragonphase likes this.
Thread Status:
Not open for further replies.

Share This Page