Best commit name frfr (admin util drag still broken)
This commit is contained in:
62
src/main/java/fun/ogre/ogredupealias/data/BlockStorage.java
Normal file
62
src/main/java/fun/ogre/ogredupealias/data/BlockStorage.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,11 +37,11 @@ public class SPBEventListener implements Listener {
|
|||||||
switch (tag) {
|
switch (tag) {
|
||||||
case "SPBfire" -> {
|
case "SPBfire" -> {
|
||||||
shooter.sendMessage("You were fire");
|
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" -> {
|
case "SPBfrost" -> {
|
||||||
shooter.sendMessage("You were frost");
|
shooter.sendMessage("You were frost");
|
||||||
DisplayUtils.tempBlocks(e.getHitBlock(),Material.BLUE_TERRACOTTA,2,600);
|
DisplayUtils.tempBlocks(e.getHitBlock(),Material.BLUE_TERRACOTTA,2,60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package fun.ogre.ogredupealias.utils;
|
package fun.ogre.ogredupealias.utils;
|
||||||
|
|
||||||
import fun.ogre.ogredupealias.OgreDupeAlias;
|
import fun.ogre.ogredupealias.OgreDupeAlias;
|
||||||
|
import fun.ogre.ogredupealias.data.BlockStorage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -21,22 +22,17 @@ public final class DisplayUtils {
|
|||||||
|
|
||||||
public static void tempBlocks(Block centerBlock, Material desiredMaterial, int radius, int tickDuration) {
|
public static void tempBlocks(Block centerBlock, Material desiredMaterial, int radius, int tickDuration) {
|
||||||
Location loc = centerBlock.getLocation();
|
Location loc = centerBlock.getLocation();
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<BlockStorage> blocks = new ArrayList<>();
|
||||||
forEachBlockIn(loc.clone().add(radius,radius,radius), loc.clone().subtract(radius,radius,radius), (point) -> {
|
forEachBlockIn(loc.clone().add(radius,radius,radius), loc.clone().subtract(radius,radius,radius), (point) -> {
|
||||||
Block b = point.getBlock();
|
Block b = point.getBlock();
|
||||||
if (!b.getType().isAir() && loc.distance(point) <= radius) {
|
if (!b.getType().isAir() && loc.distance(point) <= radius) {
|
||||||
blocks.add(b);
|
blocks.add(new BlockStorage(b));
|
||||||
b.setType(desiredMaterial);
|
b.setType(desiredMaterial);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Bukkit.getScheduler().runTaskLater(instance, () -> {
|
Bukkit.getScheduler().runTaskLater(instance, () -> {
|
||||||
for (Block block : blocks) {
|
blocks.forEach(BlockStorage::restore);
|
||||||
Location point = block.getLocation();
|
}, tickDuration);
|
||||||
Block b2 = point.getBlock();
|
|
||||||
b2.setType(block.getType());
|
|
||||||
b2.setBlockData(block.getBlockData());
|
|
||||||
}
|
|
||||||
}, 60);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forEachBlockIn(Location start, Location end, Consumer<Location> action) {
|
public static void forEachBlockIn(Location start, Location end, Consumer<Location> action) {
|
||||||
|
|||||||
Reference in New Issue
Block a user