Particle

Discussion in 'Plugin Development' started by Yarnick, Apr 30, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Yarnick

    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
    1.  
    2. public Boolean particleToggle = false;
    3.  
    4. int nummer = 0;
    5.  
    6. @EventHandler
    7.  
    8. public void particleEnable(InventoryClickEvent event)
    9.  
    10. {
    11.  
    12. Player player = (Player) event.getWhoClicked();
    13.  
    14. ItemStack item = event.getCurrentItem();
    15.  
    16. if(item.getType().equals(Material.DIAMOND) && event.getInventory().getName().equals("opengui"))
    17.  
    18. {
    19.  
    20. nummer = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    21.  
    22. {
    23.  
    24. public void run()
    25.  
    26. {
    27.  
    28. if(particleToggle = false)
    29.  
    30. {
    31.  
    32. particleToggle = true;
    33.  
    34. ParticleEffect.HEART.display(0, 0, 0, 10, 10, player.getLocation(), 15);
    35.  
    36. }
    37.  
    38. else
    39.  
    40. {
    41.  
    42. particleToggle = false;
    43.  
    44. Bukkit.getScheduler().cancelTask(nummer);
    45.  
    46. }
    47.  
    48. }
    49.  
    50. },10, 20
    51.  
    52. );
    53.  
    54. event.setCancelled(true);
    55.  
    56. }
    57.  
    58. }
    59.  
    60.  
     
    Last edited: Apr 30, 2016
  2. Offline

    SnapchatDev

    Thats the weirdest way ive ever seen something like that coded!
     
  3. Offline

    Yarnick

    It's fixed, you know what the problem is for my problem?
     
    Last edited: Apr 30, 2016
  4. Offline

    Zombie_Striker

    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.
     
  5. Offline

    Yarnick

    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.
     
    Last edited by a moderator: May 1, 2016
  6. Offline

    Zombie_Striker

    @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/
     
  7. Offline

    mcdorli

    "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.
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page