Skip to content

Instantly share code, notes, and snippets.

@macalinao
Created June 7, 2012 08:40
Show Gist options
  • Save macalinao/2887450 to your computer and use it in GitHub Desktop.
Save macalinao/2887450 to your computer and use it in GitHub Desktop.
public class BlockBreaker extends JavaPlugin implements Listener {
private List<BlockDef> blocks = new ArrayList<BlockDef>();
public void onEnable() {
Bukkit.getPluginManager.registerEvents(this);
Bukkit.getScheduler.scheduleSyncRepeatingTask(this, new Runnable() {
for (BlockDef def : BlockBreaker.this.blocks) {
if (def.time < System.currentTimeMillis()) {
continue;
}
def.loc.getWorld().getBlockAt(def.loc).setType(def.mat);
BlockBreaker.this.blocks.remove(def);
}
}, 0L, 20L);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
BlockDef def = new BlockDef(block.getType(), block.getLocation(), System.currentTimeMillis() + (1000 * 10));
blocks.add(def);
}
public static class BlockDef {
public Material mat;
public Location loc;
public long time;
public BlockDef(Material mat, Location loc, long time) {
this.mat = mat;
this.loc = loc;
this.time = time;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment