BlockPistonRetractEvent keep redstone on back, pops off on sticky but not regular piston

Discussion in 'Spigot Help' started by Fahlur, Jul 14, 2018 at 8:56 AM.

  1. Basically in BlockPistonRetractEvent, when the piston is facing down I dont want it to break the redstone on retract. It works fine with a regular piston but when I do a sticky piston its like it cokmpletely ignores the fact and breaks the item anyways.

    any ideas?

    EDIT:
    I have tried blockbreakevent but it doesn't work for this. I have checked with just the event to say hello world in a broadcast if the event fires and it doesn't when the redstone component or otherwise just pops off the piston during retraction.

    What im explaining:
    https://i.imgur.com/SZiXdFX.mp4

    Code:
    Code (Text):
    public Material[] apBlocks = new Material[] {
                Material.WOOD_PLATE,
                Material.STONE_PLATE,
                Material.IRON_PLATE,
                Material.GOLD_PLATE,
                Material.STONE_BUTTON,
                Material.WOOD_BUTTON,
                Material.LEVER,
                Material.DIODE,
                Material.DIODE_BLOCK_OFF,
                Material.DIODE_BLOCK_ON,
                Material.REDSTONE_COMPARATOR,
                Material.REDSTONE_COMPARATOR_OFF,
                Material.REDSTONE_COMPARATOR_ON,
                Material.REDSTONE,
                Material.REDSTONE_WIRE
        };

    @EventHandler
    public void pistonRetract(BlockPistonRetractEvent e) {
    Block block = e.getBlock();

     Location loc = block.getLocation().add(0, 1, 0);

     if (Arrays.asList(apBlocks).contains(loc.getBlock().getState().getType())) {

      Material bType = loc.getBlock().getType();
      byte bData = loc.getBlock().getData();

      loc.getBlock().setType(Material.AIR);

      Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
       @Override
       public void run() {

        Block d = loc.getBlock();

        d.setType(bType);
        d.setData(bData);

       }
      }, 3L);
     }
    }
     
    #1 Fahlur, Jul 14, 2018 at 8:56 AM
    Last edited: Jul 16, 2018 at 5:49 PM
  2. Rather than using that event, how about BlockBreakEvent:

    Code (Java):

    @EventHandler
    private void onLeverBreak(BlockBreakEvent event)
    {
        if(event.getBlock() != null)
            if(event.getBlock().getType() == Material.LEVER)
            {  
                Location check_location = event.getBlock().getLocation().subtract(0, 1, 0);
             
                Block under = check_location.getBlock();
             
                if(under != null)
                    if(under.getType() == Material.PISTON_STICKY_BASE)
                        event.setCancelled(true);
            }
     
    }
     
     
  3. I attempted block break event originally. It didnt even register the fact the items were broken because of the piston retract. It didnt fire.


    edit:
    just encase I attempted the example and that didnt fire either. Whilst my other one worked fine. with exception to the sticky piston.


    edit 2:
    I guess I would have to presume that the blockbreak event should be registering that, which in fact make it a bug that it doesnt? Since it does not. I even ran the event to just tell me hello world if a block was broken and it detected when I broke by hand. but when it pops off the piston it doesnt.
     
    #3 Fahlur, Jul 15, 2018 at 11:30 PM
    Last edited: Jul 16, 2018 at 5:47 PM

Share This Page