diff --git a/src/main/java/fun/ogre/ogredupealias/data/BlockStorage.java b/src/main/java/fun/ogre/ogredupealias/data/BlockStorage.java new file mode 100644 index 0000000..e50caee --- /dev/null +++ b/src/main/java/fun/ogre/ogredupealias/data/BlockStorage.java @@ -0,0 +1,62 @@ +package fun.ogre.ogredupealias.data; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; + +public class BlockStorage { + private Material type; + private BlockData data; + private Location loc; + private BlockState blockState; + + public BlockStorage(Block b) { + type = b.getType(); + data = b.getBlockData(); + loc = b.getLocation(); + blockState = b.getState(); + } + + public Block toBlock() { + return getLoc().getBlock(); + } + public void restore() { + Block b = toBlock(); + b.setType(this.getType()); + b.setBlockData(this.getData()); + } + + public Material getType() { + return type; + } + + public void setType(Material type) { + this.type = type; + } + + public BlockData getData() { + return data; + } + + public void setData(BlockData data) { + this.data = data; + } + + public Location getLoc() { + return loc; + } + + public void setLoc(Location loc) { + this.loc = loc; + } + + public BlockState getBlockState() { + return blockState; + } + + public void setBlockState(BlockState blockState) { + this.blockState = blockState; + } +} diff --git a/src/main/java/fun/ogre/ogredupealias/events/SPBEventListener.java b/src/main/java/fun/ogre/ogredupealias/events/SPBEventListener.java index 94f2c1e..95a7b83 100644 --- a/src/main/java/fun/ogre/ogredupealias/events/SPBEventListener.java +++ b/src/main/java/fun/ogre/ogredupealias/events/SPBEventListener.java @@ -37,11 +37,11 @@ public class SPBEventListener implements Listener { switch (tag) { case "SPBfire" -> { shooter.sendMessage("You were fire"); - DisplayUtils.tempBlocks(e.getHitBlock(),Material.RED_TERRACOTTA,2,600); + DisplayUtils.tempBlocks(e.getHitBlock(),Material.RED_TERRACOTTA,2,60); } case "SPBfrost" -> { shooter.sendMessage("You were frost"); - DisplayUtils.tempBlocks(e.getHitBlock(),Material.BLUE_TERRACOTTA,2,600); + DisplayUtils.tempBlocks(e.getHitBlock(),Material.BLUE_TERRACOTTA,2,60); } } } diff --git a/src/main/java/fun/ogre/ogredupealias/utils/DisplayUtils.java b/src/main/java/fun/ogre/ogredupealias/utils/DisplayUtils.java index f7d1cea..6951298 100644 --- a/src/main/java/fun/ogre/ogredupealias/utils/DisplayUtils.java +++ b/src/main/java/fun/ogre/ogredupealias/utils/DisplayUtils.java @@ -1,6 +1,7 @@ package fun.ogre.ogredupealias.utils; import fun.ogre.ogredupealias.OgreDupeAlias; +import fun.ogre.ogredupealias.data.BlockStorage; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -21,22 +22,17 @@ public final class DisplayUtils { public static void tempBlocks(Block centerBlock, Material desiredMaterial, int radius, int tickDuration) { Location loc = centerBlock.getLocation(); - List blocks = new ArrayList<>(); + List blocks = new ArrayList<>(); forEachBlockIn(loc.clone().add(radius,radius,radius), loc.clone().subtract(radius,radius,radius), (point) -> { Block b = point.getBlock(); if (!b.getType().isAir() && loc.distance(point) <= radius) { - blocks.add(b); + blocks.add(new BlockStorage(b)); b.setType(desiredMaterial); } }); Bukkit.getScheduler().runTaskLater(instance, () -> { - for (Block block : blocks) { - Location point = block.getLocation(); - Block b2 = point.getBlock(); - b2.setType(block.getType()); - b2.setBlockData(block.getBlockData()); - } - }, 60); + blocks.forEach(BlockStorage::restore); + }, tickDuration); } public static void forEachBlockIn(Location start, Location end, Consumer action) {