use of org.spongepowered.api.entity.projectile.Projectile in project Skree by Skelril.
the class ProjectileWatcherServiceImpl method onProjectileLaunch.
@Listener
public void onProjectileLaunch(SpawnEntityEvent event) {
for (Entity entity : event.getEntities()) {
if (!(entity instanceof Projectile)) {
continue;
}
ProjectileSource shooter = ((Projectile) entity).getShooter();
if (shooter instanceof ArmorEquipable) {
entity.offer(new ShootingItemData((((ArmorEquipable) shooter).getItemInHand(HandTypes.MAIN_HAND).map(ItemStack::createSnapshot).orElse(null))));
}
track((Projectile) entity, event.getCause());
}
}
use of org.spongepowered.api.entity.projectile.Projectile in project Skree by Skelril.
the class ArrowFishingHandler method onProjectileTickEvent.
@Listener
public void onProjectileTickEvent(ProjectileTickEvent event) {
Projectile projectile = event.getTargetEntity();
if (!(projectile instanceof Arrow) || Probability.getChance(3)) {
return;
}
Location<World> loc = projectile.getLocation();
if (MultiTypeRegistry.isWater(loc.getBlockType()) && checkVelocity(projectile.getVelocity())) {
ProjectileSource source = projectile.getShooter();
double modifier = 1;
if (source instanceof Living) {
modifier = 50;
}
Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
int rolls = 1;
if (optService.isPresent() && optService.get().isActive(UBER_ARROW_FISHING)) {
if (source instanceof Living) {
rolls = 15;
} else {
rolls = 5;
}
}
new ItemDropper(loc).dropStacks(dropTable.getDrops(rolls, modifier));
}
}
use of org.spongepowered.api.entity.projectile.Projectile in project RedProtect by FabioZumbi12.
the class EntityListener method onEntityDamage.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamage(DamageEntityEvent e) {
// victim
Entity e1 = e.getTargetEntity();
RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - DamageEntityEvent entity target " + e1.getType().getName());
Region r = RedProtect.get().getRegionManager().getTopRegion(e1.getLocation(), this.getClass().getName());
if (e1 instanceof Living && !(e1 instanceof Monster)) {
if (r != null && r.flagExists("invincible")) {
if (r.getFlagBool("invincible")) {
e.setCancelled(true);
}
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (r != null && r.flagExists("invincible")) {
if (r.getFlagBool("invincible")) {
if (e1 instanceof Animal) {
((Animal) e1).setTarget(null);
}
e.setCancelled(true);
}
}
}
// damager
if (!e.getCause().first(Living.class).isPresent()) {
return;
}
Entity e2 = e.getCause().first(Living.class).get();
RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - DamageEntityEvent damager " + e2.getType().getName());
if (e2 instanceof Projectile) {
Projectile a = (Projectile) e2;
if (a.getShooter() instanceof Entity) {
e2 = (Entity) a.getShooter();
}
}
Region r1 = RedProtect.get().getRegionManager().getTopRegion(e1.getLocation(), this.getClass().getName());
Region r2 = RedProtect.get().getRegionManager().getTopRegion(e2.getLocation(), this.getClass().getName());
if (e.getCause().containsType(Lightning.class) || e.getCause().containsType(Explosive.class) || e.getCause().containsType(Fireball.class) || e.getCause().containsType(Explosion.class)) {
if (r1 != null && !r1.canFire() && !(e2 instanceof Player)) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Player) {
if (e2 instanceof Player) {
Player p2 = (Player) e2;
if (r1 != null) {
ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p2);
if (itemInHand.getType().equals(ItemTypes.EGG) && !r1.canProtectiles(p2)) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
return;
}
if (r2 != null) {
if (itemInHand.getType().equals(ItemTypes.EGG) && !r2.canProtectiles(p2)) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
return;
}
if ((r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) || (r1.flagExists("pvp") && !r2.canPVP((Player) e1, p2))) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "entitylistener.region.cantpvp");
}
} else if (r1.flagExists("pvp") && !r1.canPVP((Player) e1, p2)) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "entitylistener.region.cantpvp");
}
} else if (r2 != null && r2.flagExists("pvp") && !r2.canPVP((Player) e1, p2)) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "entitylistener.region.cantpvp");
}
}
} else if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e instanceof Ambient) {
if (r1 != null && e2 instanceof Player) {
Player p2 = (Player) e2;
if (!r1.canInteractPassives(p2)) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "entitylistener.region.cantpassive");
}
}
} else if ((e1 instanceof Hanging) && e2 instanceof Player) {
Player p2 = (Player) e2;
if (r1 != null && !r1.canBuild(p2)) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
return;
}
if (r2 != null && !r2.canBuild(p2)) {
e.setCancelled(true);
RedProtect.get().getLanguageManager().sendMessage(p2, "playerlistener.region.cantuse");
}
} else if ((e1 instanceof Hanging) && e2 instanceof Monster) {
if (r1 != null || r2 != null) {
RedProtect.get().logger.debug(LogLevel.ENTITY, "Cancelled ItemFrame drop Item");
e.setCancelled(true);
}
} else if (e1 instanceof Explosive && !(e1 instanceof Living)) {
if ((r1 != null && !r1.canFire()) || (r2 != null && !r2.canFire())) {
e.setCancelled(true);
}
}
}
use of org.spongepowered.api.entity.projectile.Projectile in project RedProtect by FabioZumbi12.
the class PlayerListener method onEntityDamageEvent.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEvent(DamageEntityEvent e) {
// victim
Entity e1 = e.getTargetEntity();
// damager
Entity e2 = null;
if (e.getCause().first(IndirectEntityDamageSource.class).isPresent()) {
e2 = e.getCause().first(IndirectEntityDamageSource.class).get().getSource();
RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is DamageEntityEvent event. Damager " + e2.getType().getName());
}
Player damager = null;
if (e2 instanceof Projectile) {
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Player) {
damager = (Player) proj.getShooter();
}
} else if (e2 instanceof Player) {
damager = (Player) e2;
}
Location<World> l = e1.getLocation();
Region r = RedProtect.get().getRegionManager().getTopRegion(l, this.getClass().getName());
if (r == null) {
return;
}
RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is DamageEntityEvent event. Victim " + e1.getType().getName());
if (damager != null) {
if (e1 instanceof Hanging && !r.canBuild(damager)) {
RedProtect.get().getLanguageManager().sendMessage(damager, "entitylistener.region.cantinteract");
e.setCancelled(true);
return;
}
if ((e1 instanceof Boat || e1 instanceof Minecart) && !r.canMinecart(damager)) {
RedProtect.get().getLanguageManager().sendMessage(damager, "entitylistener.region.cantbreak");
e.setCancelled(true);
return;
}
if (e1 instanceof Player && !e1.equals(damager) && r.flagExists("pvp") && !r.canPVP(damager, (Player) e1)) {
RedProtect.get().getLanguageManager().sendMessage(damager, "entitylistener.region.cantpvp");
e.setCancelled(true);
return;
}
}
// return if not player
if (!(e1 instanceof Player)) {
return;
}
Player play = (Player) e.getTargetEntity();
if (RedProtect.get().tpWait.contains(play.getName())) {
RedProtect.get().tpWait.remove(play.getName());
RedProtect.get().getLanguageManager().sendMessage(play, RedProtect.get().getLanguageManager().get("cmdmanager.region.tpcancelled"));
}
if (!r.canPlayerDamage()) {
e.setCancelled(true);
}
// execute on health
if (r.cmdOnHealth(play)) {
RedProtect.get().logger.debug(LogLevel.PLAYER, "Cmd on healt: true");
}
if (!r.canDeath() && play.get(Keys.HEALTH).get() <= 1) {
e.setCancelled(true);
}
// deny damagecauses
List<String> Causes = RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(play.getWorld().getName()).deny_death_by;
if (Causes.size() > 0) {
DamageType damagec = null;
if (e.getCause().containsType(EntityDamageSource.class)) {
damagec = e.getCause().first(EntityDamageSource.class).get().getType();
}
if (e.getCause().containsType(DamageSource.class)) {
damagec = e.getCause().first(DamageSource.class).get().getType();
}
if (e.getCause().containsType(BlockDamageSource.class)) {
damagec = e.getCause().first(BlockDamageSource.class).get().getType();
}
if (damagec != null && Causes.contains(damagec.getName())) {
e.setCancelled(true);
}
}
}
use of org.spongepowered.api.entity.projectile.Projectile in project RedProtect by FabioZumbi12.
the class GlobalListener method onEntityDamageEntity.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDamageEntity(DamageEntityEvent e) {
Entity e1 = e.getTargetEntity();
Entity e2;
RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener: DamageEntityEvent - e1: " + e1.getType().getName());
if (e1 instanceof Living && !(e1 instanceof Monster)) {
Region r = RedProtect.get().getRegionManager().getTopRegion(e1.getLocation(), this.getClass().getName());
if (r == null && RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).invincible) {
e.setCancelled(true);
}
}
if (e.getCause().first(Living.class).isPresent()) {
e2 = e.getCause().first(Living.class).get();
RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener: DamageEntityEvent - Is DamageEntityEvent event. Damager " + e2.getType().getName());
} else {
return;
}
RedProtect.get().logger.debug(LogLevel.ENTITY, "GlobalListener: DamageEntityEvent - e1: " + e1.getType().getName() + " - e2: " + e2.getType().getName());
Location<World> loc = e1.getLocation();
if (e2 instanceof Projectile) {
Region r1 = RedProtect.get().getRegionManager().getTopRegion(loc, this.getClass().getName());
if (r1 != null) {
return;
}
Projectile proj = (Projectile) e2;
if (proj.getShooter() instanceof Entity) {
e2 = (Entity) proj.getShooter();
}
if (!(e2 instanceof Player)) {
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).entity_block_damage) {
e.setCancelled(true);
return;
}
}
}
}
if (e2 instanceof Creeper || e2 instanceof PrimedTNT || e2 instanceof TNTMinecart) {
Region r1 = RedProtect.get().getRegionManager().getTopRegion(loc, this.getClass().getName());
if (r1 != null) {
return;
}
if (e1 instanceof Player) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).explosion_entity_damage) {
e.setCancelled(true);
return;
}
}
}
if (e2 instanceof Player) {
Region r1 = RedProtect.get().getRegionManager().getTopRegion(loc, this.getClass().getName());
if (r1 != null) {
return;
}
Player p = (Player) e2;
if (e1 instanceof Player) {
if (!e1.equals(e2) && !RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).pvp && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Animal || e1 instanceof Villager || e1 instanceof Golem || e1 instanceof Ambient) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).player_hurt_passives && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Monster) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).player_hurt_monsters && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Boat || e1 instanceof Minecart) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).use_minecart && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
return;
}
}
if (e1 instanceof Hanging || e1 instanceof ArmorStand) {
if (!RedProtect.get().getConfigManager().globalFlagsRoot().worlds.get(e1.getWorld().getName()).entity_block_damage && !p.hasPermission("redprotect.world.bypass")) {
e.setCancelled(true);
}
}
}
}
Aggregations