Search in sources :

Example 1 with CuboidRegion

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);
}
Also used : Arrays(java.util.Arrays) Config(me.untouchedodin0.plugin.config.Config) RevAutoSellListener(me.untouchedodin0.plugin.listener.RevAutoSellListener) ArgType(redempt.redlib.commandmanager.ArgType) ConfigManager(redempt.redlib.config.ConfigManager) Utils(me.untouchedodin0.plugin.util.Utils) Location(org.bukkit.Location) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Gson(com.google.gson.Gson) BlockPoints6(me.untouchedodin0.privatemines.we_6.worldedit.BlockPoints6) World(org.bukkit.World) PathMatcher(java.nio.file.PathMatcher) UpdateChecker(de.jeff_media.updatechecker.UpdateChecker) Path(java.nio.file.Path) Exceptions(me.untouchedodin0.plugin.util.Exceptions) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) CommandParser(redempt.redlib.commandmanager.CommandParser) IWrappedRegion(org.codemc.worldguardwrapper.region.IWrappedRegion) MineWorldManager(me.untouchedodin0.plugin.world.MineWorldManager) WE7Adapter(me.untouchedodin0.privatemines.we_7.worldedit.WE7Adapter) MineTypeManager(me.untouchedodin0.plugin.mines.MineTypeManager) PrivateMinesExpansion(me.untouchedodin0.plugin.util.placeholderapi.PrivateMinesExpansion) Metrics(org.bstats.bukkit.Metrics) UUID(java.util.UUID) SingleLineChart(org.bstats.charts.SingleLineChart) Collectors(java.util.stream.Collectors) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) RedLib(redempt.redlib.RedLib) List(java.util.List) MineData(me.untouchedodin0.plugin.mines.data.MineData) TimeStorage(me.untouchedodin0.plugin.storage.TimeStorage) MineCreationTest(me.untouchedodin0.plugin.listener.MineCreationTest) MenuItemType(me.untouchedodin0.plugin.config.menu.MenuItemType) MineFactory(me.untouchedodin0.plugin.factory.MineFactory) WorldEditAdapter(me.untouchedodin0.privatemines.compat.WorldEditAdapter) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) MineConfig(me.untouchedodin0.plugin.config.MineConfig) PrivateMinesCommand(me.untouchedodin0.plugin.commands.PrivateMinesCommand) WorldEditCompatibility(me.untouchedodin0.privatemines.compat.WorldEditCompatibility) WorldGuardWrapper(org.codemc.worldguardwrapper.WorldGuardWrapper) AutoSellListener(me.untouchedodin0.plugin.listener.AutoSellListener) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) CuboidRegion(redempt.redlib.region.CuboidRegion) Economy(net.milkbowl.vault.economy.Economy) Files(java.nio.file.Files) IOException(java.io.IOException) MineType(me.untouchedodin0.plugin.mines.MineType) File(java.io.File) Messages(redempt.redlib.commandmanager.Messages) MineStorage(me.untouchedodin0.plugin.storage.MineStorage) Mine(me.untouchedodin0.plugin.mines.Mine) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) FileSystems(java.nio.file.FileSystems) CuboidRegion(redempt.redlib.region.CuboidRegion) IOException(java.io.IOException) World(org.bukkit.World) MineData(me.untouchedodin0.plugin.mines.data.MineData) PathMatcher(java.nio.file.PathMatcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mine(me.untouchedodin0.plugin.mines.Mine) MineType(me.untouchedodin0.plugin.mines.MineType) Files(java.nio.file.Files) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 2 with CuboidRegion

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);
}
Also used : Path(java.nio.file.Path) MineData(me.untouchedodin0.plugin.mines.data.MineData) TextComponent(net.md_5.bungee.api.chat.TextComponent) Mine(me.untouchedodin0.plugin.mines.Mine) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Material(org.bukkit.Material) CuboidRegion(redempt.redlib.region.CuboidRegion) UUID(java.util.UUID) File(java.io.File) IWrappedRegion(org.codemc.worldguardwrapper.region.IWrappedRegion) Location(org.bukkit.Location)

Example 3 with CuboidRegion

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;
}
Also used : ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) Operation(com.sk89q.worldedit.function.operation.Operation) CuboidRegion(redempt.redlib.region.CuboidRegion) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BlockVector3(com.sk89q.worldedit.math.BlockVector3) ClipboardFormat(com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat) CuboidRegion(redempt.redlib.region.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) EditSession(com.sk89q.worldedit.EditSession) ClipboardReader(com.sk89q.worldedit.extent.clipboard.io.ClipboardReader) WorldEditException(com.sk89q.worldedit.WorldEditException)

Example 4 with CuboidRegion

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;
}
Also used : ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) InputStream(java.io.InputStream) RegionOperationException(com.sk89q.worldedit.regions.RegionOperationException) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) Operation(com.sk89q.worldedit.function.operation.Operation) CuboidRegion(redempt.redlib.region.CuboidRegion) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) CuboidRegion(redempt.redlib.region.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard)

Example 5 with CuboidRegion

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));
}
Also used : Task(redempt.redlib.misc.Task) CuboidRegion(redempt.redlib.region.CuboidRegion)

Aggregations

CuboidRegion (redempt.redlib.region.CuboidRegion)13 Location (org.bukkit.Location)6 BukkitWorld (com.sk89q.worldedit.bukkit.BukkitWorld)4 World (com.sk89q.worldedit.world.World)4 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 IWrappedRegion (org.codemc.worldguardwrapper.region.IWrappedRegion)4 Gson (com.google.gson.Gson)3 Region (com.sk89q.worldedit.regions.Region)3 File (java.io.File)3 Arrays (java.util.Arrays)3 List (java.util.List)3 UUID (java.util.UUID)3 EditSession (com.sk89q.worldedit.EditSession)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 Operation (com.sk89q.worldedit.function.operation.Operation)2 RandomPattern (com.sk89q.worldedit.function.pattern.RandomPattern)2 ClipboardHolder (com.sk89q.worldedit.session.ClipboardHolder)2 UpdateChecker (de.jeff_media.updatechecker.UpdateChecker)2 FileSystems (java.nio.file.FileSystems)2