So I'm creating a plugin that stops players from spamming, it first checks if the message is simular to the previouw message and then adds the new message as last message. but the last message never gets added to the HasMap for some reason, this is my code: Code (Text): Map<UUID, String> lastmsg = new HashMap<UUID, String>(); @EventHandler public void Chat(AsyncPlayerChatEvent e) { Player p = e.getPlayer(); String msg = e.getMessage().toLowerCase(); if (msg.contains(lastmsg.get(p.getUniqueId())) || msg == lastmsg.get(p.getUniqueId())) { p.sendMessage(ChatColor.RED + "Please don't spam the chat!"); p.playSound(p.getLocation(), Sound.NOTE_BASS, 2.0F, 1.0F); e.setCancelled(true); } lastmsg.put(p.getUniqueId(), msg); } Thanks for your help!
The person will never get added to the map because it will throw nullpointerexceptions as you try to get something from the map which isn't there yet.