Problem/Bug Messaging Sending 2 Messages Each Time.

Discussion in 'Plugin Help/Development/Requests' started by PoseidonGraphics, Mar 29, 2015.

Thread Status:
Not open for further replies.
  1. **BEFORE COMMENTING "Don't store player in hashmap" I already know!

    So when ever I message a player it seems to send twice. (For both of us) I have changed the code multiple times trying for a fix without any luck.

    Left out some stuff for other commands in plugin.

    The (Message.send(online) is a Title.
    same for the Reply.send

    CODE:
    Code:
                if (cmd.getName().equalsIgnoreCase("message") || cmd.getName().equalsIgnoreCase("msg") || cmd.getName().equalsIgnoreCase("pm") || cmd.getName().equalsIgnoreCase("tell") || cmd.getName().equalsIgnoreCase("m")) {
                if (args.length < 2) {
                    player.sendMessage(ChatColor.RED + "/Message {Player} {Message}");
                    return true;
                }
                if (args.length > 1) {
                    Player online = Bukkit.getPlayer(args[0]);
                    if (online ==  null || !online.isOnline()) {
                        player.sendMessage(ChatColor.RED + "Player Not Found");
                    } else {
                        StringBuilder x = new StringBuilder();
                        for(int i = 1; i < args.length; i++) {
                            x.append(args[i] + " ");
                        }
                        reply.put(player, online);
                        reply.put(online, player);
                        player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("sender") + sender.getName() + ChatColor.translateAlternateColorCodes('&', getConfig().getString("playersplit") + getConfig().getString("Between") + ChatColor.translateAlternateColorCodes('&', getConfig().getString("recieve") + online.getName() + getConfig().getString("Ending")+ " " + ChatColor.GRAY  + ChatColor.translateAlternateColorCodes('&', x.toString().trim())))));
                        online.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("sender") + sender.getName() + ChatColor.translateAlternateColorCodes('&', getConfig().getString("playersplit") + getConfig().getString("Between") + ChatColor.translateAlternateColorCodes('&', getConfig().getString("recieve") + online.getName() + getConfig().getString("Ending")+ " " + ChatColor.GRAY  + ChatColor.translateAlternateColorCodes('&', x.toString().trim())))));
                        if (UseSound) {
                            online.getWorld().playSound((online.getLocation()), Sound.valueOf(getConfig().getString("sound1")), 1, 1);
                            online.getWorld().playSound((online.getLocation()), Sound.valueOf(getConfig().getString("sound2")), 1, 1);
                        }
                        if (UseEffect) {
                            online.getWorld().playEffect((online.getLocation()), Effect.valueOf(getConfig().getString("effect")), 1, 1);
                        }
                        if (UseTitle) {
                            Message.send(online);
                        }
                    }
                }
            }
            if (cmd.getName().equalsIgnoreCase("reply") || cmd.getName().equalsIgnoreCase("r")) {
                Player online = reply.get(player);
                if (args.length < 0) {
                    player.sendMessage(ChatColor.RED + "/Reply {Message}");
                    return true;
                }
                if (args.length > 0) {
                            StringBuilder x = new StringBuilder();
                            for(int i = 0; i < args.length; i++) {
                                x.append(args[i] + " ");
                            }
                            reply.put(player, online);
                            reply.put(online, player);
                            player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("sender") + sender.getName() + ChatColor.translateAlternateColorCodes('&', getConfig().getString("playersplit") + getConfig().getString("Between") + ChatColor.translateAlternateColorCodes('&', getConfig().getString("recieve") + online.getName() + getConfig().getString("Ending")+ " " + ChatColor.GRAY  + ChatColor.translateAlternateColorCodes('&', x.toString().trim())))));
                            online.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("sender") + sender.getName() + ChatColor.translateAlternateColorCodes('&', getConfig().getString("playersplit") + getConfig().getString("Between") + ChatColor.translateAlternateColorCodes('&', getConfig().getString("recieve") + online.getName() + getConfig().getString("Ending")+ " " + ChatColor.GRAY  + ChatColor.translateAlternateColorCodes('&', x.toString().trim())))));
                            if (UseSound) {
                                online.getWorld().playSound((online.getLocation()), Sound.valueOf(getConfig().getString("sound1")), 1, 1);
                                online.getWorld().playSound((online.getLocation()), Sound.valueOf(getConfig().getString("sound2")), 1, 1);
                            }
                            if (UseEffect) {
                                online.getWorld().playEffect((online.getLocation()), Effect.valueOf(getConfig().getString("effect")), 1, 1);
                            }
                            if (UseTitle) {
                                Reply.send(online);
                            }
                    }
                }
            }
            return true;
        }
    }
     
  2. Invisible

    nverdier

    @PoseidonGraphics Actually, it's fine to store a Player in a Collection. At least if you handle it properly. Remove them when they leave, or use a WeakReference/WeakHashMap.
     
  3. @nverdier See the problem? I've still been looking at it with no luck.
     
  4. Bumping, Still haven't found a fix.
     
Thread Status:
Not open for further replies.

Share This Page