Search in sources :

Example 1 with StackedBarrel

use of com.bgsoftware.wildstacker.api.objects.StackedBarrel in project IridiumSkyblock by Iridium-Development.

the class WildStackerSupport method getExtraBlocks.

@Override
public int getExtraBlocks(Island island, XMaterial material) {
    IslandBlocks islandBlocks = IridiumSkyblock.getInstance().getIslandManager().getIslandBlock(island, material);
    int stackedBlocks = 0;
    for (StackedBarrel stackedBarrel : WildStackerAPI.getWildStacker().getSystemManager().getStackedBarrels()) {
        if (!island.isInIsland(stackedBarrel.getLocation()))
            continue;
        if (material != XMaterial.matchXMaterial(stackedBarrel.getType()))
            continue;
        if (material == XMaterial.matchXMaterial(stackedBarrel.getType())) {
            stackedBlocks--;
        } else {
            stackedBlocks += stackedBarrel.getStackAmount();
        }
    }
    islandBlocks.setExtraAmount(stackedBlocks);
    return stackedBlocks;
}
Also used : StackedBarrel(com.bgsoftware.wildstacker.api.objects.StackedBarrel) IslandBlocks(com.iridium.iridiumskyblock.database.IslandBlocks)

Example 2 with StackedBarrel

use of com.bgsoftware.wildstacker.api.objects.StackedBarrel in project Level by BentoBoxWorld.

the class IslandLevelCalculator method handleStackedBlocks.

private void handleStackedBlocks() {
    // Deal with any stacked blocks
    Iterator<Location> it = stackedBlocks.iterator();
    while (it.hasNext()) {
        Location v = it.next();
        Util.getChunkAtAsync(v).thenAccept(c -> {
            Block cauldronBlock = v.getBlock();
            boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
            if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(cauldronBlock)) {
                StackedBarrel barrel = WildStackerAPI.getStackedBarrel(cauldronBlock);
                int barrelAmt = WildStackerAPI.getBarrelAmount(cauldronBlock);
                for (int _x = 0; _x < barrelAmt; _x++) {
                    checkBlock(barrel.getType(), belowSeaLevel);
                }
            }
            it.remove();
        });
    }
}
Also used : StackedBarrel(com.bgsoftware.wildstacker.api.objects.StackedBarrel) Block(org.bukkit.block.Block) Location(org.bukkit.Location)

Example 3 with StackedBarrel

use of com.bgsoftware.wildstacker.api.objects.StackedBarrel in project RoseStacker by Rosewood-Development.

the class WildStackerPluginConverter method convert.

@Override
public void convert() {
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    // Force save loaded data
    SystemManager systemHandler = WildStackerAPI.getWildStacker().getSystemManager();
    systemHandler.performCacheSave();
    // Go through the database to be able to load all information
    DatabaseConnector connector = new SQLiteConnector(this.wildStacker, "database");
    connector.connect(connection -> {
        // Load barrels (blocks)
        Set<StackedBlock> stackedBlocks = new HashSet<>();
        try (Statement statement = connection.createStatement()) {
            ResultSet result = statement.executeQuery("SELECT location, stackAmount FROM barrels");
            while (result.next()) {
                Location location = this.parseLocation(result.getString("location"), ',');
                if (location == null)
                    continue;
                int amount = result.getInt("stackAmount");
                Material type = systemHandler.getStackedSnapshot(location.getChunk()).getStackedBarrelItem(location).getValue().getType();
                Block block = location.getBlock();
                // Remove hologram thingy
                StackedBarrel barrel = systemHandler.getStackedBarrel(block);
                if (barrel != null)
                    barrel.removeDisplayBlock();
                // Set the block type to the stack type since we just removed the hologram thingy
                block.setType(type);
                // Stacks of 1 aren't really stacks
                if (amount == 1)
                    continue;
                stackedBlocks.add(new StackedBlock(amount, block));
            }
        }
        // Load spawners
        Set<StackedSpawner> stackedSpawners = new HashSet<>();
        try (Statement statement = connection.createStatement()) {
            ResultSet result = statement.executeQuery("SELECT location, stackAmount FROM spawners");
            while (result.next()) {
                Location location = this.parseLocation(result.getString("location"), ',');
                if (location == null)
                    continue;
                Block block = location.getBlock();
                BlockState blockState = block.getState();
                if (!(blockState instanceof CreatureSpawner))
                    continue;
                int amount = result.getInt("stackAmount");
                stackedSpawners.add(new StackedSpawner(amount, location));
            }
        }
        if (!stackedBlocks.isEmpty() || !stackedSpawners.isEmpty()) {
            Bukkit.getScheduler().runTask(this.rosePlugin, () -> {
                for (StackedBlock stackedBlock : stackedBlocks) stackManager.createBlockStack(stackedBlock.getLocation().getBlock(), stackedBlock.getStackSize());
                for (StackedSpawner stackedSpawner : stackedSpawners) stackManager.createSpawnerStack(stackedSpawner.getLocation().getBlock(), stackedSpawner.getStackSize(), false);
            });
        }
    });
}
Also used : DatabaseConnector(dev.rosewood.rosegarden.database.DatabaseConnector) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) StackManager(dev.rosewood.rosestacker.manager.StackManager) Statement(java.sql.Statement) SystemManager(com.bgsoftware.wildstacker.api.handlers.SystemManager) Material(org.bukkit.Material) CreatureSpawner(org.bukkit.block.CreatureSpawner) BlockState(org.bukkit.block.BlockState) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) SQLiteConnector(dev.rosewood.rosegarden.database.SQLiteConnector) ResultSet(java.sql.ResultSet) StackedBarrel(com.bgsoftware.wildstacker.api.objects.StackedBarrel) Block(org.bukkit.block.Block) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Aggregations

StackedBarrel (com.bgsoftware.wildstacker.api.objects.StackedBarrel)3 Location (org.bukkit.Location)2 Block (org.bukkit.block.Block)2 SystemManager (com.bgsoftware.wildstacker.api.handlers.SystemManager)1 IslandBlocks (com.iridium.iridiumskyblock.database.IslandBlocks)1 DatabaseConnector (dev.rosewood.rosegarden.database.DatabaseConnector)1 SQLiteConnector (dev.rosewood.rosegarden.database.SQLiteConnector)1 StackManager (dev.rosewood.rosestacker.manager.StackManager)1 StackedBlock (dev.rosewood.rosestacker.stack.StackedBlock)1 StackedSpawner (dev.rosewood.rosestacker.stack.StackedSpawner)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashSet (java.util.HashSet)1 Material (org.bukkit.Material)1 BlockState (org.bukkit.block.BlockState)1 CreatureSpawner (org.bukkit.block.CreatureSpawner)1