Created
June 7, 2012 08:40
-
-
Save macalinao/2887450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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