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;
}
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);
}
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;
}
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;
}
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);
});
}
});
}
Aggregations