Search in sources :

Example 11 with StackedSpawner

use of dev.rosewood.rosestacker.stack.StackedSpawner in project RoseStacker by Rosewood-Development.

the class DataUtils method readStackedSpawners.

public static List<StackedSpawner> readStackedSpawners(Chunk chunk) {
    PersistentDataContainer pdc = chunk.getPersistentDataContainer();
    List<StackedSpawner> stackedSpawners = new ArrayList<>();
    byte[] data = pdc.get(CHUNK_SPAWNERS_KEY, PersistentDataType.BYTE_ARRAY);
    if (data == null)
        return stackedSpawners;
    try (ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
        ObjectInputStream dataInput = new ObjectInputStream(inputStream)) {
        int dataVersion = dataInput.readInt();
        if (dataVersion == 1) {
            int length = dataInput.readInt();
            for (int i = 0; i < length; i++) {
                int stackSize = dataInput.readInt();
                int x = dataInput.readInt();
                int y = dataInput.readInt();
                int z = dataInput.readInt();
                boolean placedByPlayer = dataInput.readBoolean();
                Block block = chunk.getBlock(x, y, z);
                if (block.getType() == Material.SPAWNER)
                    stackedSpawners.add(new StackedSpawner(stackSize, block, placedByPlayer));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        pdc.remove(CHUNK_SPAWNERS_KEY);
    }
    return stackedSpawners;
}
Also used : StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer) ObjectInputStream(java.io.ObjectInputStream)

Example 12 with StackedSpawner

use of dev.rosewood.rosestacker.stack.StackedSpawner in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method injectStackedSpawnerTile.

@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
    StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
    Block block = stackedSpawner.getBlock();
    ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
    BlockEntity blockEntity = level.getBlockEntity(new BlockPos(block.getX(), block.getY(), block.getZ()));
    if (blockEntity instanceof SpawnerBlockEntity) {
        SpawnerBlockEntity spawnerBlockEntity = (SpawnerBlockEntity) blockEntity;
        if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
            StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
            unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
            return stackedSpawnerTile;
        } else {
            StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
            spawnerTile.updateStackedSpawner(stackedSpawner);
            return spawnerTile;
        }
    }
    return null;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) Block(org.bukkit.block.Block) BlockPos(net.minecraft.core.BlockPos) StackedSpawnerTileImpl(dev.rosewood.rosestacker.nms.v1_18_R2.spawner.StackedSpawnerTileImpl) StackedSpawnerTile(dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 13 with StackedSpawner

use of dev.rosewood.rosestacker.stack.StackedSpawner in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method injectStackedSpawnerTile.

@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
    StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
    Block block = stackedSpawner.getBlock();
    ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
    BlockEntity blockEntity = level.getBlockEntity(new BlockPos(block.getX(), block.getY(), block.getZ()));
    if (blockEntity instanceof SpawnerBlockEntity) {
        SpawnerBlockEntity spawnerBlockEntity = (SpawnerBlockEntity) blockEntity;
        if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
            StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
            unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
            return stackedSpawnerTile;
        } else {
            StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
            spawnerTile.updateStackedSpawner(stackedSpawner);
            return spawnerTile;
        }
    }
    return null;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) Block(org.bukkit.block.Block) BlockPos(net.minecraft.core.BlockPos) StackedSpawnerTileImpl(dev.rosewood.rosestacker.nms.v1_18_R1.spawner.StackedSpawnerTileImpl) StackedSpawnerTile(dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 14 with StackedSpawner

use of dev.rosewood.rosestacker.stack.StackedSpawner in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method injectStackedSpawnerTile.

@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
    StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
    Block block = stackedSpawner.getBlock();
    WorldServer level = ((CraftWorld) block.getWorld()).getHandle();
    TileEntity blockEntity = level.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
    if (blockEntity instanceof TileEntityMobSpawner) {
        TileEntityMobSpawner spawnerBlockEntity = (TileEntityMobSpawner) blockEntity;
        if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
            StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
            unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
            return stackedSpawnerTile;
        } else {
            StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
            spawnerTile.updateStackedSpawner(stackedSpawner);
            return spawnerTile;
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.server.v1_16_R3.TileEntity) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) Block(org.bukkit.block.Block) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) TileEntityMobSpawner(net.minecraft.server.v1_16_R3.TileEntityMobSpawner) StackedSpawnerTileImpl(dev.rosewood.rosestacker.nms.v1_16_R3.spawner.StackedSpawnerTileImpl) StackedSpawnerTile(dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 15 with StackedSpawner

use of dev.rosewood.rosestacker.stack.StackedSpawner in project RoseStacker by Rosewood-Development.

the class UltimateStackerPluginConverter method convert.

@Override
public void convert() {
    // If EpicSpawners is installed, spawner stacking functionality is handled by that plugin instead
    if (Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"))
        return;
    DataManager dataManager = this.rosePlugin.getManager(DataManager.class);
    // Force save loaded data
    this.ultimateStacker.getDataManager().bulkUpdateSpawners(this.ultimateStacker.getSpawnerStackManager().getStacks());
    // Go through the database to be able to load all spawner information
    DatabaseConnector connector = this.ultimateStacker.getDatabaseConnector();
    connector.connect(connection -> {
        // Load entities
        try (Statement statement = connection.createStatement()) {
            String query = "SELECT he.uuid AS uuid, COUNT(se.host) + 1 AS stackAmount FROM ultimatestacker_host_entities he " + "JOIN ultimatestacker_stacked_entities se ON he.id = se.host " + "GROUP BY se.host";
            ResultSet result = statement.executeQuery(query);
            Set<ConversionData> entityConversionData = new HashSet<>();
            while (result.next()) {
                UUID uuid = UUID.fromString(result.getString("uuid"));
                int amount = result.getInt("stackAmount");
                entityConversionData.add(new ConversionData(uuid, amount));
            }
            Map<StackType, Set<ConversionData>> conversionData = new HashMap<>();
            conversionData.put(StackType.ENTITY, entityConversionData);
            dataManager.setConversionData(conversionData);
        }
        // Load blocks
        Set<StackedBlock> stackedBlocks = new HashSet<>();
        try (Statement statement = connection.createStatement()) {
            ResultSet result = statement.executeQuery("SELECT amount, world, x, y, z FROM ultimatestacker_blocks");
            while (result.next()) {
                World world = Bukkit.getWorld(result.getString("world"));
                if (world == null)
                    continue;
                int amount = result.getInt("amount");
                if (amount == 1)
                    continue;
                Block block = world.getBlockAt(result.getInt("x"), result.getInt("y"), result.getInt("z"));
                stackedBlocks.add(new StackedBlock(amount, block));
            }
        }
        // Load spawners
        Set<StackedSpawner> stackedSpawners = new HashSet<>();
        try (Statement statement = connection.createStatement()) {
            ResultSet result = statement.executeQuery("SELECT amount, world, x, y, z FROM ultimatestacker_spawners");
            while (result.next()) {
                World world = Bukkit.getWorld(result.getString("world"));
                if (world == null)
                    continue;
                int x = result.getInt("x");
                int y = result.getInt("y");
                int z = result.getInt("z");
                Location location = new Location(world, x, y, z);
                int amount = result.getInt("amount");
                stackedSpawners.add(new StackedSpawner(amount, location));
            }
        }
        if (!stackedBlocks.isEmpty() || !stackedSpawners.isEmpty()) {
            StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
            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(com.songoda.ultimatestacker.core.database.DatabaseConnector) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) HashMap(java.util.HashMap) Statement(java.sql.Statement) StackManager(dev.rosewood.rosestacker.manager.StackManager) DataManager(dev.rosewood.rosestacker.manager.DataManager) World(org.bukkit.World) StackType(dev.rosewood.rosestacker.stack.StackType) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) ResultSet(java.sql.ResultSet) Block(org.bukkit.block.Block) StackedBlock(dev.rosewood.rosestacker.stack.StackedBlock) ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) UUID(java.util.UUID) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Aggregations

StackedSpawner (dev.rosewood.rosestacker.stack.StackedSpawner)21 Block (org.bukkit.block.Block)17 StackManager (dev.rosewood.rosestacker.manager.StackManager)11 Location (org.bukkit.Location)9 StackedSpawnerTile (dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile)8 StackedBlock (dev.rosewood.rosestacker.stack.StackedBlock)8 ItemStack (org.bukkit.inventory.ItemStack)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 EventHandler (org.bukkit.event.EventHandler)6 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)5 EntityType (org.bukkit.entity.EntityType)5 Material (org.bukkit.Material)4 World (org.bukkit.World)4 LivingEntity (org.bukkit.entity.LivingEntity)4 RoseStacker (dev.rosewood.rosestacker.RoseStacker)3 Setting (dev.rosewood.rosestacker.manager.ConfigurationManager.Setting)3 StackSettingManager (dev.rosewood.rosestacker.manager.StackSettingManager)3 ConditionTag (dev.rosewood.rosestacker.spawner.conditions.ConditionTag)3 NoneConditionTag (dev.rosewood.rosestacker.spawner.conditions.tags.NoneConditionTag)3