ClickListener

Discussion in 'Plugin Development' started by Chrisdamonster, Nov 5, 2014.

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

    Chrisdamonster

    Before I start this, I wanna say that up in the class, I have all of the other valid things, and they all work. It is just this small part that doesn't work in this entire class.

    Ok, when I click this, nothing happens, though stuff should happen. In the fc (player config), the thing is saving, its just this part isn't working.

    Code:java
    1. Wool red = new Wool(DyeColor.RED);
    2. ItemStack enable = red.toItemStack(1);
    3. ItemMeta sunim = enable.getItemMeta();
    4. sunim.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Click to Enable");
    5. enable.setItemMeta(sunim);
    6.  
    7. Wool green = new Wool(DyeColor.GREEN);
    8. ItemStack disable = green.toItemStack(1);
    9. ItemMeta greenim = disable.getItemMeta();
    10. greenim.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Click to Disable");
    11. disable.setItemMeta(greenim);
    12.  
    13. if(fc.getBoolean("gadgets.trampoline.enabled") == true){
    14. levelinven.setItem(13, disable);
    15. }
    16. if(fc.getBoolean("gadgets.trampoline.enabled") == false){
    17. levelinven.setItem(13, enable);
    18. }
    19.  
    20. //There is some other stuff here, not important, its all working.
    21.  
    22. if(item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "Click to Disable")) {
    23. Wool red = new Wool(DyeColor.RED);
    24. ItemStack enable = red.toItemStack(1);
    25. ItemMeta enableim = enable.getItemMeta();
    26. enableim.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Click to Enable");
    27. enable.setItemMeta(enableim);
    28.  
    29. fc.set("gadgets.trampoline.enabled", false);
    30. try {
    31. fc.save(playerFile);
    32. } catch (IOException e1) {
    33. e1.printStackTrace();
    34. }
    35.  
    36. levelinven.setItem(13, enable);
    37.  
    38. }if(item.getItemMeta().getDisplayName().equals(ChatColor.RED + "" + ChatColor.BOLD + "Click to Enable")) {
    39. Wool green = new Wool(DyeColor.GREEN);
    40. ItemStack disable = green.toItemStack(1);
    41. ItemMeta greenim = disable.getItemMeta();
    42. greenim.setDisplayName(ChatColor.GREEN + "" + ChatColor.BOLD + "Click to Disable");
    43. disable.setItemMeta(greenim);
    44.  
    45. fc.set("gadgets.trampoline.enabled", true);
    46. try {
    47. fc.save(playerFile);
    48. } catch (IOException e1) {
    49. e1.printStackTrace();
    50. }
    51.  
    52. levelinven.setItem(13, disable);
    53.  
    54. }
     
  2. Offline

    Barinade

    Have you tried debug messages yet?
     
    mine-care likes this.
  3. Offline

    Chrisdamonster

    Yep, every other line I put a player.sendMessage("hi"), didn't even get to the first line when I clicked the item.
     
  4. Offline

    Barinade

    Do you register events? Did you forget the annotation? Is it the correct event?
     
  5. Offline

    Chrisdamonster

    Barinade Like I said, no errors, no internal errors, nothing. I did register the events, and other stuff IN THE CLASS is working. It is litterly only this part of the class.
     
  6. Offline

    Barinade

    It doesn't work that way. Something you did or didn't do when you should have is the reason this is happening.

    A missing annotation wouldn't give an error, wrong event wouldn't give an error, and whether or not the events are registered wouldn't give an error. These are things you just need to check.

    If you have an event that says something every time, no conditions, like so:
    @EventHandler
    public void interact(PlayerInteractEvent e) {
    System.out.println("Somebody did something!");
    }

    and it's not writing to the console then you probably didn't register your events (assuming the event and annotation are correct)

    How about you give more code. Your entire listener, event, and onEnable should be enough.
     
    mine-care likes this.
  7. Offline

    mine-care

    As Barinade about debugging you could also print variables to check for false where true should be ect.
    Also a Tip if you have a boolean and you want to use it in a if, you don't have to do boolean==true you can simply put it as:
    If(boolean){

    }
    This if will work only of boolean is true, to do the same for false use the ! Operator from of the boolean.
     
  8. Offline

    Barinade

    You don't even need to check them to print
    System.out.println(boolean)
     
  9. Offline

    Chrisdamonster

  10. Offline

    Barinade

    You should be using else if if you're checking the same variable

    Add an else statement to that if block and print to console what the display name is.
    Perhaps you have the bold & green backwards?
     
  11. Offline

    Chrisdamonster

    Barinade Its almost like the green wool doesn't exist. Even when I click it, with the else tag, nothing happens.
     
  12. Offline

    Barinade

    Add a debug message just before and just after the if statement, see if it's even reaching it
     
  13. Offline

    Chrisdamonster

    Barinade Its printing the debug messages...this is so weird.
     
  14. Offline

    Barinade

    You really need to start being more specific. Which debug message?
     
  15. Offline

    Chrisdamonster

    Barinade The one before and after. Its reading those, its just not getting to the part.

    Hello...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  16. Offline

    Barinade

    My guess is you're thinking the code is supposed to do one thing where in reality it does something completely different.
     
  17. Offline

    mine-care

    Barinade yes the tip was general not about the debug :)
     
  18. Offline

    Watto

    Chrisdamonster

    Also this:
    Code:java
    1. fc.getBoolean("gadgets.trampoline.bought.level5") == false || !fc.isSet("gadgets.trampoline.bought.level5")


    This format is pointless. If anything isSet should be run first, however since getBoolean returns false if nothing is set you don't really need isSet in there..
     
  19. Offline

    teej107

    [​IMG]

    if(fc.getBoolean("gadgets.trampoline.enabled"))

    is sufficient enough as well with using an else statement.
     
Thread Status:
Not open for further replies.

Share This Page