use of dev.rosewood.rosestacker.stack.StackedEntity in project RoseStacker by Rosewood-Development.
the class EntityListener method onChickenLayEgg.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onChickenLayEgg(EntityDropItemEvent event) {
if (event.getEntityType() != EntityType.CHICKEN || event.getItemDrop().getItemStack().getType() != Material.EGG)
return;
if (this.stackManager.isWorldDisabled(event.getEntity().getWorld()))
return;
if (!this.stackManager.isEntityStackingEnabled())
return;
Chicken chickenEntity = (Chicken) event.getEntity();
StackedEntity stackedEntity = this.stackManager.getStackedEntity(chickenEntity);
if (stackedEntity == null || stackedEntity.getStackSize() == 1)
return;
ChickenStackSettings chickenStackSettings = (ChickenStackSettings) stackedEntity.getStackSettings();
if (!chickenStackSettings.shouldMultiplyEggDropsByStackSize())
return;
event.getItemDrop().remove();
List<ItemStack> items = GuiUtil.getMaterialAmountAsItemStacks(Material.EGG, stackedEntity.getStackSize());
this.stackManager.preStackItems(items, event.getEntity().getLocation());
}
use of dev.rosewood.rosestacker.stack.StackedEntity 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.StackedEntity in project RoseStacker by Rosewood-Development.
the class EntityListener method handleEntityDeath.
private void handleEntityDeath(EntityEvent event, LivingEntity entity, boolean useLastDamageCause) {
if (this.stackManager.isWorldDisabled(entity.getWorld()))
return;
if (!this.stackManager.isEntityStackingEnabled())
return;
StackedEntity stackedEntity = this.stackManager.getStackedEntity(entity);
if (stackedEntity == null)
return;
if (stackedEntity.getStackSize() == 1) {
this.stackManager.removeEntityStack(stackedEntity);
return;
}
// Should we kill the entire stack at once?
EntityDamageEvent lastDamageCause = entity.getLastDamageCause();
if (useLastDamageCause && (stackedEntity.getStackSettings().shouldKillEntireStackOnDeath() || (Setting.SPAWNER_DISABLE_MOB_AI_OPTIONS_KILL_ENTIRE_STACK_ON_DEATH.getBoolean() && PersistentDataUtils.isAiDisabled(entity)) || (lastDamageCause != null && Setting.ENTITY_KILL_ENTIRE_STACK_CONDITIONS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(lastDamageCause.getCause().name()))) || (entity.getKiller() != null && entity.getKiller().hasPermission("rosestacker.killentirestack")))) {
if (Setting.ENTITY_DROP_ACCURATE_ITEMS.getBoolean()) {
if (entity instanceof Slime)
((Slime) entity).setSize(1);
if (event instanceof EntityDeathEvent) {
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
stackedEntity.dropStackLoot(new ArrayList<>(deathEvent.getDrops()), deathEvent.getDroppedExp());
deathEvent.getDrops().clear();
} else {
stackedEntity.dropStackLoot(null, 0);
}
} else if (Setting.ENTITY_DROP_ACCURATE_EXP.getBoolean() && event instanceof EntityDeathEvent) {
EntityDeathEvent deathEvent = (EntityDeathEvent) event;
deathEvent.setDroppedExp(deathEvent.getDroppedExp() * stackedEntity.getStackSize());
}
Player killer = entity.getKiller();
if (killer != null && stackedEntity.getStackSize() - 1 > 0)
killer.incrementStatistic(Statistic.KILL_ENTITY, entity.getType(), stackedEntity.getStackSize() - 1);
this.stackManager.removeEntityStack(stackedEntity);
return;
}
// Decrease stack size by 1
stackedEntity.updateDisplay();
stackedEntity.decreaseStackSize();
stackedEntity.getEntity().setVelocity(new Vector());
if (Setting.ENTITY_KILL_TRANSFER_VELOCITY.getBoolean()) {
stackedEntity.getEntity().setVelocity(entity.getVelocity());
entity.setVelocity(new Vector());
}
if (!Setting.ENTITY_DISPLAY_CORPSE.getBoolean())
event.getEntity().remove();
}
use of dev.rosewood.rosestacker.stack.StackedEntity in project RoseStacker by Rosewood-Development.
the class StackToolListener method onRightClick.
/**
* Handles Right Clicking for StackedEntities.
* Handles Shift Right Clicking for StackedEntities.
*
* @param event The PlayerInteractAtEntityEvent
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onRightClick(PlayerInteractAtEntityEvent event) {
Player player = event.getPlayer();
ItemStack tool = player.getInventory().getItemInMainHand();
if (!(event.getRightClicked() instanceof LivingEntity) || event.getHand() != EquipmentSlot.HAND || !ItemUtils.isStackingTool(tool))
return;
event.setCancelled(true);
if (!player.hasPermission("rosestacker.stacktool")) {
this.localeManager.sendMessage(player, "command-stacktool-no-permission");
return;
}
LivingEntity entity = (LivingEntity) event.getRightClicked();
StackedEntity stackedEntity = this.stackManager.getStackedEntity(entity);
if (stackedEntity == null) {
this.localeManager.sendMessage(player, "command-stacktool-invalid-entity");
return;
}
if (!player.isSneaking()) {
boolean stackable = !PersistentDataUtils.isUnstackable(entity);
PersistentDataUtils.setUnstackable(entity, stackable);
String stackableStr = !stackable ? "stackable" : "unstackable";
this.localeManager.sendMessage(player, "command-stacktool-marked-" + stackableStr, StringPlaceholders.single("type", stackedEntity.getStackSettings().getDisplayName()));
} else {
PersistentDataUtils.setUnstackable(entity, true);
List<LivingEntity> stackEntities = StackerUtils.deconstructStackedEntities(stackedEntity);
for (LivingEntity stackEntity : stackEntities) PersistentDataUtils.setUnstackable(stackEntity, true);
StackerUtils.reconstructStackedEntities(stackedEntity, stackEntities);
this.localeManager.sendMessage(player, "command-stacktool-marked-all-unstackable", StringPlaceholders.single("type", stackedEntity.getStackSettings().getDisplayName()));
}
}
use of dev.rosewood.rosestacker.stack.StackedEntity 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;
}
Aggregations