Search in sources :

Example 1 with SystemManager

use of com.bgsoftware.wildstacker.api.handlers.SystemManager 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

SystemManager (com.bgsoftware.wildstacker.api.handlers.SystemManager)1 StackedBarrel (com.bgsoftware.wildstacker.api.objects.StackedBarrel)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 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 Block (org.bukkit.block.Block)1 BlockState (org.bukkit.block.BlockState)1 CreatureSpawner (org.bukkit.block.CreatureSpawner)1