use of org.bukkit.projectiles.ProjectileSource in project MassiveCore by MassiveCraft.
the class LiabilityCalculatorAreaEffectCloud method liability.
// -------------------------------------------- //
// LIABILITY CALCULATION
// -------------------------------------------- //
public static Entity liability(EntityDamageByEntityEvent event) {
Entity liable = event.getDamager();
if (!(liable instanceof AreaEffectCloud))
return null;
AreaEffectCloud cloud = (AreaEffectCloud) liable;
ProjectileSource source = cloud.getSource();
return source instanceof Entity ? (Entity) source : null;
}
use of org.bukkit.projectiles.ProjectileSource in project Prism-Bukkit by prism.
the class PaperListeners method onTargetHitEvent.
/**
* React to a target hit event.
* @param event the TargetHitEvent.
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onTargetHitEvent(TargetHitEvent event) {
Projectile projectile = event.getEntity();
ProjectileSource shooter = projectile.getShooter();
if (shooter instanceof Player) {
if (!Prism.getIgnore().event("target-hit", (Player) shooter)) {
return;
}
Block block = event.getHitBlock();
RecordingQueue.addToQueue(ActionFactory.createBlock("target-hit", block, (Player) shooter));
}
}
use of org.bukkit.projectiles.ProjectileSource in project Prism-Bukkit by prism.
the class PrismEntityEvents method onEntityDeath.
/**
* EntityDeathEvent.
* @param event EntityDeathEvent
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDeath(final EntityDeathEvent event) {
final LivingEntity entity = event.getEntity();
// Mob Death
if (!(entity instanceof Player)) {
// Log item drops
if (Prism.getIgnore().event("item-drop", entity.getWorld())) {
String name = entity.getType().name().toLowerCase();
// Inventory
if (entity instanceof InventoryHolder) {
final InventoryHolder holder = (InventoryHolder) entity;
for (final ItemStack i : holder.getInventory().getContents()) {
if (checkNotNullorAir(i)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-drop", i, i.getAmount(), -1, null, entity.getLocation(), name));
}
}
}
// Equipment
EntityEquipment equipment = entity.getEquipment();
if (equipment != null) {
for (final ItemStack i : equipment.getArmorContents()) {
if (checkNotNullorAir(i)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-drop", i, i.getAmount(), -1, null, entity.getLocation(), name));
}
}
}
// Hand items not stored in "getArmorContents"
ItemStack main = entity.getEquipment().getItemInMainHand();
ItemStack off = entity.getEquipment().getItemInOffHand();
if (checkNotNullorAir(main)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-drop", main, main.getAmount(), -1, null, entity.getLocation(), name));
}
if (checkNotNullorAir(off)) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-drop", off, off.getAmount(), -1, null, entity.getLocation(), name));
}
}
EntityDamageEvent damageEvent = entity.getLastDamageCause();
Entity entitySource = null;
Block blockSource = null;
// Resolve source
if (damageEvent != null && !damageEvent.isCancelled()) {
if (damageEvent instanceof EntityDamageByEntityEvent) {
entitySource = ((EntityDamageByEntityEvent) damageEvent).getDamager();
if (entitySource instanceof Projectile) {
ProjectileSource ps = ((Projectile) entitySource).getShooter();
if (ps instanceof BlockProjectileSource) {
entitySource = null;
blockSource = ((BlockProjectileSource) ps).getBlock();
} else {
entitySource = (Entity) ps;
}
}
} else if (damageEvent instanceof EntityDamageByBlockEvent) {
blockSource = ((EntityDamageByBlockEvent) damageEvent).getDamager();
}
}
// Create handlers
if (entitySource instanceof Player) {
Player player = (Player) entitySource;
if (!Prism.getIgnore().event("player-kill", player)) {
return;
}
RecordingQueue.addToQueue(ActionFactory.createEntity("player-kill", entity, player));
} else if (entitySource != null) {
if (!Prism.getIgnore().event("entity-kill", entity.getWorld())) {
return;
}
String name = entitySource.getType().name().toLowerCase(Locale.ENGLISH).replace('_', ' ');
RecordingQueue.addToQueue(ActionFactory.createEntity("entity-kill", entity, name));
} else if (blockSource != null) {
if (!Prism.getIgnore().event("entity-kill", entity.getWorld())) {
return;
}
String name = "block:" + blockSource.getType().name().toLowerCase(Locale.ENGLISH).replace('_', ' ');
RecordingQueue.addToQueue(ActionFactory.createEntity("entity-kill", entity, name));
} else {
if (!Prism.getIgnore().event("entity-kill", entity.getWorld())) {
return;
}
String name = "unknown";
if (damageEvent != null && !damageEvent.isCancelled()) {
name = damageEvent.getCause().name().toLowerCase(Locale.ENGLISH).replace('_', ' ');
}
RecordingQueue.addToQueue(ActionFactory.createEntity("entity-kill", entity, name));
}
/*
* if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) { final
* EntityDamageByEntityEvent entityDamageByEntityEvent =
* (EntityDamageByEntityEvent) entity .getLastDamageCause();
*
* // Mob killed by player if (entityDamageByEntityEvent.getDamager() instanceof
* Player) { final Player player = (Player)
* entityDamageByEntityEvent.getDamager(); if
* (!Prism.getIgnore().event("player-kill", player)) return;
* RecordingQueue.addToQueue(ActionFactory.createEntity("player-kill", entity,
* player));
*
* } // Mob shot by an arrow from a player else if
* (entityDamageByEntityEvent.getDamager() instanceof Arrow) { final Arrow arrow
* = (Arrow) entityDamageByEntityEvent.getDamager();
*
* if (arrow.getShooter() instanceof Player) { final Player player = (Player)
* arrow.getShooter(); if (!Prism.getIgnore().event("player-kill", player))
* return; RecordingQueue.addToQueue(ActionFactory.createEntity("player-kill",
* entity, player));
*
* } else if (arrow.getShooter() instanceof LivingEntity) { final Entity damager
* = (Entity) arrow.getShooter(); String name = "unknown"; if (damager != null)
* { name = damager.getType().name().toLowerCase(); }
*
* if (!Prism.getIgnore().event("entity-kill", entity.getWorld())) return;
* RecordingQueue.addToQueue(ActionFactory.createEntity("entity-kill", entity,
* name)); } else if (arrow.getShooter() instanceof BlockProjectileSource) {
*
* final Block damager = (Block)
* ((BlockProjectileSource)arrow.getShooter()).getBlock();
*
* if (!Prism.getIgnore().event("entity-kill", entity.getWorld())) return;
*
* String name = "block:" + damager.getType().name().toLowerCase();
*
* RecordingQueue.addToQueue(ActionFactory.createEntity("entity-kill", entity,
* name)); } } else { // Mob died by another mob final Entity damager =
* entityDamageByEntityEvent.getDamager(); String name = "unknown"; if (damager
* != null) { name = damager.getType().name().toLowerCase(); }
*
* if (!Prism.getIgnore().event("entity-kill", entity.getWorld())) return;
* RecordingQueue.addToQueue(ActionFactory.createEntity("entity-kill", entity,
* name)); } } else {
*
* if (!Prism.getIgnore().event("entity-kill", entity.getWorld())) return;
*
* String killer = "unknown"; final EntityDamageEvent damage =
* entity.getLastDamageCause(); if (damage != null) { final DamageCause cause =
* damage.getCause(); if (cause != null) { killer = cause.name().toLowerCase();
* } }
*
* // Record the death as natural
* RecordingQueue.addToQueue(ActionFactory.createEntity("entity-kill", entity,
* killer));
*
* }
*/
} else {
// Determine who died and what the exact cause was
final Player p = (Player) event.getEntity();
if (Prism.getIgnore().event("player-death", p)) {
final String cause = DeathUtils.getCauseNiceName(p);
String attacker = DeathUtils.getAttackerName(p);
if (attacker.equals("pvpwolf")) {
final String owner = DeathUtils.getTameWolfOwner(event);
attacker = owner + "'s wolf";
}
RecordingQueue.addToQueue(ActionFactory.createPlayerDeath("player-death", p, cause, attacker));
}
// Log item drops
if (Prism.getIgnore().event("item-drop", p)) {
if (!event.getDrops().isEmpty()) {
for (final ItemStack i : event.getDrops()) {
RecordingQueue.addToQueue(ActionFactory.createItemStack("item-drop", i, i.getAmount(), -1, null, p.getLocation(), p));
}
}
}
}
}
use of org.bukkit.projectiles.ProjectileSource in project AuthMeReloaded by AuthMe.
the class EntityListenerTest method shouldAllowProjectileLaunchFromNonHuman.
@Test
public void shouldAllowProjectileLaunchFromNonHuman() {
// given
Projectile projectile = mock(Projectile.class);
ProjectileSource source = mock(ProjectileSource.class);
given(projectile.getShooter()).willReturn(source);
ProjectileLaunchEvent event = mock(ProjectileLaunchEvent.class);
given(event.getEntity()).willReturn(projectile);
// when
listener.onProjectileLaunch(event);
// then
verifyNoInteractions(listenerService);
verify(event, never()).setCancelled(anyBoolean());
}
use of org.bukkit.projectiles.ProjectileSource in project Denizen-For-Bukkit by DenizenScript.
the class EntityAreaEffectCloud method getObjectAttribute.
@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("base_potion")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(getHelper().getBPName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_upgraded")) {
return new ElementTag(getHelper().getBPUpgraded()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_extended")) {
return new ElementTag(getHelper().getBPExtended()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getBPName() + "," + getHelper().getBPUpgraded() + "," + getHelper().getBPExtended()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("particle")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("color")) {
return new ColorTag(getHelper().getColor()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getParticle()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("duration")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new DurationTag(getHelper().getDurationOnUse()).getObjectAttribute(attribute.fulfill(1));
}
return new DurationTag(getHelper().getDuration()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("radius")) {
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("on_use")) {
return new ElementTag(getHelper().getRadiusOnUse()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("per_tick")) {
return new ElementTag(getHelper().getRadiusPerTick()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().getRadius()).getObjectAttribute(attribute);
}
// -->
if (attribute.startsWith("reapplication_delay")) {
return new DurationTag(getHelper().getReappDelay()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("wait_time")) {
return new DurationTag(getHelper().getWaitTime()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_custom_effect")) {
if (attribute.hasParam()) {
PotionEffectType effectType = PotionEffectType.getByName(attribute.getParam());
for (PotionEffect effect : getHelper().getCustomEffects()) {
if (effect.getType().equals(effectType)) {
return new ElementTag(true).getObjectAttribute(attribute.fulfill(1));
}
}
return new ElementTag(false).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(getHelper().hasCustomEffects()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("source")) {
ProjectileSource shooter = getHelper().getSource();
if (shooter instanceof LivingEntity) {
return new EntityTag((LivingEntity) shooter).getObjectAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("custom_effects")) {
List<PotionEffect> effects = getHelper().getCustomEffects();
if (!attribute.hasParam()) {
ListTag list = new ListTag();
for (PotionEffect effect : effects) {
list.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles());
}
return list.getObjectAttribute(attribute.fulfill(1));
}
int val = attribute.getIntParam() - 1;
if (val < 0 || val >= effects.size()) {
return null;
}
attribute = attribute.fulfill(1);
PotionEffect effect = effects.get(val);
// -->
if (attribute.startsWith("type")) {
return new ElementTag(effect.getType().getName()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("amplifier")) {
return new ElementTag(effect.getAmplifier()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("duration")) {
return new DurationTag((long) effect.getDuration()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_particles")) {
return new ElementTag(effect.hasParticles()).getObjectAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_ambient")) {
return new ElementTag(effect.isAmbient()).getObjectAttribute(attribute.fulfill(1));
}
return new ElementTag(effect.getType().getName() + "," + effect.getAmplifier() + "," + new DurationTag((long) effect.getDuration()).identify() + "," + effect.isAmbient() + "," + effect.hasParticles()).getObjectAttribute(attribute);
}
return null;
}
Aggregations