use of redempt.redlib.region.CuboidRegion in project RedLib by Redempt.
the class Structure method getRegion.
/**
* Gets the region this Structure occupies
* @return The region this Structure occupies
*/
public CuboidRegion getRegion() {
int[] dim = this.getType().getDimensions();
Location loc = this.getRelative(dim[0] - 1, dim[1] - 1, dim[2] - 1).getBlock().getLocation();
return new CuboidRegion(this.loc, loc).expand(1, 0, 1, 0, 1, 0);
}
use of redempt.redlib.region.CuboidRegion in project RedLib by Redempt.
the class ProtectionListener method testAll.
private static boolean testAll(Block outside, List<Block> inside, ProtectionType type, Player player) {
if (inside == null) {
return true;
}
Location min = outside.getLocation();
Location max = outside.getLocation();
for (Block block : inside) {
max.setX(Math.max(max.getX(), block.getX()));
max.setY(Math.max(max.getY(), block.getY()));
max.setZ(Math.max(max.getZ(), block.getZ()));
min.setX(Math.min(min.getX(), block.getX()));
min.setY(Math.min(min.getY(), block.getY()));
min.setZ(Math.min(min.getZ(), block.getZ()));
}
CuboidRegion region = new CuboidRegion(min, max);
int radius = (int) Arrays.stream(region.getDimensions()).max().getAsDouble();
Set<ProtectionPolicy> applicable = ProtectionPolicy.regionMap.getNearby(region.getCenter(), radius);
for (ProtectionPolicy policy : applicable) {
if (policy.allow(outside, type, player) && inside.stream().anyMatch(b -> !policy.allow(b, type, player))) {
return false;
}
}
return true;
}
use of redempt.redlib.region.CuboidRegion in project RedLib by Redempt.
the class MultiBlockStructure method getRegion.
/**
* Gets the Region this multi-block structure would occupy, were it built here
* @param loc The location of the multi-block structure
* @param relX The relative X in the structure to center at
* @param relY The relative Y in the structure to center at
* @param relZ The relative Z in the structure to center at
* @param rotation The number of 90-degree clockwise rotations to apply
* @param mirror Whether to mirror the structure on the X axis
* @return The Region this multi-block structure would occupy
*/
public CuboidRegion getRegion(Location loc, int relX, int relY, int relZ, int rotation, boolean mirror) {
loc = loc.getBlock().getLocation();
Rotator rotator = new Rotator(rotation, mirror);
rotator.setLocation(relX, relZ);
Location start = loc.clone().subtract(rotator.getRotatedBlockX(), relY, rotator.getRotatedBlockZ());
rotator.setLocation(dimX, dimZ);
Location end = start.clone().add(rotator.getRotatedBlockX(), dimY, rotator.getRotatedBlockZ());
return new CuboidRegion(start, end);
}
use of redempt.redlib.region.CuboidRegion in project PrivateMinesOOP by UntouchedOdin0.
the class PrivateMines method loadMinesOld.
/**
* @deprecated
* This is the old system for loading the mines, it was non-async, so it wasn't thread friendly.
* We're using {@link PrivateMines#loadMines()} instead now as it's Async and threaded correctly.
*/
private void loadMinesOld() throws IOException {
final PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json");
AtomicInteger loadedMineCount = new AtomicInteger();
String worldName = mineWorldManager.getMinesWorld().getName();
Files.list(minesDirectory).filter(jsonMatcher::matches).map(Exceptions.throwing(Files::readAllLines)).map(lines -> String.join("\n", lines)).forEach(file -> {
Mine mine = new Mine(this);
MineData mineData = gson.fromJson(file, MineData.class);
int minX = mineData.getMinX();
int minY = mineData.getMinY();
int minZ = mineData.getMinZ();
int maxX = mineData.getMaxX();
int maxY = mineData.getMaxY();
int maxZ = mineData.getMaxZ();
final World world = Bukkit.getWorld(worldName);
if (world == null) {
throw new IllegalStateException("World " + mineData.getWorldName() + " does not exist!");
}
Location spawn = new Location(world, mineData.getSpawnX(), mineData.getSpawnY(), mineData.getSpawnZ());
Location min = new Location(world, minX, minY, minZ);
Location max = new Location(world, maxX, maxY, maxZ);
CuboidRegion cuboidRegion = new CuboidRegion(min, max);
mine.setSpawnLocation(spawn);
mine.setRegion(mineData.getFullRegion());
mine.setMiningRegion(cuboidRegion);
mine.setMineData(mineData);
mine.setMineType(mineTypeManager.getMineType(mineData.getMineType()));
mine.setMineOwner(mineData.getMineOwner());
mine.startResetTask();
mineStorage.addMine(mineData.getMineOwner(), mine);
mineWorldManager.getNextFreeLocation();
loadedMineCount.incrementAndGet();
});
getLogger().info(() -> "Loaded " + loadedMineCount.get() + " mines");
}
use of redempt.redlib.region.CuboidRegion in project PrivateMinesOOP by UntouchedOdin0.
the class WE6Adapter method fillRegion.
@Override
public void fillRegion(CuboidRegion region, Map<Material, Double> materials) {
World world = new BukkitWorld(region.getWorld());
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
editSession.enableQueue();
final RandomPattern randomPattern = new RandomPattern();
materials.forEach((material, chance) -> {
// noinspection deprecation SHUT UP
final BlockPattern pattern = new BlockPattern(new BaseBlock(material.getId()));
randomPattern.add(pattern, chance);
});
final Region worldEditRegion = new com.sk89q.worldedit.regions.CuboidRegion(BukkitUtil.toVector(region.getStart()), BukkitUtil.toVector(region.getEnd()));
try {
editSession.setBlocks(worldEditRegion, Patterns.wrap(randomPattern));
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
// this shouldn't happen
}
editSession.flushQueue();
}
Aggregations