bed-wars/src/main/java/rip/tilly/bedwars/utils/LocationUtils.java

35 lines
900 B
Java
Raw Normal View History

2021-11-24 19:09:19 +00:00
package rip.tilly.bedwars.utils;
import org.bukkit.Location;
import org.bukkit.block.Block;
import java.util.ArrayList;
import java.util.List;
public class LocationUtils {
public static List<Block> getBlocks(Location center, int radius) {
return getBlocks(center, radius, radius);
}
public static List<Block> getBlocks(Location center, int radius, int yRadius) {
if (radius < 0) {
return new ArrayList<>();
}
int iterations = radius * 2 + 1;
List<Block> blocks = new ArrayList<>(iterations * iterations * iterations);
for (int x = -radius; x <= radius; x++) {
for (int y = -yRadius; y <= yRadius; y++) {
for (int z = -radius; z <= radius; z++) {
blocks.add(center.getBlock().getRelative(x, y, z));
}
}
}
return blocks;
}
}