Discussion in 'Spigot Plugin Development' started by TheFuzzyHead5, Apr 22, 2017.

  1. I'm sure this is simple but I'm just missing a key point.

    From the PlayerInteractEvent I have a .getClickedBlock().

    How do I then turn this into a chest which can be manipulated? I attempted to check if

    e.getClickedBlock().getState() instanceof Chest

    and then I casted it to a chest. It seems I get an error.

    (Yes, I have null checked it etc.)

    Essentially I'm asking how to turn a e.getClickedBlock() into an Inventory that can be manipulated.
  2. We cant do much without code and an error stacktrace
  3. I'm not at a convenient place to provide one but I assumed somebody might know how to go from a regular Block to an Inventory efficiently.
  4. Just going to write this down step by step.

    • Check if the getClickedBlock() returns null if so, return
    • Check if getClickedBlock().getState() is instanceof Chest
    • Cast getClickedBlock.getState() to a Chest.
    Now you can do whatever you please with the chest.
    • Agree Agree x 1
    • Informative Informative x 1
  5. Or instead you could check for
    Code (Text):
     if(e.getClickedBlock().getType() == Material.CHEST || e.getClickedBlock().getType() == Material.DOUBLE_CHEST){
        //Cast object to chest or double chest