use of redempt.redlib.region.CuboidRegion in project PrivateMinesOOP by UntouchedOdin0.
the class PrivateMines method loadMines.
private void loadMines() {
final PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json");
AtomicInteger loadedMinesCount = new AtomicInteger();
String worldName = mineWorldManager.getMinesWorld().getName();
final World world = Bukkit.getWorld(worldName);
Runnable runnable = () -> {
try {
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);
MineType mineType = mineTypeManager.getMineType(mineData.getMineType());
UUID owner = mineData.getMineOwner();
int minX = mineData.getMinX();
int minY = mineData.getMinY();
int minZ = mineData.getMinZ();
int maxX = mineData.getMaxX();
int maxY = mineData.getMaxY();
int maxZ = mineData.getMaxZ();
int spawnX = mineData.getSpawnX();
int spawnY = mineData.getSpawnY();
int spawnZ = mineData.getSpawnZ();
if (world == null) {
throw new IllegalStateException("World " + worldName + " does not exist!");
}
Location spawn = new Location(world, spawnX, spawnY, spawnZ);
Location minimumLocation = new Location(world, minX, minY, minZ);
Location maximumLocation = new Location(world, maxX, maxY, maxZ);
CuboidRegion miningRegion = new CuboidRegion(minimumLocation, maximumLocation);
mine.setSpawnLocation(spawn);
mine.setRegion(mineData.getFullRegion());
mine.setMiningRegion(miningRegion);
mine.setMineData(mineData);
mine.setMineType(mineType);
mine.setMineOwner(owner);
mine.startResetTask();
mineStorage.addMine(owner, mine);
mineWorldManager.getNextFreeLocation();
loadedMinesCount.incrementAndGet();
});
if (loadedMinesCount.get() == 1) {
getLogger().info("Loaded " + loadedMinesCount.get() + " mine!");
} else {
getLogger().info("Loaded " + loadedMinesCount.get() + " mines!");
}
} catch (IOException e) {
e.printStackTrace();
}
};
CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(runnable);
}
use of redempt.redlib.region.CuboidRegion in project PrivateMinesOOP by UntouchedOdin0.
the class MineFactory method createMine.
public void createMine(Player player, Location location, @NotNull MineType mineType, boolean replaceOld) {
UUID uuid = player.getUniqueId();
Material spawnMaterial = Config.spawnPoint;
Material mineCornerMaterial = Config.mineCorner;
File schematicFile = new File("plugins/PrivateMines/schematics/" + mineType.getFile());
Path path = schematicFile.toPath();
Mine mine = new Mine(privateMines);
MineData mineData = new MineData();
CuboidRegion region = privateMines.getWorldEditAdapter().pasteSchematic(location, path);
mineBlocks = findMineBlocks(region, spawnMaterial, mineCornerMaterial);
spawnLocation = mineBlocks.spawnLocation;
corner1 = mineBlocks.corners[0];
corner2 = mineBlocks.corners[1];
final Location fullCorner1 = region.getStart();
final Location fullCorner2 = region.getEnd();
final CuboidRegion miningRegion = new CuboidRegion(corner1, corner2);
final CuboidRegion fullRegion = new CuboidRegion(fullCorner1, fullCorner2);
mine.setMiningRegion(miningRegion);
mine.setFullRegion(fullRegion);
mine.setRegion(region);
mine.setSpawnLocation(spawnLocation);
mine.setMineType(mineType);
mine.setMineOwner(player.getUniqueId());
mineData.setMineOwner(uuid);
mineData.setSpawnX(spawnLocation.getBlockX());
mineData.setSpawnY(spawnLocation.getBlockY());
mineData.setSpawnZ(spawnLocation.getBlockZ());
mineData.setMiningRegion(miningRegion);
mineData.setFullRegion(fullRegion);
mineData.setMineType(mineType.getName());
mine.setMineData(mineData);
utils.saveMineData(uuid, mineData);
mine.reset();
mine.startResetTask();
if (replaceOld) {
privateMines.getMineStorage().replaceMine(uuid, mine);
player.sendMessage(Messages.msg("recievedMine"));
String commandToSuggest = "/privatemines teleport %name%".replace("%name%", player.getName());
// Make a new component using the Bungee API.
TextComponent textComponent = new TextComponent("Click me to go to your mine!");
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandToSuggest));
player.spigot().sendMessage(textComponent);
} else {
privateMines.getMineStorage().addMine(uuid, mine);
player.sendMessage(Messages.msg("recievedMine"));
String commandToSuggest = "/privatemines teleport";
// Make a new component using the Bungee API.
TextComponent textComponent = new TextComponent(ChatColor.GREEN + "Click me to go to your mine!");
textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandToSuggest));
player.spigot().sendMessage(textComponent);
}
IWrappedRegion iWrappedMiningRegion = utils.createWorldGuardRegion(player, miningRegion);
// IWrappedRegion iWrappedFullRegion = utils.createFullWorldGuardRegion(player, fullRegion);
mine.setIWrappedMiningRegion(iWrappedMiningRegion);
// mine.setIWrappedFullRegion(iWrappedFullRegion);
utils.setMineFlags(mine);
// worldBorderApi.setBorder(player, 10, location);
}
use of redempt.redlib.region.CuboidRegion in project PrivateMinesOOP by UntouchedOdin0.
the class WE7Adapter method pasteSchematic.
@Override
public CuboidRegion pasteSchematic(Location location, Path file) {
ClipboardFormat clipboardFormat = ClipboardFormats.findByFile(file.toFile());
World world = BukkitAdapter.adapt(Objects.requireNonNull(location.getWorld()));
if (clipboardFormat == null) {
throw new IllegalArgumentException("File is not a valid schematic");
}
try (InputStream fix = Files.newInputStream(file);
ClipboardReader clipboardReader = clipboardFormat.getReader(fix)) {
Clipboard clipboard = clipboardReader.read();
if (clipboard == null) {
throw new IllegalArgumentException("Clipboard is null");
}
try (EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(world).build()) {
BlockVector3 centerVector = BlockVector3.at(location.getX(), location.getY(), location.getZ());
// If the clipboard isn't null prepare to create a paste operation, complete it and set the region stuff.
Operation operation = new ClipboardHolder(clipboard).createPaste(editSession).to(centerVector).ignoreAirBlocks(true).build();
Operations.complete(operation);
Region region = clipboard.getRegion();
region.shift(centerVector.subtract(clipboard.getOrigin()));
return new CuboidRegion(BukkitAdapter.adapt(location.getWorld(), region.getMinimumPoint()), BukkitAdapter.adapt(location.getWorld(), region.getMaximumPoint()));
}
} catch (IOException | WorldEditException e) {
e.printStackTrace();
}
return null;
}
use of redempt.redlib.region.CuboidRegion in project PrivateMinesOOP by UntouchedOdin0.
the class WE6Adapter method pasteSchematic.
@Override
public CuboidRegion pasteSchematic(Location location, Path file) {
World world = new BukkitWorld(location.getWorld());
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
try (InputStream fis = Files.newInputStream(file)) {
Clipboard clipboard = ClipboardFormat.SCHEMATIC.getReader(fis).read(editSession.getWorld().getWorldData());
Vector to = BukkitUtil.toVector(location).setY(clipboard.getOrigin().getY());
final ClipboardHolder clipboardHolder = new ClipboardHolder(clipboard, editSession.getWorld().getWorldData());
Operation operation = clipboardHolder.createPaste(editSession, editSession.getWorld().getWorldData()).to(to).ignoreAirBlocks(true).build();
Operations.completeBlindly(operation);
final Region region = clipboard.getRegion();
final Vector diff = to.subtract(clipboard.getOrigin());
region.shift(diff);
return new CuboidRegion(BukkitUtil.toLocation(location.getWorld(), region.getMinimumPoint()), BukkitUtil.toLocation(location.getWorld(), region.getMaximumPoint()));
} catch (IOException | RegionOperationException e) {
e.printStackTrace();
}
return null;
}
use of redempt.redlib.region.CuboidRegion in project PrivateMinesOOP by UntouchedOdin0.
the class Mine method fill.
public void fill(Map<Material, Double> blocks) {
CuboidRegion cuboidRegion = getMiningRegion();
Task task = Task.asyncDelayed(() -> privateMines.getWorldEditAdapter().fillRegion(cuboidRegion, blocks));
}
Aggregations