Solved Placing chest + filling it all in 1 go.

Discussion in 'Plugin Help/Development/Requests' started by Scorpionvssub, Jul 22, 2016.

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

    Scorpionvssub

    Code:
            Location loc = p.getLocation();
            Block mat = loc.getBlock();
            mat.setType(Material.CHEST);
            Chest chest = (Chest) mat.getLocation();
    
                    ItemStack is = new ItemStack(Material.TRIPWIRE_HOOK);
                    chest.getInventory().addItem(is);
    I got the placement of a chest working at the players feet. However i get an error when trying to get the chests location so i can use it in a chests plugin sense.(i don't know how to explain it all too well)

    Basicly a chest is 1 of the only few blocks with an inventory so i would need to cast the block as a chest for those functions to work.

    However there is an issue with grabbing the Chest as a chest on that location(This line: Chest chest = (Chest) mat.getLocation();)

    The error itself is:
    22.07 11:13:31 [Server] [Informatie] Caused by: java.lang.ClassCastException: org.bukkit.Location cannot be cast to org.bukkit.block.Chest

    And when i put .getBlock behind mat.getlocation i get this:

    22.07 11:22:03 [Server] [Informatie] Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.block.CraftBlock cannot be cast to org.bukkit.block.Chest

    What im trying to do is after the plugin "ends" a chest popsup with rewards which are inside this chest.
     
  2. @Scorpionvssub
    You are trying to cast a Location to Chest. You would need to cast Block.getState() instead.
     
Thread Status:
Not open for further replies.

Share This Page