Bukkit openInventory() help?

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

Thread Status:
Not open for further replies.
  1. Cut me a little slack, I'm 12 years old and I have only jut started learning.
     
  2. Offline

    Compressions

  3. Offline

    lobnews

    Compressions How have you start? You had also problems. So let him be. If it does bother you, you have not to read this thread.
     
    sebasju1234, Hoolean and bobacadodl like this.
  4. Offline

    Drkmaster83

    This code works for me:
    Code:
    package INVTELE.Connor2weirdness;
    
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class INVTELE extends JavaPlugin implements Listener 
    {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static INVTELE plugin;
    
        @Override
        public void onEnable() 
        {
            getServer().getPluginManager().registerEvents(this, this);
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " VerDev: " + pdfFile.getVersion()
                    + " Enabled. ");
        }
    
        @Override
        public void onDisable() 
        {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Y U disable :(. Disabled. ");
        }
    
        @EventHandler
        public void onVChestOpen(PlayerInteractEvent event) 
        {
            Player player = event.getPlayer();
            if (event.getAction().equals(Action.LEFT_CLICK_AIR))
            {
                Inventory quickwarps = Bukkit.createInventory(player, 54, "Quick Warps");
                player.openInventory(quickwarps);
            }
            
        }
    
    }
    And this is my plugin.yml:
    Code:
    name: QuickWarps
    main: INVTELE.Connor2weirdness.INVTELE
    version: 1.0
    author: Connor2weirdness
    
    Yes, we had problems when we were beginners, but we actually cared to look at the tutorial. He should know at least what a "Listener" is.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  5. http://pastebin.com/6rZPfLAD

    I've just tried to use your code, nothing happens still. When the left click the air, it should open an inventory. Thank you for you patience.

    ....

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

    GodzOfMadness

    Compressions Registering your events isn't 'basic java'. It's done through the bukkit API that was made in java.
     
  7. Offline

    Compressions

    GodzOfMadness I was waiting for a post like this :p. Okay, basic Bukkit API.
     
    GodzOfMadness likes this.
  8. Anyone help? Please? http://pastebin.com/6rZPfLAD
     
  9. Offline

    Compressions

    Connor2weirdness Why is the rest of this if-statement blank?
    Code:
    if (player.
     
  10. Sorry, I think that was a mis-paste. Here is the proper code:
    }

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

    }

    }

    So yeah you know why?

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

    theDman18

    Connor2weirdness I am having the same issue, for me it only works if the player is in creative mode. But if he is in survival then he can't open the inventory. Like you said, no stack traces or errors or anything.
     
  12. Offline

    Drkmaster83

    The following code (all in the main class) works perfectly for me. It opens the inventory successfully, regardless of gamemode.

    Code:
    package INVTELE.Connor2weirdness;
    
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class INVTELE extends JavaPlugin implements Listener 
    {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static INVTELE plugin;
    
        @Override
        public void onEnable() 
        {
            getServer().getPluginManager().registerEvents(this, this);
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " VerDev: " + pdfFile.getVersion()
                    + " Enabled. ");
        }
    
        @Override
        public void onDisable() 
        {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Y U disable :(. Disabled. ");
        }
    
        @EventHandler
        public void onVChestOpen(PlayerInteractEvent event) 
        {
            Player player = event.getPlayer();
            if (event.getAction().equals(Action.LEFT_CLICK_AIR))
            {
                Inventory quickwarps = Bukkit.createInventory(player, 54, "Quick Warps");
                player.openInventory(quickwarps);
            }
            
        }
    
    }
    
     
  13. When you say "works perfectly" what does it do? It's supposed to open an inventory on left click air. That is the code I already have. Thank you very much for helping so far.

    For me, it won't even work at all :( Could you paste your code please? So I could at least have something working?

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

    theDman18

    Connor2weirdness This is what I have my code as. I think it is something like what yours does. Anyways, for me it only works when someone is in creative, not survival. Here ya go:
    Code:java
    1. @EventHandler
    2. public void onBlockClick(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. if (event.getClickedBlock().getType() == Material.DIAMOND_ORE) {
    6.  
    7. // Potion
    8. ItemStack potion = new ItemStack(Material.POTION);
    9. potion.setDurability((short) 16421);
    10. ItemMeta pm = potion.getItemMeta();
    11. pm.setDisplayName("§bMedkit");
    12. potion.setItemMeta(pm);
    13.  
    14. // Arrow
    15. ItemStack a = new ItemStack(Material.ARROW);
    16. ItemMeta am = a.getItemMeta();
    17. am.setDisplayName("§bArrow");
    18. a.setItemMeta(am);
    19.  
    20. // Cooked Beef
    21. ItemStack b = new ItemStack(Material.COOKED_BEEF);
    22. ItemMeta bm = b.getItemMeta();
    23. bm.setDisplayName("§bSteak");
    24. b.setItemMeta(bm);
    25.  
    26.  
    27. Inventory inv = Bukkit.createInventory(player, 9,
    28. "§8Shop");
    29. inv.addItem(potion);
    30. inv.addItem(a);
    31. inv.addItem(b);
    32.  
    33. player.openInventory(inv);
    34. }
    35. }
    36. }
     
  15. Offline

    lycano

    Connor2weirdness what does not work? As you said you are a beginner .. do you know that you have to compile the plugin to a .jar file and put it into the plugins directory?

    What are your steps you execute after you pressed "save file" in your IDE? (Are you using Netbeans or IntelliJ?)
     
  16. I am using Eclipse. I click save, hit the export as JAR file. I click the project. Click finish. Done.

    Thanks a lot, I'll see if I can find a solution, and if I do, I will let ya know ;)

    Ok, just tried the code, it still won't work for me, creative or survival. It won't let me add the new ItemStack paragraphs (I think they are called statements, I'm not sure :p)

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

    ZeusAllMighty11

    A lot of these issues are common java. Did you try googling around for your issue?
     
  18. Yup, spent hours. :(
     
  19. Offline

    ZeusAllMighty11

    I call BS.

    1) Learn Java
    2) Learn more Java
    3) Learn even more Java
    4) Read plugin tutorial
    5) Learn MOAR JAVA
    6) Start with basic plugin, using YOUR knowledge of Java, not other people's
     
  20. I'll do it when I want to, thank you. if you don't know why my plugin won't work, I don't care what you have to say. I'm not taking other people's code, just trying to get mine fixed.
     
  21. Offline

    ZeusAllMighty11

    I know exactly why your plugin doesn't work, along with everyone else in this thread, pretty much.
    Which is why we tried to help you, yet, you just don't understand. Too darn stubborn, yeh..
     
    Burnett1 likes this.
  22. Offline

    tylersyme

    Ok, so IF your "ProjectileHitEvent" is in the same class as your "onEnable" method then do this
    Code:
    public void onEnable()
        {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onProjectileHit(PlayerInteractEvent event)
        {
            Player player = event.getPlayer();
            if (event.getAction() == Action.LEFT_CLICK_AIR)
            {
                Inventory quickwarps = Bukkit.createInventory(player, 54, "Quick Warps");
                player.openInventory(quickwarps);
            }
        }
     
  23. Offline

    theDman18

    Connor2weirdness I figured out my problem. There was a cancel in the InventoryOpenEvent in another class that I had.
     
  24. Offline

    Wingzzz

    Is this still unsolved?
     
  25. It certainly is :(

    Sorry, I am kind of a noob to Java/Bukkit API. ProjectileHitEvent?

    Thanks for helping, but the code still hasn't worked :(

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

    Drkmaster83

    So, is the inventory opening? Are you trying to figure out how to add new ItemStacks that cause something to happen when they're interacted with?

    Also, tylersyme thought that you were using the ProjectileHitEvent because of what your event name is.
    Code:
    public void onProjectileHit <--- (PlayerInteractEvent event)
    
    I need you to tell me exactly what you want to happen, what's working, and what isn't.
     
  27. Nothing is working, when I left click the air, no inventory opens. No errors, stacktraces, any sign of a problem.
     
  28. Offline

    Deckerz

    what does your plugin.yml look like?
     
  29. name: INVTELE
    main: INVTELE.Connor2weirdness.INVTELE
    version: 1.0
    description: >
    INVTELE by Connor2weirdness
     
  30. Offline

    Wingzzz

    By convention you shouldn't be using capitals in your package names.
     
Thread Status:
Not open for further replies.

Share This Page