Search in sources :

Example 1 with StackedSpawner

use of dev.rosewood.rosestacker.stack.StackedSpawner in project IridiumSkyblock by Iridium-Development.

the class RoseStackerSupport method getExtraSpawners.

@Override
public int getExtraSpawners(Island island, EntityType entityType) {
    IslandSpawners islandSpawners = IridiumSkyblock.getInstance().getIslandManager().getIslandSpawners(island, entityType);
    int stackedSpawners = 0;
    for (StackedSpawner stackedSpawner : RoseStackerAPI.getInstance().getStackedSpawners().values()) {
        if (!island.isInIsland(stackedSpawner.getLocation()))
            continue;
        if (stackedSpawner.getSpawner().getSpawnedType() != entityType)
            continue;
        stackedSpawners += (stackedSpawner.getStackSize() - 1);
    }
    islandSpawners.setExtraAmount(stackedSpawners);
    return stackedSpawners;
}
Also used : StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) IslandSpawners(com.iridium.iridiumskyblock.database.IslandSpawners)

Example 2 with StackedSpawner

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

the class DataUtils method writeStackedSpawners.

public static void writeStackedSpawners(Collection<StackedSpawner> stackedSpawners, Chunk chunk) {
    PersistentDataContainer pdc = chunk.getPersistentDataContainer();
    byte[] data = null;
    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream dataOutput = new ObjectOutputStream(outputStream)) {
        dataOutput.writeInt(SPAWNER_DATA_VERSION);
        dataOutput.writeInt(stackedSpawners.size());
        for (StackedSpawner stackedSpawner : stackedSpawners) {
            dataOutput.writeInt(stackedSpawner.getStackSize());
            dataOutput.writeInt(stackedSpawner.getLocation().getBlockX() & 0xF);
            dataOutput.writeInt(stackedSpawner.getLocation().getBlockY());
            dataOutput.writeInt(stackedSpawner.getLocation().getBlockZ() & 0xF);
            dataOutput.writeBoolean(stackedSpawner.isPlacedByPlayer());
        }
        // Serialize that array
        dataOutput.close();
        data = outputStream.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (data != null)
        pdc.set(CHUNK_SPAWNERS_KEY, PersistentDataType.BYTE_ARRAY, data);
}
Also used : StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer)

Example 3 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_17_R1.spawner.StackedSpawnerTileImpl) StackedSpawnerTile(dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 4 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_R2.TileEntity) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) BlockPosition(net.minecraft.server.v1_16_R2.BlockPosition) Block(org.bukkit.block.Block) WorldServer(net.minecraft.server.v1_16_R2.WorldServer) TileEntityMobSpawner(net.minecraft.server.v1_16_R2.TileEntityMobSpawner) StackedSpawnerTileImpl(dev.rosewood.rosestacker.nms.v1_16_R2.spawner.StackedSpawnerTileImpl) StackedSpawnerTile(dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld)

Example 5 with StackedSpawner

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

the class EpicSpawnersPluginConverter method convert.

@Override
public void convert() {
    // Query their database ourselves
    DatabaseConnector connector = new SQLiteConnector(this.epicSpawners);
    connector.connect(connection -> {
        Set<StackedSpawner> stackedSpawners = new HashSet<>();
        String tablePrefix = this.epicSpawners.getDataManager().getTablePrefix();
        try (Statement statement = connection.createStatement()) {
            String query = "SELECT amount, world, x, y, z FROM " + tablePrefix + "placed_spawners ps JOIN " + tablePrefix + "spawner_stacks ss ON ps.id = ss.spawner_id";
            ResultSet result = statement.executeQuery(query);
            while (result.next()) {
                World world = Bukkit.getWorld(result.getString("world"));
                if (world == null)
                    continue;
                int amount = result.getInt("amount");
                double x = result.getDouble("x");
                double y = result.getDouble("y");
                double z = result.getDouble("z");
                Location location = new Location(world, x, y, z);
                stackedSpawners.add(new StackedSpawner(amount, location));
            }
        }
        if (!stackedSpawners.isEmpty()) {
            Bukkit.getScheduler().runTask(this.rosePlugin, () -> {
                StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
                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) Statement(java.sql.Statement) StackManager(dev.rosewood.rosestacker.manager.StackManager) World(org.bukkit.World) SQLiteConnector(dev.rosewood.rosegarden.database.SQLiteConnector) ResultSet(java.sql.ResultSet) 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