PerWorldChat and PerWorldTab

Discussion in 'Spigot Plugin Development' started by MangoCodes, Jun 5, 2016.

  1. Does anyone know on how I could go about doing this?
     
  2. For the chat you can cancel event and then loop all players in the same world the player that sended the message is.

    For tab you can listen for PacketPlayOutPlayerInfo and just show the players in the current world.
     
  3. Never cancel the chat event just to send a message to all players in replace.. that breaks so many things :s

    Instead, simply iterate the recipients and remove the ones that are not in the same world as the chat sender. Simple.

    Code (Text):

    public void onChat(PlayerAsyncChatEvent event) {
        Iterator iter = event.getRecipients().iterator();
        while(iter.hasNext()) {
            if (!iter.next().getWorld().equals(event.getPlayer.getWorld())) {
                iter.remove();
            }
        }
    }
     
    That is the general idea for per world chat. Wrote code on phone, so may contain typos. ;)
     
    #3 BillyGalbreath, Jun 8, 2016
    Last edited: Jun 8, 2016
  4. For PerWorldTab:

    Code (Java):
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
    setup(e.getPlayer());
    }

    @EventHandler
    public void onWorldChange(PlayerChangedWorldEvent e) {
    setup(e.getPlayer());
    }

    public void setup(Player p) {
    for(Player o : Bukkit.getOnlinePlayers()) {
    if(o.getName().equals(p.getName())) continue;

    if(!o.getWorld().getName().equals(p.getWorld().getName())) {
    o.hidePlayer(p);
    p.hidePlayer(o);
    } else {
    o.showPlayer(p);
    p.showPlayer(o);
    }
    }