use of org.spongepowered.api.entity.living.monster.Wither in project Skree by Skelril.
the class WildernessWorldWrapper method onEntityDeath.
@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
Entity entity = event.getTargetEntity();
Location<World> loc = entity.getLocation();
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
return;
}
int level = optLevel.get();
if (entity instanceof Monster) {
DropTable dropTable;
if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
dropTable = netherMobDropTable;
} else {
dropTable = commonDropTable;
}
Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
if (optDamageSource.isPresent()) {
Entity srcEntity;
if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
} else {
srcEntity = optDamageSource.get().getSource();
}
int dropTier = level;
if (srcEntity instanceof Player) {
Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
if (optHeldItem.isPresent()) {
Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
if (optLooting.isPresent()) {
dropTier += optLooting.get().getLevel();
}
}
dropTier = getDropTier(dropTier);
Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
int times = 1;
Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
if (optService.isPresent()) {
ModifierService service = optService.get();
if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
times *= 2;
}
}
ItemDropper dropper = new ItemDropper(loc);
for (int i = 0; i < times; ++i) {
dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
}
Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
optHighScores.ifPresent(highScoreService -> highScoreService.update((Player) srcEntity, ScoreTypes.WILDERNESS_MOB_KILLS, 1));
}
}
if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
}
}
if (entity instanceof Player) {
Player player = (Player) entity;
GRAVE_STONE.createGraveFromDeath(player);
Optional<HighScoreService> optHighScores = Sponge.getServiceManager().provide(HighScoreService.class);
optHighScores.ifPresent(highScoreService -> highScoreService.update(player, ScoreTypes.WILDERNESS_DEATHS, 1));
}
}
use of org.spongepowered.api.entity.living.monster.Wither in project RedProtect by FabioZumbi12.
the class RPEntityListener method onCreatureSpawn.
@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
for (Entity e : event.getEntities()) {
if (e == null || e.getType() == null) {
continue;
}
if (!(e instanceof Living)) {
continue;
}
Optional<SpawnTypes> cause = event.getCause().first(SpawnTypes.class);
RedProtect.get().logger.debug("entity", "SpawnCause: " + (cause.map(Object::toString).orElse(" null")));
if (e instanceof Wither && cause.isPresent() && cause.get().equals(SpawnTypes.PLACEMENT)) {
Region r = RedProtect.get().rm.getTopRegion(e.getLocation());
if (r != null && !r.canSpawnWhiter()) {
event.isCancelled();
return;
}
}
if (e instanceof Monster) {
Location<World> l = e.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canSpawnMonsters()) {
RedProtect.get().logger.debug("entity", "Cancelled spawn of monster " + e.getType().getName());
event.setCancelled(true);
return;
}
}
if (e instanceof Animal || e instanceof Golem || e instanceof Ambient || e instanceof Aquatic) {
Location<World> l = e.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canSpawnPassives()) {
RedProtect.get().logger.debug("entity", "Cancelled spawn of animal " + e.getType().getName());
event.setCancelled(true);
return;
}
}
RedProtect.get().logger.debug("entity", "RPEntityListener - Spawn mob " + e.getType().getName());
}
}
use of org.spongepowered.api.entity.living.monster.Wither in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onCreatureSpawn.
@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
for (Entity e : event.getEntities()) {
if (e == null || RedProtect.get().rm.getTopRegion(e.getLocation()) != null) {
continue;
}
if (e instanceof Wither && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-wither")) {
RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Wither " + e.getType().getName());
event.setCancelled(true);
return;
}
if (e instanceof Monster && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-monsters")) {
RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Monster " + e.getType().getName());
event.setCancelled(true);
return;
}
if ((e instanceof Animal || e instanceof Villager || e instanceof Ambient || e instanceof Golem) && !RedProtect.get().cfgs.getGlobalFlag(e.getWorld().getName(), "spawn-passives")) {
RedProtect.get().logger.debug("spawn", "RPGlobalListener - Cancelled spawn of Animal " + e.getType().getName());
event.setCancelled(true);
return;
}
RedProtect.get().logger.debug("spawn", "RPGlobalListener - Spawn mob " + e.getType().getName());
}
}
Aggregations