use of org.spongepowered.api.event.Listener in project Skree by Skelril.
the class RangedSpecialAttackClusterListener method onPlayerCombat.
@Listener(order = Order.LATE)
public void onPlayerCombat(DamageEntityEvent event) {
Entity targetEntity = event.getTargetEntity();
if (!(targetEntity instanceof Living)) {
return;
}
Optional<Clause<Living, ItemStackSnapshot>> optSourceEntity = getSource(event.getCause());
if (!optSourceEntity.isPresent()) {
return;
}
Living sourceEntity = optSourceEntity.get().getKey();
ItemStackSnapshot snapshot = optSourceEntity.get().getValue();
if (!applicabilityTest.test(sourceEntity, snapshot)) {
return;
}
if (cooldownHandler.canUseAbility(sourceEntity)) {
cooldownHandler.useAbility(sourceEntity);
} else {
return;
}
rangedCluster.getNextAttackToRun().run(sourceEntity, (Living) targetEntity, event);
}
use of org.spongepowered.api.event.Listener in project Skree by Skelril.
the class PointOfContactClusterListener method onBlockCollide.
@Listener
public void onBlockCollide(CollideEvent.Impact event, @First Projectile projectile) {
ProjectileSource source = projectile.getShooter();
if (!(source instanceof Living)) {
return;
}
Living sourceEntity = (Living) source;
ItemStackSnapshot shootingItemStack = projectile.get(SHOOTING_ITEM_DATA_KEY).map(Optional::get).orElse(null);
if (!applicabilityTest.test(sourceEntity, shootingItemStack)) {
return;
}
if (cooldownHandler.canUseAbility(sourceEntity)) {
cooldownHandler.useAbility(sourceEntity);
} else {
return;
}
attackCluster.getNextAbilityToRun().run(sourceEntity, event.getImpactPoint());
}
use of org.spongepowered.api.event.Listener 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.event.Listener in project Skree by Skelril.
the class WildernessWorldWrapper method onEntitySpawn.
@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
List<Entity> entities = event.getEntities();
Optional<BlockSpawnCause> optBlockCause = event.getCause().first(BlockSpawnCause.class);
for (Entity entity : entities) {
Location<World> loc = entity.getLocation();
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
continue;
}
int level = optLevel.get();
if (entity instanceof Egg && optBlockCause.isPresent()) {
PrimedTNT explosive = (PrimedTNT) entity.getLocation().getExtent().createEntity(EntityTypes.PRIMED_TNT, entity.getLocation().getPosition());
explosive.setVelocity(entity.getVelocity());
explosive.offer(Keys.FUSE_DURATION, 20 * 4);
// TODO used to have a 1/4 chance of creating fire
entity.getLocation().getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.DISPENSE).build()).build());
event.setCancelled(true);
return;
}
if (level > 1) {
// TODO move damage modification
if (entity instanceof Monster) {
HealthData healthData = ((Monster) entity).getHealthData();
double curMax = healthData.maxHealth().get();
if (curMax <= 80) {
// TODO do this a better way, but for now it prevents super mobs
double newMax = curMax * getHealthMod(level);
healthData.set(Keys.MAX_HEALTH, newMax);
healthData.set(Keys.HEALTH, newMax);
entity.offer(healthData);
}
// Wandering Bosses
Collection<String> wanderers = wanderingMobManager.getSupportedWanderersOfType(entity.getType());
for (String wanderer : wanderers) {
if (wanderingMobManager.chanceBind(wanderer, level, entity)) {
break;
}
}
}
}
Optional<Value<Integer>> optExplosiveRadius = Optional.empty();
if (optExplosiveRadius.isPresent()) {
Value<Integer> explosiveRadius = optExplosiveRadius.get();
int min = explosiveRadius.get();
entity.offer(Keys.EXPLOSION_RADIUS, Optional.of(MathExt.bound((min + level) / 2, min, entity instanceof Fireball ? 4 : 9)));
}
}
}
use of org.spongepowered.api.event.Listener in project Skree by Skelril.
the class ZoneInventoryProtector method onPlayerDeath.
@Listener
public void onPlayerDeath(DestructEntityEvent.Death event, @Getter("getTargetEntity") Player player) {
if (!isApplicable(player)) {
return;
}
PlayerStateService service = Sponge.getServiceManager().provideUnchecked(PlayerStateService.class);
try {
service.storeInventory(player);
service.releaseInventory(player);
player.getInventory().clear();
} catch (InventoryStorageStateException e) {
e.printStackTrace();
}
}
Aggregations