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

Discussion in 'Spigot Help' started by Fahlur, Jul 14, 2018.

  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
    Last edited: Jul 16, 2018
  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
    Last edited: Jul 16, 2018
  4. hm any ideas?
     
  5. Make a scheduler and after let's say 10 ticks, spawn the lever back.
     
  6. didnt seem to work. also doesnt matter on levers much anymore unless I do some sort of trickery to allow them on pistons in 1.13 (that ability to put buttons and levers on pistons is gone in 1.13) plates and other redstone seems fine.

    edit: heh seems in 1.13 pre7 the regular piston no longer fires the BlockPistonRetractEvent. But sticky does.
    edit-2: and lovely, they dont register any block thats basically rails, redstone, etc they register them as air. tried multiple different things. worked fine in 1.12.2.. uhg
     
    #6 Fahlur, Jul 18, 2018
    Last edited: Jul 19, 2018

Share This Page