InventoryClickEvent

Discussion in 'Plugin Development' started by ewrs, Aug 28, 2018.

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

    ewrs

    Hello. I recently changed something in my plugin and there was a mistake. I can not understand what, but it's because of

    Adrenalin.getInstance (). Adrenalins.put (p.getName (), 1);

    Code:
    @EventHandler
    public void GUI(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    if (inventory.getName().equals(c.getName())) {
    e.setCancelled(true);
    p.updateInventory();
    Adrenalin.getInstance().Adrenalins.put(p.getName(), 1);
    }
    }

    Error: https://pastebin.com/RfgHDZDi


    Sorry for my english, he's not the best.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @ewrs Please post the full Adrenalin class.
     
  3. Offline

    ewrs

    NULL
     
    Last edited: Sep 7, 2018
  4. Offline

    timtower Administrator Administrator Moderator

    @ewrs You never initialize instance.
     
  5. Offline

    ewrs

    In what sense?
     
  6. Offline

    timtower Administrator Administrator Moderator

    You never give it a value.
     
  7. Offline

    ewrs

    Something I was confused ... And what to do about it?
     
  8. Offline

    timtower Administrator Administrator Moderator

    You are making an instance somewhere, pass that one around instead of making a static instance.
     
  9. Offline

    Caedus

  10. Offline

    ewrs

    I can not understand. I'm doing everything right, but it does not work. I will soon have a brain explode!
     
  11. Offline

    timtower Administrator Administrator Moderator

    public static Adrenalin instance;
    Where is the line that says:
    instance = somethingThatIsn'tNull
     
  12. Offline

    ThePandaPlayer

    @ewrs
    The best way to go about initializing your instance is simply doing it in the onEnable method()
    Code:
    public void onEnable() {
        //SOME CODE HERE
        instance = this;
        //OTHER CODE HERE
    }
    
     
  13. Offline

    Caedus

    This would give him an instance of his plugin, but not of the Adrenalin class he wants. In the link I provided there is literally the code he needs.
     
  14. Offline

    ewrs

    So tnank you. I figured it out. Only I can not understand why the plug-in does not register events ... I wrote everything correctly. In Adrenalin there is a Listener
    getServer().getPluginManager().registerEvents(new Adrenalin(), this);

    I DO NOT UNDERSTAND! Now after all this I have problems with events! If you remove from that code, problems with ClickEvent AGAIN!
     
    Last edited: Aug 28, 2018
  15. Offline

    Caedus

    Are you registering this listener in Adrenalin class or your main class (the one that extends JavaPlugin)?
     
  16. Offline

    ewrs

    Yes
     
  17. Offline

    Caedus

    That wasn't a yes or no question :oops:
     
Thread Status:
Not open for further replies.

Share This Page