Hey Guys,. I want to put a world chat thingy into my server but I should use stuff out of my own plugin so IM not able to use plugins for it, that is the reason why I tested something but it didnt work. Can someone help me? Code: Code: @EventHandler public void onChat (AsyncPlayerChatEvent e) { Player p = e.getPlayer(); World w = p.getLocation().getWorld(); String m = e.getMessage(); e.setFormat(w.getName() + " " + p.getName() + " " + m); String f = e.getFormat(); e.setCancelled(true); for(Player wp : w.getPlayers()) { wp.sendMessage(f); } }
@MrFrozen That is not how you prevent players from seeing messages. You should remove the players that shouldn't see the message from the recipient set obtainable from the AsyncPlayerChatEvent.
The recipents list = e.getRecipents(); Clear the list, and when you loop through your players, instead of sending them a message add them to the recipents list.
This is the code I used to make my per world chat plugin. There are some things in there specific for my plugin. But the general concept is, on a playerchatevent it checks if they are using the override and doesn't do anything, if they are not using the override, it clears out all recipients, adds the sender to the list, then loops through all online players, if the player is in the same world, or in the world group, it adds them back to the recipients list. Once it has looped through all players, it sends the message. Code: @EventHandler(priority = EventPriority.HIGHEST) public void onChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); UUID Id = player.getUniqueId(); if (event.isCancelled()) { return; } else { if ((event.getMessage().contains(plugin.getConfig().getString("Override")) && (player.hasPermission("pwcp.bypass"))) || plugin.data.getString("Players." + Id + ".Bypass").equalsIgnoreCase("True")) { String gPrefix = plugin.getConfig().getString("Global Prefix"); String prefix = (ChatColor.translateAlternateColorCodes('&', gPrefix) + " " + ChatColor.RESET); event.setFormat(prefix + event.getFormat()); event.setMessage(event.getMessage().replaceAll(plugin.getConfig().getString("Override"), "").trim()); return; } else { String w = player.getWorld().getName(); if (!(plugin.shares.contains(w))) { event.getRecipients().clear(); for (Player p : Bukkit.getOnlinePlayers()) { UUID pId = p.getUniqueId(); if (p.getLocation().getWorld().getName() == w) { event.getRecipients().add(p); } if (plugin.data.getString("Players." + pId + ".Spy").equalsIgnoreCase("True") && !event.getRecipients().contains(p)) { event.getRecipients().add(p); } if (plugin.alerts.contains("Alerts." + pId)) { for (String word : plugin.alerts.getStringList("Alerts." + pId)) { if (event.getMessage().contains(word)) { if (!event.getRecipients().contains(p)) { event.getRecipients().add(p); } p.playSound(p.getLocation(), Sound.LEVEL_UP, 1f, 0f); } } } } event.setFormat(event.getFormat()); event.setMessage(event.getMessage()); return; } else { event.getRecipients().clear(); for (Player p : Bukkit.getOnlinePlayers()) { String wo = p.getLocation().getWorld().getName(); if (plugin.shares.getStringList(w).contains(wo)) { event.getRecipients().add(p); } if (p.getLocation().getWorld().getName() == w) { event.getRecipients().add(p); } UUID pId = p.getUniqueId(); if (plugin.data.getString("Players." + pId + ".Spy").equalsIgnoreCase("True") && !event.getRecipients().contains(p)) { event.getRecipients().add(p); } if (plugin.alerts.contains("Alerts." + pId)) { for (String word : plugin.alerts.getStringList("Alerts." + pId)) { if (event.getMessage().contains(word)) { if (!event.getRecipients().contains(p)) { event.getRecipients().add(p); } p.playSound(p.getLocation(), Sound.LEVEL_UP, 1f, 0f); } } } } event.setFormat(event.getFormat()); event.setMessage(event.getMessage()); return; } } } } } If you need more help with it, just tahg me please. (I registered the listener on highest priority to override some other plugins because I conflicted with them, but HIGH should be okay for you)