use of dev.rosewood.rosestacker.conversion.ConversionData in project RoseStacker by Rosewood-Development.
the class UltimateStackerConversionHandler method handleConversion.
@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
Set<Stack<?>> stacks = new HashSet<>();
for (ConversionData data : conversionData) {
Item item = data.getItem();
if (item == null)
continue;
int stackSize = this.getItemAmount(item);
StackedItem stackedItem = new StackedItem(stackSize, data.getItem());
this.stackManager.addItemStack(stackedItem);
stacks.add(stackedItem);
}
return stacks;
}
use of dev.rosewood.rosestacker.conversion.ConversionData in project RoseStacker by Rosewood-Development.
the class DataManager method getConversionData.
private Set<ConversionData> getConversionData(List<Entity> entities, String tableName, Connection connection) throws SQLException {
Set<ConversionData> conversionData = new HashSet<>();
Map<UUID, Entity> entityMap = new HashMap<>();
for (Entity entity : entities) entityMap.put(entity.getUniqueId(), entity);
if (entityMap.isEmpty())
return conversionData;
String entityUniqueIdsString = entityMap.keySet().stream().map(UUID::toString).map(x -> "'" + x + "'").collect(Collectors.joining(","));
// Get data
try (Statement statement = connection.createStatement()) {
String query = "SELECT entity_uuid, stack_size FROM " + this.getTablePrefix() + "convert_stacked_" + tableName + " WHERE entity_uuid IN (" + entityUniqueIdsString + ")";
ResultSet result = statement.executeQuery(query);
while (result.next()) {
UUID uuid = UUID.fromString(result.getString("entity_uuid"));
Entity entity = entityMap.get(uuid);
int stackSize = result.getInt("stack_size");
conversionData.add(new ConversionData(entity, stackSize));
}
}
// Delete data
try (Statement statement = connection.createStatement()) {
String query = "DELETE FROM " + this.getTablePrefix() + "convert_stacked_" + tableName + " WHERE entity_uuid IN (" + entityUniqueIdsString + ")";
statement.executeUpdate(query);
}
return conversionData;
}
use of dev.rosewood.rosestacker.conversion.ConversionData in project RoseStacker by Rosewood-Development.
the class EntityConversionHandler method handleConversion.
@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
Set<Stack<?>> stacks = new HashSet<>();
for (ConversionData data : conversionData) {
LivingEntity entity = data.getEntity();
// This could cause data loss if the entity actually has a custom name, but we have to remove the stack tag
entity.setCustomName(null);
entity.setCustomNameVisible(false);
StackedEntity stackedEntity = new StackedEntity(data.getEntity(), this.createEntityStackNBT(entity.getType(), data.getStackSize(), entity.getLocation()));
this.stackManager.addEntityStack(stackedEntity);
stacks.add(stackedEntity);
}
return stacks;
}
use of dev.rosewood.rosestacker.conversion.ConversionData in project RoseStacker by Rosewood-Development.
the class StackMobConversionHandler method handleConversion.
@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
Set<LivingEntity> entities = conversionData.stream().map(ConversionData::getEntity).filter(Objects::nonNull).collect(Collectors.toSet());
Set<Stack<?>> stacks = new HashSet<>();
for (LivingEntity entity : entities) {
PersistentDataContainer dataContainer = entity.getPersistentDataContainer();
if (dataContainer.has(PersistentDataUtils.CONVERTED_KEY, PersistentDataType.INTEGER))
continue;
int stackSize = dataContainer.getOrDefault(STACK_KEY, PersistentDataType.INTEGER, -1);
if (stackSize == -1)
continue;
dataContainer.set(PersistentDataUtils.CONVERTED_KEY, PersistentDataType.INTEGER, 1);
StackedEntity stackedEntity = new StackedEntity(entity, this.createEntityStackNBT(entity.getType(), stackSize, entity.getLocation()));
this.stackManager.addEntityStack(stackedEntity);
stacks.add(stackedEntity);
}
return stacks;
}
use of dev.rosewood.rosestacker.conversion.ConversionData in project RoseStacker by Rosewood-Development.
the class ConversionManager method convertChunkEntities.
/**
* Runs the chunk data conversion for any conversion handlers
*
* @param chunkEntities The entities in the chunk to convert
*/
public void convertChunkEntities(List<Entity> chunkEntities) {
Set<StackType> requiredStackTypes = new HashSet<>();
for (ConversionHandler conversionHandler : this.conversionHandlers) requiredStackTypes.add(conversionHandler.getRequiredDataStackType());
Map<StackType, Set<ConversionData>> conversionData = this.dataManager.getConversionData(chunkEntities, requiredStackTypes);
Set<Stack<?>> convertedStacks = new HashSet<>();
for (ConversionHandler conversionHandler : this.conversionHandlers) {
Set<ConversionData> data;
if (conversionHandler.shouldUseChunkEntities()) {
data = new HashSet<>();
switch(conversionHandler.getRequiredDataStackType()) {
case ENTITY:
for (Entity entity : chunkEntities) if (entity.getType() != EntityType.DROPPED_ITEM)
data.add(new ConversionData(entity));
break;
case ITEM:
for (Entity entity : chunkEntities) if (entity.getType() == EntityType.DROPPED_ITEM)
data.add(new ConversionData(entity));
break;
default:
break;
}
} else {
data = conversionData.get(conversionHandler.getRequiredDataStackType());
}
if (data.isEmpty())
continue;
convertedStacks.addAll(conversionHandler.handleConversion(data));
}
// Update nametags synchronously
if (!convertedStacks.isEmpty())
Bukkit.getScheduler().runTask(this.rosePlugin, () -> convertedStacks.forEach(Stack::updateDisplay));
}
Aggregations