get chests inventory

Discussion in 'Plugin Development' started by Benedikt Wüller, Feb 5, 2012.

Thread Status:
Not open for further replies.
  1. Hello guys,
    I want to remove or add Items into a chest.
    The plugin have to check, whether the Block at the specific location is a chest.

    Code:
    public boolean getInventory() {
            BlockState state = location.getBlock().getState();
         
            if (state instanceof Chest) {
                return ((Chest) state).getInventory();
            }
         
            return false;
        }
    in the Line
    Code:
    return ((Chest) state).getInventory();
    there is an error, but I don't know, why.

    the error is
    Code:
    incomptible types
     
    required: boolean
    found: org.bukkit.inventory.Inventory
    Please Help me.
    B2801

    Sry, for bad english, I am from germany
     
  2. well in the function you say, it will return a boolean
    Code:
    public boolean getInventory() {
    [...]
    but
    Code:
    ((Chest)state).getInventory();
    returns Inventory which is NOT a boolean.

    so either change the return type to object or the Inventory and instead of false you can return null then.
     
Thread Status:
Not open for further replies.

Share This Page