Getting door as block?

Discussion in 'Plugin Development' started by WiseHollow, Oct 28, 2013.

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

    WiseHollow

    Hey, In my plugin I am blocking pistons from editing blocks that are in protected areas. Well my problem is that doors aren't being recognized as a block.

    I tested it and it recognizes stone or other blocks but not doors. Any idea how to make it recognize any block in its path?

    Code:
    public void onPistonPush(BlockPistonExtendEvent event)
        {
            List<Block> blocks = event.getBlocks();
            for (Block b : blocks)
     
  2. Offline

    connor stone

    I think you may have left something out of your code...but you can check with something like this



    Code:java
    1. @EventHandler
    2. public void onPistonPush(BlockPistonExtendEvent event){
    3. List<Block> block = event.getBlocks;
    4. for (Block b : blocks){
    5. if (b != Material.Air){
    6. //somecode here to stop it
    7. event.setCancelled(true);
    8. }
    9.  
    10. }
    11.  
    12. }
     
  3. Offline

    WiseHollow

    Here is the entire event. I left out most of it because I wasn't sure if it was necessary to mention :p

    Code:
    @EventHandler
        public void onPistonPush(BlockPistonExtendEvent event)
        {
            List<Block> blocks = event.getBlocks();
            for (Block b : blocks)
            {
                Town source = ProjectUtilities.getEnteredTown(event.getBlock().getLocation());
                Town target = ProjectUtilities.getEnteredTown(b.getLocation());
                if (source != target)
                {
                    event.setCancelled(true);
                    return;
                }
                if (source != null && target != null)
                {
                    TownPlot plotSource = source.getEnteredTownPlot(event.getBlock().getLocation());
                    TownPlot plotTarget = source.getEnteredTownPlot(b.getLocation());
                   
                    if (plotSource != plotTarget)
                    {
                        event.setCancelled(true);
                        return;
                    }
                }
            }
        }
    This blocks people from pushing stone into protected zones but they are able to push doors from the outside inwards.
     
  4. Offline

    Jake6177

    e.getBlock() according to the javadocs gets the block involved in the event (e.g. the block pushed, not the pusher).
     
    WiseHollow likes this.
  5. Offline

    WiseHollow

    Jake6177 Oh! Well, any idea why Doors aren't recognized by the event.getBlock() and not included in the event.getBlocks() ?
     
  6. Offline

    Jake6177

    I haven't been doing bukkit long, but after a bit of researching a few ago, I saw that "Door" is a material, not a block. Does that make any difference to you? Sorry I'm still quite new.
     
    WiseHollow likes this.
  7. Offline

    WiseHollow

    Very interesting. Thanks for that; gets me a bit closer to the answer but still quite clueless on how to get the Material from that location. :)
     
  8. Offline

    Jake6177

    e.getBlock().getType() returns a material, try that?
    Scratch that, I don't see door there....

    AHA. Doors are materials. It would be "Material.WOODEN_DOOR", and so on so forth for each type of door.

    Something like this, maybe? Block door = (Block) e.getBlock().getState().getData();
     
  9. Offline

    WiseHollow

    I get an error: Cannot be cast

    :(
     
  10. Offline

    Jake6177

    WiseHollow
    I'm at a loss then. Sorry I couldn't have been more help.
     
  11. Offline

    WiseHollow

  12. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page