Search in sources :

Example 6 with CuboidRegion

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

Example 7 with CuboidRegion

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;
}
Also used : ProtectionType(redempt.redlib.protection.ProtectionPolicy.ProtectionType) Arrays(java.util.Arrays) Cancellable(org.bukkit.event.Cancellable) Event(org.bukkit.event.Event) Set(java.util.Set) Player(org.bukkit.entity.Player) Function(java.util.function.Function) EventListener(redempt.redlib.misc.EventListener) ArrayList(java.util.ArrayList) RedLib(redempt.redlib.RedLib) Consumer(java.util.function.Consumer) List(java.util.List) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EventPriority(org.bukkit.event.EventPriority) CuboidRegion(redempt.redlib.region.CuboidRegion) BiConsumer(java.util.function.BiConsumer) Block(org.bukkit.block.Block) CuboidRegion(redempt.redlib.region.CuboidRegion) Location(org.bukkit.Location)

Example 8 with CuboidRegion

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

Example 9 with CuboidRegion

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");
}
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) MineData(me.untouchedodin0.plugin.mines.data.MineData) PathMatcher(java.nio.file.PathMatcher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mine(me.untouchedodin0.plugin.mines.Mine) CuboidRegion(redempt.redlib.region.CuboidRegion) World(org.bukkit.World) Location(org.bukkit.Location)

Example 10 with CuboidRegion

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();
}
Also used : BlockPattern(com.sk89q.worldedit.function.pattern.BlockPattern) RandomPattern(com.sk89q.worldedit.function.pattern.RandomPattern) com.sk89q.worldedit(com.sk89q.worldedit) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) CuboidRegion(redempt.redlib.region.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(redempt.redlib.region.CuboidRegion) World(com.sk89q.worldedit.world.World) BukkitWorld(com.sk89q.worldedit.bukkit.BukkitWorld) BaseBlock(com.sk89q.worldedit.blocks.BaseBlock)

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