Plugin Help Giving player a warning if duplicate messages are send

Discussion in 'Plugin Help/Development/Requests' started by GeeSplit, Aug 19, 2015.

Thread Status:
Not open for further replies.
  1. Hello,

    What I am trying to do is, when a player says something, the plugin saves that message. If the player says that message again, it'll warn the player that you're not allowed to post duplicate messages.

    The chat listener section:
    Code:
    if (DuplicateMessages.isDuplicate(e.getMessage())){
                    e.setCancelled(true);
                    e.getPlayer().sendMessage(ChatColor.RED + "No duplicate messages!");
                    return;
                }else{
                    e.setCancelled(false);
                }
               
                DuplicateMessages.add(e.getMessage());
    The DuplicateMessages class:
    Code:
    public class DuplicateMessages extends JavaPlugin{
       
        static ChatGuard configGetter;
        static PlayerListener listener;
       
        private static Map<String, String> lastMessage = new HashMap<String, String>();
       
        public DuplicateMessages(ChatGuard plugin) {
            configGetter = plugin;
        }
       
        public static boolean isDuplicate(String m){
            return lastMessage.containsKey(m);
        }
       
        public static void add(String m){
            lastMessage.put(listener.player.getName(), m);
        }
    }
    I previously had the problem that, even though the player said something different, it still warned them that duplicate messages aren't allowed.
    My HashMap knowledge isn't that great and I wanted to try and figure it out by myself without looking at someone else's duplicate messages plugin.
     
Thread Status:
Not open for further replies.

Share This Page