Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class RestoreManager implements Runnable {
- private final Set<RestoreNode> nodes = Sets.newHashSet();
- public void restore(Block block, Material material) {
- restore(block, material, seconds);
- }
- public void restore(Block block, Material material, long delay) {
- RestoreNode node = new RestoreNode(block.getState(), material, delay);
- if (delay > 0L) {
- this.nodes.add(node);
- node.onStart();
- } else {
- node.transfer();
- }
- }
- @Override
- public void run() {
- if (!this.nodes.isEmpty()) {
- long time = System.currentTimeMillis();
- this.nodes.removeIf(node -> node.update(time));
- }
- }
- public static final class RestoreNode {
- private final BlockState state;
- private final Material material;
- private final long transferExpire;
- RestoreNode(BlockState state, Material material, long delay) {
- this.state = state;
- this.material = material;
- this.transferExpire = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(delay);
- }
- boolean update(long time) {
- if (time >= getTransferExpire()) {
- transfer();
- return true;
- }
- return false;
- }
- void onStart() {
- this.state.setType(Material.BEDROCK);
- this.state.update(true);
- }
- void transfer() {
- this.state.setType(this.material);
- this.state.update(true);
- }
- long getTransferExpire() {
- return this.transferExpire;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement