Basicly, im trying to create a cookie clicker plugin, it returns the value of 1 each time you click it. But i'm trying to make it go up a int everytime you click it :/ My Code: public static HashMap<Player, Integer> clicks = new HashMap<Player, Integer>(); public void onEnable() { Bukkit.getPluginManager().registerEvents(this, this); } public void onDisable() { //Stuff here } @EventHandler public void onInteract(PlayerInteractEvent e) { Player p = e.getPlayer(); if(e.getItem().getType() == Material.COOKIE) { p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.RED + clicks.size() + ChatColor.GREEN + " Cookie Clicks!"); clicks.put(p, clicks.size()+1); } } }
@D4rkzm, your code as is will create a memory leak. you are just putting another value over and over again into the hashmap. Actually, that entire thing doesn't make sense... Storing player objects won't work in the first place. Code:java HashMap<UUID, Integer> clicks = new HashMap<UUID, Integer>(); @EventHandlerpublic void onInteract(PlayerInteractEvent e){int playerClicks;Player p = e.getPlayer();if(e.getItem().getType() == Material.COOKIE) {if(clicks.get(p.getUniqueId)!=null) {playerClicks=clicks.get(p.getUniqueId); }else {playerClicks=0; }clicks.remove(p.getUniqueId);clicks.add(p.getUniqueId(), (playerClicks+1));p.sendMessage(ChatColor.GREEN + "You have " + ChatColor.RED + (playerClicks+1) + ChatColor.GREEN + " Cookie Clicks!"); }//end of if cookie}//end of onInteract fair warning, I did not test this.