Skip to content

Instantly share code, notes, and snippets.

@NeatMonster
Created November 7, 2013 17:21
Show Gist options
  • Save NeatMonster/28c07a6a2b5b633e49cc to your computer and use it in GitHub Desktop.
Save NeatMonster/28c07a6a2b5b633e49cc to your computer and use it in GitHub Desktop.
public static class Save {
private final Block block;
private final byte data;
private final Material type;
@SuppressWarnings("deprecation")
public Save(final Block block) {
this.block = block;
type = block.getType();
data = block.getData();
}
@SuppressWarnings("deprecation")
public void restore() {
block.setType(type);
block.setData(data);
}
}
public static final BlockFace[] AXES = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
public void createWall(final Player player) {
final List<Save> saves = new ArrayList<Save>();
final BlockFace axis = AXES[Math.round(player.getLocation().getYaw() / 90f) & 0x3];
for (int xz = 0; xz < 5; xz++) {
for (int y = 0; y < 3; y++) {
final int x = axis.getModX() + (axis.getModX() + 1) % 2 * (-2 + xz);
final int z = axis.getModZ() + (axis.getModZ() + 1) % 2 * (-2 + xz);
final Block block = player.getLocation().clone().add(x, y, z).getBlock();
saves.add(new Save(block));
block.setType(Material.BRICK);
}
}
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
for (final Save save : saves)
save.restore();
}
}, 5 * 20L);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment