Reviving a block

Discussion in 'Plugin Development' started by Creeperzombi3, Apr 27, 2015.

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

    Creeperzombi3

    I want to revert the block changed to the original block after 3 seconds.
    What would I add to make this happen?
    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                public void run() {
                    Block hitBlock = null;
                    if (EntityType.EGG == egg) {
                        while (iterator.hasNext()) {
                            while (iterator.hasNext()) {
                                hitBlock = iterator.next();
    
                                if (hitBlock.getTypeId() != 0) {
                                    break;
                                }
                            }
                          
                            if (hitBlock.getType() != Material.BEDROCK) {
                                hitBlock.getWorld().playEffect(
                                        hitBlock.getLocation(), Effect.STEP_SOUND,
                                        hitBlock.getTypeId());
                                hitBlock.setType(Material.WOOL);
                            }
                        }
                    }
                }
            }, 60);
     
  2. Offline

    nverdier

  3. Offline

    meguy26

    @nverdier
    He is using a scheduler, albeit a slightly messy one.
    @Creeperzombi3
    I actually do this in my plugin, and the way I do it is on block break event I start a schedulere which accepts a block and a material for its constructor, then I just set the type of the block to the material in the run method.
     
  4. Offline

    Creeperzombi3

    @meguy26 I know what I need to do, just need to figure out how.
    Thanks for the help though
     
  5. Code:
    final Block b = e.getBlock();
    final Material m = b.getType();
    new BukkitRunnable() {
      @Override
      public void run() {
        b.setType(m);
      }
    }.runTaskLater(<plugin>, 3 * 20L);
     
  6. Offline

    mythbusterma

    @megamichiel

    You can't store a reference to a Block between ticks....
     
  7. @mythbusterma
    Actually, you can, it works fine for me :p

    Cause inside the block class it only saves the chunk, x, y and z and using that it sets the block using the methods

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  8. Offline

    mythbusterma

    @megamichiel

    Sorry. "Shouldn't" would've been better.

    Most of the time it doesn't work. Use BlockStates instead.
     
Thread Status:
Not open for further replies.

Share This Page