Search in sources :

Example 1 with Stack

use of dev.rosewood.rosestacker.stack.Stack 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;
}
Also used : Item(org.bukkit.entity.Item) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) Stack(dev.rosewood.rosestacker.stack.Stack) ItemStack(org.bukkit.inventory.ItemStack) HashSet(java.util.HashSet)

Example 2 with Stack

use of dev.rosewood.rosestacker.stack.Stack 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;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) Stack(dev.rosewood.rosestacker.stack.Stack) HashSet(java.util.HashSet)

Example 3 with Stack

use of dev.rosewood.rosestacker.stack.Stack 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;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) Stack(dev.rosewood.rosestacker.stack.Stack) HashSet(java.util.HashSet) PersistentDataContainer(org.bukkit.persistence.PersistentDataContainer)

Example 4 with Stack

use of dev.rosewood.rosestacker.stack.Stack 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));
}
Also used : Entity(org.bukkit.entity.Entity) StackType(dev.rosewood.rosestacker.stack.StackType) HashSet(java.util.HashSet) Set(java.util.Set) ConversionHandler(dev.rosewood.rosestacker.conversion.handler.ConversionHandler) ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) HashSet(java.util.HashSet) Stack(dev.rosewood.rosestacker.stack.Stack)

Example 5 with Stack

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

the class ItemConversionHandler method handleConversion.

@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
    Set<Stack<?>> stacks = new HashSet<>();
    for (ConversionData data : conversionData) {
        StackedItem stackedItem = new StackedItem(data.getStackSize(), data.getItem());
        this.stackManager.addItemStack(stackedItem);
        stacks.add(stackedItem);
    }
    return stacks;
}
Also used : ConversionData(dev.rosewood.rosestacker.conversion.ConversionData) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) Stack(dev.rosewood.rosestacker.stack.Stack) HashSet(java.util.HashSet)

Aggregations

ConversionData (dev.rosewood.rosestacker.conversion.ConversionData)7 Stack (dev.rosewood.rosestacker.stack.Stack)7 HashSet (java.util.HashSet)7 StackedEntity (dev.rosewood.rosestacker.stack.StackedEntity)3 StackedItem (dev.rosewood.rosestacker.stack.StackedItem)3 LivingEntity (org.bukkit.entity.LivingEntity)3 PersistentDataContainer (org.bukkit.persistence.PersistentDataContainer)3 Item (org.bukkit.entity.Item)2 ConversionHandler (dev.rosewood.rosestacker.conversion.handler.ConversionHandler)1 StackType (dev.rosewood.rosestacker.stack.StackType)1 Set (java.util.Set)1 Entity (org.bukkit.entity.Entity)1 ItemStack (org.bukkit.inventory.ItemStack)1