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