When you type opengui it opens an inventory with a diamond in it, when you click the diamond it toggles particles on and off. But it's not working. Code:java public Boolean particleToggle = false; int nummer = 0; @EventHandler public void particleEnable(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); ItemStack item = event.getCurrentItem(); if(item.getType().equals(Material.DIAMOND) && event.getInventory().getName().equals("opengui")) { nummer = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { public void run() { if(particleToggle = false) { particleToggle = true; ParticleEffect.HEART.display(0, 0, 0, 10, 10, player.getLocation(), 15); } else { particleToggle = false; Bukkit.getScheduler().cancelTask(nummer); } } },10, 20 ); event.setCancelled(true); } }
This means there can be only one boolean, meaning only one player can have the particles on their head. Instead, create a Map that stores a value from the player (e.g. UUID or player's name) as the key, and a boolean as the value. This way you can store multiple booleans linked to individual players. Remember: Item can be null if the player is not holding anything/ holding 'air'. Do a null check before you get it's type. You forgot an extra '='. One equal sign means you are setting the value, two means you're checking the value.
Thanks a lot! I will try to fix it now. Do you have an example of such a map? I'm quite new to Bukkit and after a bit of Googling I am still not sure how to do it. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@Yarnick You can use this tutorial to learn what Maps are. http://docs.oracle.com/javase/tutorial/collections/interfaces/map.html BTW: Maps are not apart of Bukkit, but Java. If you have not learned Java yet, then please do. Doing so will prevent you from having these problems, or will allow you to know how to fix them by yourself. In case you have not already learned Java ,please pick a tutorial from the following link and take some time to fully understand Java by itself. https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/
"Not a part..." instead of "not apart", it actually matters in this case, apart means separated, a part means a piece of something. http://grammarist.com/spelling/apart-vs-a-part/ I really hope you indent your code and you don't separate every row with a new line. Please, follow java naming conventions, brackets should be in the same line as the statement header, and not in a separate row (the latter is called Allman style, and preferred in C# or C++). Use boolean instead of Boolean, the first one is only 1 byte, the last is huge compared to it, as it is the object wrapper of the first.