per wold chat?

Discussion in 'Plugin Development' started by rmb938, Aug 13, 2011.

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

    rmb938

    Is there any easy way to do per world chat? The only way I know would work is loop through all the players.
     
  2. Nope, but isn't that easy aswell?

    Iterate through the sender's world and send them that message.
     
  3. PlayerChatEvent
    getRecipients()

    Loop through recipients and check if they are in the same world as the sender. Can't imagine anything easier than that.
     
  4. Offline

    feildmaster

    Set a playersworld map, when they join/teleport worlds, set the player to be in that world, and remove him from old world.

    then get the world and iterate through the players stored in it.
     
  5. Offline

    cholo71796

    Out of curiosity, what is the difference between getRecipients on the event and getOnlinePlayers on the server?
     
  6. Offline

    niccholaspage

    None, except by removing players from the recipients you don't have to cancel the event and
    send the message to each individual player. In the source for the chat event:
    Code:
    recipients = new HashSet<Player>(Arrays.asList(player.getServer().getOnlinePlayers()));
     
  7. recipients default to every online player. But they were made to be able to modify that. So why should you do your stuff manually (and maybe bypass plugins that do something with the event like logging it) when there is a built in method for it?

    Also, when your plugin isn't the first one to handle the event, others might have already changed the recipients. Imagine an AdminChat plugin listening on Priority.Normal and you listen on Priority.Highest. When you get the event, there are only admins in the recipients, and you can further control it.
    If you would go on sending it to every online player in the same world, you ignore what the AdminChat plugin did and the "secret message to the other admins" would go public ;)
     
  8. Offline

    feildmaster

    @Bone008 : On an unrelated note to this topic... I hate when people use Priority.Highest. They need to start using Priority.High. Just because they THINK their plugin is the best, and needs to be last, doesn't mean it is/does.
     
  9. In this case, the order wouldn't change anything (if both plugins are well-coded using recipients), so priorities wouldn't matter.
    But in general, it always depends on the event and what you do with it.
    And using Highest is still better than Monitor if you change stuff (what beginners still use to do from time to time :/)
     
  10. Offline

    feildmaster

    Priorities always matter. You should always take into account if your plugin should be considered the "final" or "first" plugin. If it doesn't matter, "Normal." If it should run early, "Low." If you think someone should be able to change/use the info you have set, "High." And in the off chance you really need to be last (Very few plugins ever need to be last...), "Highest."

    Everyone should have the mentality of... "I want this plugin to be able to be used by other plugins." Not... "This part is important to my plugin, so I will go highest!" or something of that effect.
     
  11. With "priorities wouldn't matter", I was trying to say that the outcome of that particular example (admin chat & per world chat) does not depend on priorities. Sorry if that was misleading, I didn't mean that you could slap priorities out.
    Other than that, you are certainly right.
     
Thread Status:
Not open for further replies.

Share This Page