Bukkit openInventory() help?

Discussion in 'Plugin Development' started by Connor2weirdness, Jun 9, 2013.

Thread Status:
Not open for further replies.
  1. Hello, if you could help me, I would immensely appreciate it. For some reason, the following code will not work as it is supposed to. When a player left clicks the air, it should open an inventory, which it fails to do so. Here is the code:

    @EventHandler
    public void onVChestOpen(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if ((event.getAction() == Action.LEFT_CLICK_AIR)) {
    Inventory quickwarps = Bukkit.createInventory(player, 54, "Quick Warps");
    player.openInventory(quickwarps);

    There are no errors in the console, no incorrect lines in Eclipse, no in-game errors, just nothing happens. I am using CraftBukkit 1.5.2 R1. Thanks a bunch!
     
  2. Offline

    kreashenz

    I don't think you are registering your events?
     
    Th3Br1x likes this.
  3. In English lol? I'm not a super nerd at Java.
     
  4. Offline

    kreashenz

    Connor2weirdness In your onEnable() put
    Code:java
    1. getServer().getPluginManager().registerEvents(new <Class>(), this);
     
  5. Yeah I do have all that it's just that what's the point pasting the whole thing in when I know where the error is? But oh well, here's the whole thing: http://pastebin.com/RrQfRL2S
     
  6. Offline

    Rockon999

    You don't have that in your onEnable... you have to put it into it :|
     
  7. Ok I just tried it, I got a red line at <Class> Thanks everyone for the help so far!
     
  8. Offline

    Rockon999

    Replace <Class> with the class your listener is in :)
     
  9. I then get a line under registerEvents :(

    bump please help

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

    Rockon999

    oh sorry I'll be more specific...
    getServer().getPluginManager().registerEvents(new <CLASS NAME (No .java)>(this), this);
     
  11. Offline

    Rockon999

    getServer().getPluginManager().registerEvents(new INVTELE(this), this);
     
  12. Any ideas why?
     
  13. Offline

    Rockon999

    You didn't put "this" inside "new INVTELE(), this);"
    should be: new INVTELE(this), this);
     
  14. When I do that, I get an error, it asks me to create a constructor which when I do, makes no difference apart from removing the line.
     
  15. Offline

    Rockon999

    Wait... if your listener is in your main class you do it like this:
    getServer().getPluginManager().registerEvents(this, this);
     
  16. Yep the class name is INVTELE which I had already done: getServer().getPluginManager().registerEvents(new INVTELE(), this);
    [​IMG]
     
  17. Offline

    lobnews

    Please show your INVTELE.class
     
  18. Still nothing, and what is a listener o.0
     
  19. Offline

    Rockon999

    If INVTELE.class has your Listener & onEnable() ...
    you have to register it like this:
    getServer().getPluginManager().registerEvents(this, this);


    ... A listener is the thing with
    @EventHandler
    that listens for an event...
     
  20. http://pastebin.com/2Xvg4KfL

    As said above, no difference.

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

    lobnews

    And is it an external Listener you have to register it like this:
    getServer().getPluginManager().registerEvents(new <Listenerclass>(if needed something as parameter),this);
     
  22. Offline

    Rockon999

    That should work :)
     
  23. Does not work, used the following: getServer().getPluginManager().registerEvents(new INVTELE,this);
    Thanks guys o.0
     
  24. Offline

    lobnews

    This won't work because java wants to have the brackets.
    getServer().getPluginManager().registerEvents(new INVTELE(),this);
    Will work.
     
  25. Offline

    Drkmaster83

    (A note to lobnews: These are brackets: {}. These are parentheses: (). And, you also forgot to add the 'this' in between your two parentheses.)

    Okay, so, let's clear this up:

    If the event that you've created a Listener for (supposedly with no knowledge of any Bukkit slang for such methods and classes) is in the same class that extends JavaPlugin and has your onEnable(), it would be this in your onEnable():
    Code:
    getServer().getPluginManager().registerEvents(this,this);
    
    If it's NOT in that main class, and it's an external class named, say, "INVTELEListener", then it'd look like this in your onEnable().
    Code:
    getServer().getPluginManager().registerEvents(new INVTELEListener(this),this);
    
     
  26. Ok so I entered getServer().getPluginManager().registerEvents(this,this); in onEnable(); and the plugin still doesn't work. No errors or anything. Thanks.
     
  27. Offline

    Drkmaster83

    Sigh, post the code and any stack traces you might have.
     
  28. Offline

    Compressions

    Connor2weirdness Registering your events isn't "super nerd talk"; it's basic Java.
     
Thread Status:
Not open for further replies.

Share This Page