use of dev.rosewood.roseloot.loot.LootContents in project RoseLoot by Rosewood-Development.
the class LootTableManager method callEvent.
/**
* Calls the PostLootGenerateEvent for the given LootResult.
* May modify the given LootResult or return a new one entirely.
*
* @param lootResult The LootResult to call the event with
* @return The LootResult after the event has been called
*/
private LootResult callEvent(LootResult lootResult) {
PostLootGenerateEvent event = new PostLootGenerateEvent(lootResult);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return new LootResult(lootResult.getLootContext(), new LootContents(lootResult.getLootContext()), OverwriteExisting.NONE);
if (!event.shouldDropItems())
lootResult.getLootContents().removeItems();
if (!event.shouldDropExperience())
lootResult.getLootContents().removeExperience();
if (!event.shouldTriggerExtras())
lootResult.getLootContents().removeExtraTriggers();
lootResult.setOverwriteExisting(event.getOverwriteExisting());
return lootResult;
}
use of dev.rosewood.roseloot.loot.LootContents in project RoseLoot by Rosewood-Development.
the class LootGenerateListener method onLootGenerate.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onLootGenerate(LootGenerateEvent event) {
if (!(event.getInventoryHolder() instanceof Container))
return;
Block block = ((Container) event.getInventoryHolder()).getBlock();
if (Setting.DISABLED_WORLDS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(block.getWorld().getName())))
return;
LivingEntity looter = null;
if (event.getEntity() instanceof LivingEntity)
looter = (LivingEntity) event.getEntity();
LootContext lootContext = LootContext.builder(LootUtils.getEntityLuck(looter)).put(LootContextParams.ORIGIN, block.getLocation()).put(LootContextParams.LOOTER, looter).put(LootContextParams.LOOTED_BLOCK, block).put(LootContextParams.VANILLA_LOOT_TABLE_KEY, event.getLootTable().getKey()).build();
LootResult lootResult = this.lootTableManager.getLoot(LootTableTypes.CONTAINER, lootContext);
LootContents lootContents = lootResult.getLootContents();
// Overwrite existing loot if applicable
if (lootResult.shouldOverwriteItems())
event.getLoot().clear();
// Set items and drop experience
event.getLoot().addAll(lootResult.getLootContents().getItems());
int experience = lootContents.getExperience();
if (experience > 0) {
Location location = looter == null ? block.getLocation() : looter.getLocation();
block.getWorld().spawn(location, ExperienceOrb.class, x -> x.setExperience(experience));
}
lootContents.triggerExtras(block.getLocation());
}
use of dev.rosewood.roseloot.loot.LootContents in project RoseLoot by Rosewood-Development.
the class RoseStackerEntityDeathListener method onEntityStackMultipleDeath.
@EventHandler
public void onEntityStackMultipleDeath(EntityStackMultipleDeathEvent event) {
LivingEntity mainEntity = event.getStack().getEntity();
if (ConfigurationManager.Setting.DISABLED_WORLDS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(mainEntity.getWorld().getName())))
return;
Entity looter = null;
if (mainEntity.getLastDamageCause() instanceof EntityDamageByEntityEvent)
looter = ((EntityDamageByEntityEvent) mainEntity.getLastDamageCause()).getDamager();
List<LootContents> extras = new ArrayList<>();
for (Map.Entry<LivingEntity, EntityStackMultipleDeathEvent.EntityDrops> entry : event.getEntityDrops().entrySet()) {
LivingEntity entity = entry.getKey();
EntityStackMultipleDeathEvent.EntityDrops drops = entry.getValue();
LootContext lootContext = LootContext.builder(LootUtils.getEntityLuck(looter)).put(LootContextParams.ORIGIN, entity.getLocation()).put(LootContextParams.LOOTER, looter).put(LootContextParams.LOOTED_ENTITY, entity).put(LootContextParams.EXPLOSION_TYPE, LootUtils.getDeathExplosionType(entity)).put(LootContextParams.HAS_EXISTING_ITEMS, !drops.getDrops().isEmpty()).build();
LootResult lootResult = this.lootTableManager.getLoot(LootTableTypes.ENTITY, lootContext);
LootContents lootContents = lootResult.getLootContents();
// Overwrite existing drops if applicable
if (lootResult.shouldOverwriteItems())
drops.getDrops().clear();
if (lootResult.shouldOverwriteExperience())
drops.setExperience(0);
// Add items to drops and adjust experience
drops.getDrops().addAll(lootContents.getItems());
drops.setExperience(drops.getExperience() + lootContents.getExperience());
extras.add(lootContents);
}
Runnable task = () -> extras.forEach(x -> x.triggerExtras(mainEntity.getLocation()));
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(this.rosePlugin, task);
} else {
task.run();
}
}
use of dev.rosewood.roseloot.loot.LootContents in project RoseLoot by Rosewood-Development.
the class EntityListener method onEntityDeath.
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
LivingEntity entity = event.getEntity();
if (Setting.DISABLED_WORLDS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(entity.getWorld().getName())))
return;
// Handle RoseStacker entity stack deaths in a different listener
if (RoseStackerHook.useCustomEntityDeathHandling() && RoseStackerHook.isEntireEntityStackDying(entity))
return;
Entity looter = null;
if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent)
looter = ((EntityDamageByEntityEvent) entity.getLastDamageCause()).getDamager();
LootContext lootContext = LootContext.builder(LootUtils.getEntityLuck(looter)).put(LootContextParams.ORIGIN, entity.getLocation()).put(LootContextParams.LOOTER, looter).put(LootContextParams.LOOTED_ENTITY, entity).put(LootContextParams.EXPLOSION_TYPE, LootUtils.getDeathExplosionType(entity)).put(LootContextParams.HAS_EXISTING_ITEMS, !event.getDrops().isEmpty()).build();
LootResult lootResult = this.lootTableManager.getLoot(LootTableTypes.ENTITY, lootContext);
LootContents lootContents = lootResult.getLootContents();
// Overwrite existing drops if applicable
if (lootResult.shouldOverwriteItems())
event.getDrops().clear();
if (lootResult.shouldOverwriteExperience())
event.setDroppedExp(0);
// Add items to drops and adjust experience
event.getDrops().addAll(lootContents.getItems());
event.setDroppedExp(event.getDroppedExp() + lootContents.getExperience());
lootContents.triggerExtras(entity.getLocation());
}
use of dev.rosewood.roseloot.loot.LootContents in project RoseLoot by Rosewood-Development.
the class EntityListener method onEntityDropItem.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityDropItem(EntityDropItemEvent event) {
if (!(event.getEntity() instanceof LivingEntity))
return;
LivingEntity entity = (LivingEntity) event.getEntity();
if (Setting.DISABLED_WORLDS.getStringList().stream().anyMatch(x -> x.equalsIgnoreCase(entity.getWorld().getName())))
return;
Player shearer;
switch(entity.getType()) {
case SHEEP:
case SNOWMAN:
case MUSHROOM_COW:
shearer = this.lastShearer.get();
break;
default:
shearer = null;
break;
}
LootContext lootContext = LootContext.builder(LootUtils.getEntityLuck(shearer)).put(LootContextParams.ORIGIN, entity.getLocation()).put(LootContextParams.LOOTER, shearer).put(LootContextParams.LOOTED_ENTITY, entity).put(LootContextParams.INPUT_ITEM, event.getItemDrop().getItemStack()).put(LootContextParams.HAS_EXISTING_ITEMS, true).build();
LootResult lootResult = this.lootTableManager.getLoot(LootTableTypes.ENTITY_DROP_ITEM, lootContext);
LootContents lootContents = lootResult.getLootContents();
Location dropLocation = event.getItemDrop().getLocation();
// Overwrite existing drops if applicable
if (lootResult.shouldOverwriteItems())
event.setCancelled(true);
// Add items to drops and spawn experience
lootContents.getItems().forEach(x -> entity.getWorld().dropItemNaturally(dropLocation, x));
int experience = lootContents.getExperience();
if (experience > 0)
entity.getWorld().spawn(entity.getLocation(), ExperienceOrb.class, x -> x.setExperience(experience));
lootContents.triggerExtras(dropLocation);
}
Aggregations