Search in sources :

Example 1 with SheepStackSettings

use of dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings in project RoseStacker by Rosewood-Development.

the class EntityListener method onSheepRegrowWool.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSheepRegrowWool(SheepRegrowWoolEvent event) {
    if (this.stackManager.isWorldDisabled(event.getEntity().getWorld()))
        return;
    if (!this.stackManager.isEntityStackingEnabled())
        return;
    Sheep sheepEntity = event.getEntity();
    StackedEntity stackedEntity = this.stackManager.getStackedEntity(sheepEntity);
    if (stackedEntity == null || stackedEntity.getStackSize() == 1)
        return;
    SheepStackSettings sheepStackSettings = (SheepStackSettings) stackedEntity.getStackSettings();
    double regrowPercentage = sheepStackSettings.getPercentageOfWoolToRegrowPerGrassEaten() / 100D;
    int regrowAmount = Math.max(1, (int) Math.round(stackedEntity.getStackSize() * regrowPercentage));
    if (sheepEntity.isSheared()) {
        sheepEntity.setSheared(false);
        regrowAmount--;
    }
    if (regrowAmount < 1)
        return;
    int fRegrowAmount = regrowAmount;
    Bukkit.getScheduler().runTaskAsynchronously(this.rosePlugin, () -> {
        int remaining = fRegrowAmount;
        List<Sheep> sheepList = StackerUtils.deconstructStackedEntities(stackedEntity).stream().map(x -> (Sheep) x).collect(Collectors.toList());
        for (Sheep sheep : sheepList) {
            if (sheep.isSheared()) {
                sheep.setSheared(false);
                remaining--;
                if (remaining <= 0)
                    break;
            }
        }
        StackerUtils.reconstructStackedEntities(stackedEntity, sheepList);
    });
}
Also used : StackedEntityDataEntry(dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry) TransformReason(org.bukkit.event.entity.EntityTransformEvent.TransformReason) SheepStackSettings(dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings) AttributeInstance(org.bukkit.attribute.AttributeInstance) Slime(org.bukkit.entity.Slime) RoseStacker(dev.rosewood.rosestacker.RoseStacker) Statistic(org.bukkit.Statistic) Animals(org.bukkit.entity.Animals) Projectile(org.bukkit.entity.Projectile) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent) Player(org.bukkit.entity.Player) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) ItemUtils(dev.rosewood.rosestacker.utils.ItemUtils) EventHandler(org.bukkit.event.EventHandler) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) Enderman(org.bukkit.entity.Enderman) Sheep(org.bukkit.entity.Sheep) PigZapEvent(org.bukkit.event.entity.PigZapEvent) PersistentDataUtils(dev.rosewood.rosestacker.utils.PersistentDataUtils) ItemStackSettings(dev.rosewood.rosestacker.stack.settings.ItemStackSettings) Material(org.bukkit.Material) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Bukkit(org.bukkit.Bukkit) Setting(dev.rosewood.rosestacker.manager.ConfigurationManager.Setting) NPC(org.bukkit.entity.NPC) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) Blaze(org.bukkit.entity.Blaze) EntityEvent(org.bukkit.event.entity.EntityEvent) PlayerShearEntityEvent(org.bukkit.event.player.PlayerShearEntityEvent) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) EntityCacheManager(dev.rosewood.rosestacker.manager.EntityCacheManager) Collectors(java.util.stream.Collectors) RosePlugin(dev.rosewood.rosegarden.RosePlugin) ChickenStackSettings(dev.rosewood.rosestacker.stack.settings.entity.ChickenStackSettings) ItemStack(org.bukkit.inventory.ItemStack) StackManager(dev.rosewood.rosestacker.manager.StackManager) List(java.util.List) Guardian(org.bukkit.entity.Guardian) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) StackerUtils(dev.rosewood.rosestacker.utils.StackerUtils) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) Item(org.bukkit.entity.Item) Variant(org.bukkit.entity.MushroomCow.Variant) Wither(org.bukkit.entity.Wither) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) EntityTargetEvent(org.bukkit.event.entity.EntityTargetEvent) SpawnerSpawnEvent(org.bukkit.event.entity.SpawnerSpawnEvent) ArrayList(java.util.ArrayList) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) EntityTransformEvent(org.bukkit.event.entity.EntityTransformEvent) GameMode(org.bukkit.GameMode) GuiUtil(dev.rosewood.guiframework.framework.util.GuiUtil) AsyncEntityDeathEvent(dev.rosewood.rosestacker.event.AsyncEntityDeathEvent) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) SheepRegrowWoolEvent(org.bukkit.event.entity.SheepRegrowWoolEvent) MushroomCow(org.bukkit.entity.MushroomCow) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Listener(org.bukkit.event.Listener) Attribute(org.bukkit.attribute.Attribute) EntityCombustEvent(org.bukkit.event.entity.EntityCombustEvent) EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) MushroomCowStackSettings(dev.rosewood.rosestacker.stack.settings.entity.MushroomCowStackSettings) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Bat(org.bukkit.entity.Bat) Vector(org.bukkit.util.Vector) Chicken(org.bukkit.entity.Chicken) EventPriority(org.bukkit.event.EventPriority) EntityCombustByBlockEvent(org.bukkit.event.entity.EntityCombustByBlockEvent) EntityDropItemEvent(org.bukkit.event.entity.EntityDropItemEvent) Golem(org.bukkit.entity.Golem) NMSAdapter(dev.rosewood.rosestacker.nms.NMSAdapter) Collections(java.util.Collections) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) SheepStackSettings(dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings) Sheep(org.bukkit.entity.Sheep) EventHandler(org.bukkit.event.EventHandler)

Example 2 with SheepStackSettings

use of dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings in project RoseStacker by Rosewood-Development.

the class EntityListener method handleSheepShear.

public static boolean handleSheepShear(RosePlugin rosePlugin, ItemStack shears, Entity entity) {
    if (entity.getType() != EntityType.SHEEP)
        return false;
    StackManager stackManager = rosePlugin.getManager(StackManager.class);
    if (stackManager.isWorldDisabled(entity.getWorld()))
        return false;
    if (!stackManager.isEntityStackingEnabled())
        return false;
    Sheep sheepEntity = (Sheep) entity;
    StackedEntity stackedEntity = stackManager.getStackedEntity(sheepEntity);
    if (stackedEntity == null || stackedEntity.getStackSize() == 1)
        return false;
    SheepStackSettings sheepStackSettings = (SheepStackSettings) stackedEntity.getStackSettings();
    if (!sheepStackSettings.shouldShearAllSheepInStack())
        return false;
    ItemUtils.damageTool(shears);
    ItemStack baseSheepWool = new ItemStack(ItemUtils.getWoolMaterial(sheepEntity.getColor()), getWoolDropAmount());
    sheepEntity.setSheared(true);
    List<ItemStack> drops = new ArrayList<>(Collections.singletonList(baseSheepWool));
    stackManager.setEntityUnstackingTemporarilyDisabled(true);
    Bukkit.getScheduler().runTaskAsynchronously(RoseStacker.getInstance(), () -> {
        try {
            List<Sheep> sheepList = StackerUtils.deconstructStackedEntities(stackedEntity).stream().map(x -> (Sheep) x).collect(Collectors.toList());
            for (Sheep sheep : sheepList) {
                if (!sheep.isSheared()) {
                    ItemStack sheepWool = new ItemStack(ItemUtils.getWoolMaterial(sheep.getColor()), getWoolDropAmount());
                    sheep.setSheared(true);
                    drops.add(sheepWool);
                }
            }
            StackerUtils.reconstructStackedEntities(stackedEntity, sheepList);
            Bukkit.getScheduler().runTask(RoseStacker.getInstance(), () -> stackManager.preStackItems(drops, sheepEntity.getLocation()));
        } finally {
            stackManager.setEntityUnstackingTemporarilyDisabled(false);
        }
    });
    return true;
}
Also used : StackedEntityDataEntry(dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry) TransformReason(org.bukkit.event.entity.EntityTransformEvent.TransformReason) SheepStackSettings(dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings) AttributeInstance(org.bukkit.attribute.AttributeInstance) Slime(org.bukkit.entity.Slime) RoseStacker(dev.rosewood.rosestacker.RoseStacker) Statistic(org.bukkit.Statistic) Animals(org.bukkit.entity.Animals) Projectile(org.bukkit.entity.Projectile) EntitySpawnEvent(org.bukkit.event.entity.EntitySpawnEvent) Player(org.bukkit.entity.Player) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) ItemUtils(dev.rosewood.rosestacker.utils.ItemUtils) EventHandler(org.bukkit.event.EventHandler) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) Enderman(org.bukkit.entity.Enderman) Sheep(org.bukkit.entity.Sheep) PigZapEvent(org.bukkit.event.entity.PigZapEvent) PersistentDataUtils(dev.rosewood.rosestacker.utils.PersistentDataUtils) ItemStackSettings(dev.rosewood.rosestacker.stack.settings.ItemStackSettings) Material(org.bukkit.Material) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Bukkit(org.bukkit.Bukkit) Setting(dev.rosewood.rosestacker.manager.ConfigurationManager.Setting) NPC(org.bukkit.entity.NPC) Entity(org.bukkit.entity.Entity) CreatureSpawnEvent(org.bukkit.event.entity.CreatureSpawnEvent) Blaze(org.bukkit.entity.Blaze) EntityEvent(org.bukkit.event.entity.EntityEvent) PlayerShearEntityEvent(org.bukkit.event.player.PlayerShearEntityEvent) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) EntityCacheManager(dev.rosewood.rosestacker.manager.EntityCacheManager) Collectors(java.util.stream.Collectors) RosePlugin(dev.rosewood.rosegarden.RosePlugin) ChickenStackSettings(dev.rosewood.rosestacker.stack.settings.entity.ChickenStackSettings) ItemStack(org.bukkit.inventory.ItemStack) StackManager(dev.rosewood.rosestacker.manager.StackManager) List(java.util.List) Guardian(org.bukkit.entity.Guardian) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) StackerUtils(dev.rosewood.rosestacker.utils.StackerUtils) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) Item(org.bukkit.entity.Item) Variant(org.bukkit.entity.MushroomCow.Variant) Wither(org.bukkit.entity.Wither) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) EntityTargetEvent(org.bukkit.event.entity.EntityTargetEvent) SpawnerSpawnEvent(org.bukkit.event.entity.SpawnerSpawnEvent) ArrayList(java.util.ArrayList) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) EntityTransformEvent(org.bukkit.event.entity.EntityTransformEvent) GameMode(org.bukkit.GameMode) GuiUtil(dev.rosewood.guiframework.framework.util.GuiUtil) AsyncEntityDeathEvent(dev.rosewood.rosestacker.event.AsyncEntityDeathEvent) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) SheepRegrowWoolEvent(org.bukkit.event.entity.SheepRegrowWoolEvent) MushroomCow(org.bukkit.entity.MushroomCow) StackedItem(dev.rosewood.rosestacker.stack.StackedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Listener(org.bukkit.event.Listener) Attribute(org.bukkit.attribute.Attribute) EntityCombustEvent(org.bukkit.event.entity.EntityCombustEvent) EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) MushroomCowStackSettings(dev.rosewood.rosestacker.stack.settings.entity.MushroomCowStackSettings) EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent) Bat(org.bukkit.entity.Bat) Vector(org.bukkit.util.Vector) Chicken(org.bukkit.entity.Chicken) EventPriority(org.bukkit.event.EventPriority) EntityCombustByBlockEvent(org.bukkit.event.entity.EntityCombustByBlockEvent) EntityDropItemEvent(org.bukkit.event.entity.EntityDropItemEvent) Golem(org.bukkit.entity.Golem) NMSAdapter(dev.rosewood.rosestacker.nms.NMSAdapter) Collections(java.util.Collections) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) SheepStackSettings(dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings) StackManager(dev.rosewood.rosestacker.manager.StackManager) ArrayList(java.util.ArrayList) Sheep(org.bukkit.entity.Sheep) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

GuiUtil (dev.rosewood.guiframework.framework.util.GuiUtil)2 RosePlugin (dev.rosewood.rosegarden.RosePlugin)2 RoseStacker (dev.rosewood.rosestacker.RoseStacker)2 AsyncEntityDeathEvent (dev.rosewood.rosestacker.event.AsyncEntityDeathEvent)2 Setting (dev.rosewood.rosestacker.manager.ConfigurationManager.Setting)2 EntityCacheManager (dev.rosewood.rosestacker.manager.EntityCacheManager)2 StackManager (dev.rosewood.rosestacker.manager.StackManager)2 StackSettingManager (dev.rosewood.rosestacker.manager.StackSettingManager)2 NMSAdapter (dev.rosewood.rosestacker.nms.NMSAdapter)2 NMSHandler (dev.rosewood.rosestacker.nms.NMSHandler)2 StackedEntityDataEntry (dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry)2 StackedEntity (dev.rosewood.rosestacker.stack.StackedEntity)2 StackedItem (dev.rosewood.rosestacker.stack.StackedItem)2 StackedSpawner (dev.rosewood.rosestacker.stack.StackedSpawner)2 ItemStackSettings (dev.rosewood.rosestacker.stack.settings.ItemStackSettings)2 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)2 ChickenStackSettings (dev.rosewood.rosestacker.stack.settings.entity.ChickenStackSettings)2 MushroomCowStackSettings (dev.rosewood.rosestacker.stack.settings.entity.MushroomCowStackSettings)2 SheepStackSettings (dev.rosewood.rosestacker.stack.settings.entity.SheepStackSettings)2 ItemUtils (dev.rosewood.rosestacker.utils.ItemUtils)2