org.bukkit.projectiles.ProjectileSource Java Examples

The following examples show how to use org.bukkit.projectiles.ProjectileSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: ProjectileTracker.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
void handleLaunch(Entity projectile, ProjectileSource source) {
  PhysicalInfo projectileInfo = entities().resolveEntity(projectile);
  if (!(projectileInfo instanceof ProjectileInfo)
      || (((ProjectileInfo) projectileInfo).getShooter() == null && source != null)) {
    ProjectileDefinition definition = ProjectileMatchModule.getProjectileDefinition(projectile);
    String customName = definition == null ? null : definition.getName();
    entities()
        .trackEntity(
            projectile,
            new ProjectileInfo(
                projectileInfo,
                tmm.resolveShooter(source),
                projectile.getLocation(),
                customName));
  }
}
 
Example #3
Source File: SentinelEventHandler.java    From Sentinel with MIT License 6 votes vote down vote up
@EventHandler
public void onEntityExplodes(EntityExplodeEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!SentinelPlugin.instance.preventExplosionBlockDamage) {
        return;
    }
    if (event.getEntity() instanceof Projectile) {
         ProjectileSource source = ((Projectile) event.getEntity()).getShooter();
         if (source instanceof Entity) {
             SentinelTrait sourceSentinel = SentinelUtilities.tryGetSentinel((Entity) source);
             if (sourceSentinel != null) {
                 event.blockList().clear();
             }
         }
    }
}
 
Example #4
Source File: FlagBowspleef.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onProjectileLaunchEvent(ProjectileLaunchEvent event) {
	Projectile projectile = event.getEntity();
	ProjectileSource source = projectile.getShooter();
	
	if (!(source instanceof Player)) {
		return;
	}
	
	SpleefPlayer shooter = getHeavySpleef().getSpleefPlayer(((Player) source));
	if (!game.isIngame(shooter)) {
		return;
	}
	
	ItemStack stack = shooter.getBukkitPlayer().getItemInHand();
	stack.setDurability((short)0);
	shooter.getBukkitPlayer().setItemInHand(stack);
}
 
Example #5
Source File: SentinelEventHandler.java    From Sentinel with MIT License 6 votes vote down vote up
@EventHandler
public void onBlockIgnites(BlockIgniteEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!SentinelPlugin.instance.preventExplosionBlockDamage) {
        return;
    }
    if (event.getIgnitingEntity() instanceof Projectile) {
        ProjectileSource source = ((Projectile) event.getIgnitingEntity()).getShooter();
        if (source instanceof Entity) {
            SentinelTrait sourceSentinel = SentinelUtilities.tryGetSentinel((Entity) source);
            if (sourceSentinel != null) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example #6
Source File: SentinelEventHandler.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Called when a projectile hits a block, to auto-remove Sentinel-fired arrows quickly.
 */
@EventHandler
public void onProjectileHitsBlock(ProjectileHitEvent event) {
    if (SentinelPlugin.instance.arrowCleanupTime <= 0) {
        return;
    }
    final Projectile projectile = event.getEntity();
    ProjectileSource source = projectile.getShooter();
    if (!(source instanceof Entity)) {
        return;
    }
    SentinelTrait sentinel = SentinelUtilities.tryGetSentinel((Entity) source);
    if (sentinel == null) {
        return;
    }
    Bukkit.getScheduler().scheduleSyncDelayedTask(SentinelPlugin.instance, new Runnable() {
        @Override
        public void run() {
            if (projectile.isValid()) {
                projectile.remove();
            }
        }
    }, SentinelPlugin.instance.arrowCleanupTime);
}
 
Example #7
Source File: ListenerMobCombat.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Entity linkProjectile(Entity original) {
    if(original == null) return null;
    
    FileConfiguration config = this.expansion.getPlugin().getConfig("config.yml");
    if(!config.getBoolean("link-projectiles")) return original;
    
    if(original instanceof Projectile) {
        Projectile projectile = (Projectile) original;
        ProjectileSource shooter = projectile.getShooter();
        if(shooter instanceof Entity) return (Entity) shooter;
    }
    
    return original;
}
 
Example #8
Source File: CraftArrow.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setShooter(ProjectileSource shooter) {
    if (shooter instanceof LivingEntity) {
        getHandle().shootingEntity = ((CraftLivingEntity) shooter).getHandle();
    } else {
        getHandle().shootingEntity = null;
    }
    getHandle().projectileSource = shooter;
}
 
Example #9
Source File: ListenerPVP.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Entity linkProjectile(Entity entity) {
    FileConfiguration config = this.expansion.getConfig("newbie-helper.yml");
    if(!config.getBoolean("pvp-checks.link-projectiles")) return entity;
    if(!(entity instanceof Projectile)) return entity;

    Projectile projectile = (Projectile) entity;
    ProjectileSource shooter = projectile.getShooter();
    return (shooter instanceof Entity ? (Entity) shooter : entity);
}
 
Example #10
Source File: ListenerNewbieProtection.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Entity linkProjectile(Entity entity) {
    FileConfiguration config = this.expansion.getConfig("newbie-helper.yml");
    if(!config.getBoolean("pvp-checks.link-projectiles")) return entity;
    if(!(entity instanceof Projectile)) return entity;

    Projectile projectile = (Projectile) entity;
    ProjectileSource shooter = projectile.getShooter();
    return (shooter instanceof Entity ? (Entity) shooter : entity);
}
 
Example #11
Source File: ListenerDamage.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private boolean checkDamageByEntity(EntityDamageEvent event) {
    if(!(event instanceof EntityDamageByEntityEvent)) return false;

    EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
    Entity damager = e.getDamager();
    if(damager instanceof LivingEntity) return true;

    if(damager instanceof Projectile) {
        Projectile projectile = (Projectile) damager;
        ProjectileSource shooter = projectile.getShooter();
        return (shooter instanceof LivingEntity);
    }

    return false;
}
 
Example #12
Source File: ListenerAttack.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private Entity linkProjectile(Entity original) {
    if(original == null) return null;

    FileConfiguration config = this.plugin.getConfig("config.yml");
    if(!config.getBoolean("link-projectiles")) return original;

    if(original instanceof Projectile) {
        Projectile projectile = (Projectile) original;
        ProjectileSource shooter = projectile.getShooter();
        if(shooter instanceof Entity) return (Entity) shooter;
    }

    return original;
}
 
Example #13
Source File: ExpCapListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler
public void onExpCapThrown(ProjectileLaunchEvent event) {
    if (!cfg.expcap_thron_enabled) return;
    if (event.getEntity() instanceof ThrownExpBottle) {
        ProjectileSource shooter = event.getEntity().getShooter();
        if (shooter instanceof Player) {
            event.getEntity().setMetadata("nu_expcap_exp",
                    new FixedMetadataValue(plugin,
                            thrownExpMap.computeIfAbsent(((Player) shooter).getUniqueId(), uuid -> 0)
                    )
            );
        }
    }
}
 
Example #14
Source File: Archer.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true)
public void damageListener(final EntityDamageByEntityEvent event)
{
	if(event.getDamager().getType() == EntityType.ARROW)
	{
		ProjectileSource s = ((Projectile)event.getDamager()).getShooter();
		if(s instanceof Player)
		{
			AnniPlayer shooter = AnniPlayer.getPlayer(((Player) s).getUniqueId());
			if(shooter != null && shooter.getKit() != null && shooter.getKit().equals(this))
				event.setDamage(event.getDamage()+1);
		}
	}
}
 
Example #15
Source File: SentinelEventHandler.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Called when combat occurs in the world (and has not yet been processed by other plugins),
 * to handle things like cancelling invalid damage to/from a Sentinel NPC,
 * changing damage values given to or received from an NPC,
 * and if relevant handling config options that require overriding damage events.
 */
@EventHandler(priority = EventPriority.LOW)
public void whenAttacksAreHappening(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    UUID victimUuid = event.getEntity().getUniqueId();
    for (SentinelTrait sentinel : cleanCurrentList()) {
        sentinel.whenSomethingMightDie(victimUuid);
    }
    SentinelTrait victim = SentinelUtilities.tryGetSentinel(event.getEntity());
    SentinelTrait attacker = SentinelUtilities.tryGetSentinel(event.getDamager());
    if (victim != null) {
        if (attacker != null && victim.getNPC().getId() == attacker.getNPC().getId()) {
            event.setCancelled(true);
            return;
        }
        victim.whenAttacksAreHappeningToMe(event);
    }
    if (attacker != null) {
        attacker.whenAttacksAreHappeningFromMe(event);
    }
    if (event.getDamager() instanceof Projectile) {
        ProjectileSource source = ((Projectile) event.getDamager()).getShooter();
        if (source instanceof Entity) {
            SentinelTrait shooter = SentinelUtilities.tryGetSentinel((Entity) source);
            if (shooter != null) {
                shooter.whenAttacksAreHappeningFromMyArrow(event);
            }
        }
    }
}
 
Example #16
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Runnable handleProjectileKill(long time, UUID victimUUID, Projectile projectile) {
    ProjectileSource source = projectile.getShooter();
    if (!(source instanceof Player)) {
        return null;
    }

    Player player = (Player) source;
    String projectileName = new EntityNameFormatter().apply(projectile.getType().name());

    return victimUUID != null
            ? new PlayerKillProcessor(player.getUniqueId(), time, victimUUID, projectileName)
            : new MobKillProcessor(player.getUniqueId());
}
 
Example #17
Source File: CraftFish.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public ProjectileSource getShooter() {
    if (getHandle().angler != null) {
        return getHandle().angler.getBukkitEntity();
    }

    return null;
}
 
Example #18
Source File: CraftProjectile.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setShooter(ProjectileSource shooter) {
    if (shooter instanceof CraftLivingEntity) {
        getHandle().thrower = (net.minecraft.entity.EntityLivingBase) ((CraftLivingEntity) shooter).entity;
        if (shooter instanceof CraftHumanEntity) {
            getHandle().throwerName = ((CraftHumanEntity) shooter).getName();
        }
    } else {
        getHandle().thrower = null;
        getHandle().throwerName = null;
    }
    getHandle().projectileSource = shooter;
}
 
Example #19
Source File: Pyro.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true)
public void arrowLaunch(final ProjectileLaunchEvent event)
{
	if(event.getEntityType() == EntityType.ARROW)
	{
		ProjectileSource shooter = event.getEntity().getShooter();
		if(shooter instanceof Player)
		{
			AnniPlayer p = AnniPlayer.getPlayer(((Player) shooter).getUniqueId());
			if(p != null && p.getKit().equals(this))
				event.getEntity().setFireTicks(999999);
		}
	}
}
 
Example #20
Source File: CraftFish.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public ProjectileSource getShooter() {
    if (getHandle().field_146042_b != null) {
        return getHandle().field_146042_b.getBukkitEntity();
    }

    return null;
}
 
Example #21
Source File: CraftFireball.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setShooter(ProjectileSource shooter) {
    if (shooter instanceof CraftLivingEntity) {
        getHandle().shootingEntity = ((CraftLivingEntity) shooter).getHandle();
    } else {
        getHandle().shootingEntity = null;
    }
    getHandle().projectileSource = shooter;
}
 
Example #22
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is PotionSplashEvent");

    ProjectileSource thrower = event.getPotion().getShooter();
    for (PotionEffect e : event.getPotion().getEffects()) {
        PotionEffectType t = e.getType();
        if (!t.equals(PotionEffectType.BLINDNESS) && !t.equals(PotionEffectType.CONFUSION) && !t.equals(PotionEffectType.HARM) && !t.equals(PotionEffectType.HUNGER) && !t.equals(PotionEffectType.POISON) && !t.equals(PotionEffectType.SLOW) && !t.equals(PotionEffectType.SLOW_DIGGING) && !t.equals(PotionEffectType.WEAKNESS) && !t.equals(PotionEffectType.WITHER)) {
            return;
        }
    }
    Player shooter;
    if (thrower instanceof Player) {
        shooter = (Player) thrower;
    } else {
        return;
    }
    for (Entity e2 : event.getAffectedEntities()) {
        Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
        if (event.getEntity() instanceof Player) {
            if (r != null && r.flagExists("pvp") && !r.canPVP((Player) event.getEntity(), shooter)) {
                event.setCancelled(true);
                return;
            }
        } else {
            if (r != null && !r.canInteractPassives(shooter)) {
                event.setCancelled(true);
                return;
            }
        }
    }
}
 
Example #23
Source File: GriefEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
    if ((!killAnimalsEnabled && !killMonstersEnabled)
            || !plugin.getWorldManager().isSkyAssociatedWorld(event.getDamager().getWorld())) {
        return;
    }
    if (!(event.getEntity() instanceof Creature)) {
        return;
    }
    if (event.getDamager() instanceof Player
            && !plugin.playerIsOnIsland((Player)event.getDamager())) {
        if (event.getDamager().hasPermission("usb.mod.bypassprotection")) {
            return;
        }
        cancelMobDamage(event);
    } else if (event.getDamager() instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
        if (!(shooter instanceof Player)) {
            return;
        }
        Player player = (Player) shooter;
        if (player.hasPermission("usb.mod.bypassprotection") || plugin.playerIsOnIsland(player)) {
            return;
        }
        cancelMobDamage(event);
    }
}
 
Example #24
Source File: GriefEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onWitherSkullExplosion(EntityDamageByEntityEvent e) {
    if (!witherEnabled
            || !(e.getEntity() instanceof WitherSkull)
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getEntity().getWorld())) {
        return;
    }
    // Find owner
    ProjectileSource shooter = ((WitherSkull) e.getEntity()).getShooter();
    if (shooter instanceof Wither) {
        handleWitherRampage(e, (Wither) shooter, e.getDamager().getLocation());
    }
}
 
Example #25
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void antiArrowSpam(ProjectileHitEvent event) {

    // Destroys the Arrows of the Minigun
    if (event.getEntityType().equals(EntityType.ARROW)) {
        Arrow arrow = (Arrow) event.getEntity();
        ProjectileSource shooter = arrow.getShooter();
        if (shooter instanceof Player)
            if (arrow.hasMetadata("ce.minigunarrow"))
                if (((Player) shooter).getGameMode().equals(GameMode.CREATIVE))
                    arrow.remove();
    }

}
 
Example #26
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void ProjectileHitEvent(ProjectileHitEvent e) {

    ProjectileSource shooter = e.getEntity().getShooter();

    if (shooter instanceof Player) {
        if (e.getEntity().hasMetadata("ce.projectile.item")) {
            CItem ci = Tools.getItemByOriginalname(e.getEntity().getMetadata("ce.projectile.item").get(0).asString());
            if (ci != null)
                ci.effect(e, (Player) shooter);
        }
    }
}
 
Example #27
Source File: Projectiles.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityHitByProjectile(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) return;
    if (event.getCause().equals(DamageCause.PROJECTILE)) {
        ProjectileSource source = ((Projectile) event.getDamager()).getShooter();
        if (source instanceof Player) {
            ((Player) source).playSound(((Player) source).getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.2F, 0.5F);
        }
        if (event.getDamager().getType().equals(projectile) && event.getDamager().hasMetadata("custom")) {
            Entity arrow = event.getEntity().getWorld().spawnEntity(event.getDamager().getLocation(), EntityType.ARROW);
            ((Projectile) arrow).setShooter(source);
            arrow.setVelocity(event.getDamager().getVelocity());
            event.getDamager().remove();
            if (event.getEntity() instanceof LivingEntity) {
                for (PotionEffect effect : potionEffects) {
                    ((LivingEntity) event.getEntity()).addPotionEffect(effect);
                }
                final Entity entity = event.getEntity();
                Bukkit.getServer().getScheduler().runTaskLater(GameHandler.getGameHandler().getPlugin(), new Runnable() {
                    @Override
                    public void run() {
                        ((LivingEntity) entity).setArrowsStuck(((LivingEntity) entity).getArrowsStuck() - 1);
                    }
                }, 0);
            }
        }
    }
}
 
Example #28
Source File: FlagBowspleef.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent event) {
	Entity damagerEntity = event.getDamager();
	Entity damagedEntity = event.getEntity();
	
	if (!(damagerEntity instanceof Arrow) || !(damagedEntity instanceof Player)) {
		return;
	}
	
	Arrow arrow = (Arrow) damagerEntity;
	ProjectileSource source = arrow.getShooter();
	if (!(source instanceof Player)) {
		return;
	}
	
	SpleefPlayer damager = getHeavySpleef().getSpleefPlayer(source);
	SpleefPlayer damaged = getHeavySpleef().getSpleefPlayer(damagedEntity);
	
	if (!game.isIngame(damager) || !game.isIngame(damaged)) {
		return;
	}
	
	event.setCancelled(true);
	
	Location location = damaged.getBukkitPlayer().getLocation();
	location.subtract(0, 1, 0);
	
	Block block = location.getWorld().getBlockAt(location);
	if (!game.canSpleef(block)) {
		return;
	}
	
	game.addBlockBroken(damager, block);
	dropBlock(block);
}
 
Example #29
Source File: EntityListener.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    final Projectile projectile = event.getEntity();

    ProjectileSource shooter = projectile.getShooter();
    if (shooter instanceof Player && listenerService.shouldCancelEvent((Player) shooter)) {
        event.setCancelled(true);
    }
}
 
Example #30
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onEntityLaunchProjectile(ProjectileLaunchEvent event) {
	ProjectileSource source = event.getEntity().getShooter();
	if (source instanceof LivingEntity && plugin.isShopkeeper((LivingEntity) source)) {
		event.setCancelled(true);
	}
}