Plugin Help Different Chat Channels for different distances.

Discussion in 'Plugin Help/Development/Requests' started by HCMatt, Apr 4, 2015.

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

    HCMatt

    There are 3 different chat channels that i need. The global chat, which looks like this:
    Code:
    @EventHandler
        public void onChat(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            Location pLocation = p.getLocation();
            String message = e.getMessage();
    
            for (Player op : Bukkit.getOnlinePlayers()) {
                if (!(op.getLocation().distance(pLocation) <= 16)) {
                    e.getRecipients().remove(op);
                } else {
                    e.getRecipients().remove(op);
                    op.sendMessage("" + getConfig().get("PlayerCard." + p.getName() + ".Name") + ChatColor.DARK_GRAY + " - " + ChatColor.WHITE + e.getMessage());
                }
            }
    
        }
    
    This works perfectly... However, The other two channels are talked in with commands. There is whisper and shout. They are exactly the same thing but with a different radius. Whisper looks like this:


    Code:
    if (cmd.getName().equalsIgnoreCase("wh")) {
                if (args.length == 0) {
                    Player p = (Player) sender;
                    p.sendMessage(ChatColor.RED + "Usage: /wh <message>");
                    return true;
                } else if (args.length > 0) {
                    Player p = (Player) sender;
    
                    String message = " ";
                    for (int i = 0; i != args.length; i++)
                        message += args[i] + " ";
                   
                    String name = (String) getConfig().get("PlayerCard." + p.getName() + ".Name");
    
                    for (Player online : Bukkit.getOnlinePlayers()) {
                        if (!(online.getLocation().distance(p.getLocation()) <= 5)) {
                            if (name == null) {
                                p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_BLUE + "Whisper" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET
                                        + p.getName() + ChatColor.DARK_GRAY + " - " + message);
                                return true;
                            } else {
                                p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_BLUE + "Whisper" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET
                                        + name + ChatColor.DARK_GRAY + " - " + message);
                                return true;
                            }
                        }else {
                            if (name == null) {
                                online.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_BLUE + "Whisper" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET
                                        + p.getName() + ChatColor.DARK_GRAY + " - " + message);
                            } else {
                                online.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_BLUE + "Whisper" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET
                                        + name + ChatColor.DARK_GRAY + " - " + message);
                            }
                        }
                    }
                }
    The 'String name = (String) getConfig()' part is another part of the plugin where someone can type /setname <name> and it will use the name they set when they type.

    When there are just 2 people online, it works fine. But when there are two people online, the ammount of people that aren't in range is the amount of times i get sent the
    Code:
    p.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_BLUE + "Whisper" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET
                                        + p.getName() + ChatColor.DARK_GRAY + " - " + message);
    Please help. Thanks

    Matty.
     
Thread Status:
Not open for further replies.

Share This Page