Get Inventory of a Chest

Discussion in 'Plugin Development' started by greaperc4, Mar 18, 2014.

Thread Status:
Not open for further replies.
  1. Hello, I am coding a Plugin for my server now and I want to get the Inventory of a Chest from a Location.

    Code:java
    1. Location Location = new Location(world, x, y, z);
    2. Block block = Location.getBlock();
    3. if (block.getType() == Material.CHEST)
    4. {
    5. Chest chest = (Chest) block.getState();
    6. }


    and this does now wants to do:
    Code:java
    1. Inventory inv = ((Chest) chest.getState()).getInventory();


    it just wont let me get inventory of a chest

    If someone could solve this for me I would be very happy.

    Greaperc4
     
  2. Offline

    ShadowLAX

    greaperc4 chest.getInventory() or chest.getBlockInventory() both return the same inventory, but they both have different methods depending on what you need.
     

  3. Yeahh... the Problem is Both wont show up Here is a ScreenShot:
    http://prntscr.com/3279mr
     
  4. Offline

    ShadowLAX

    greaperc4 Your problem is that you imported the org.bukkit.material Chest instead of org.bukkit.block Chest. Fix the imports and it will work.
     
  5. Whoops didn't seen that, Thanks! it works now ;)
     
Thread Status:
Not open for further replies.

Share This Page