org.bukkit.event.entity.ProjectileHitEvent Java Examples

The following examples show how to use org.bukkit.event.entity.ProjectileHitEvent. 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: ServerListener.java    From ZombieEscape with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onHit(ProjectileHitEvent event) {
    Projectile projectile = event.getEntity();

    if (projectile instanceof Arrow) {
        projectile.remove();
    } else if (projectile instanceof Snowball && event.getEntity() instanceof Player) {
        ((Player) event.getEntity()).addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 20 * 2, 1));
    } else if (projectile instanceof Egg && projectile.getShooter() instanceof Player) {
        projectile.getWorld().createExplosion(projectile.getLocation(), 0.0F);

        for (Entity entity : projectile.getNearbyEntities(5, 5, 5)) {
            if (entity instanceof Player) {
                Player player = (Player) entity;
                if (plugin.getGameArena().isZombie(player)) {
                    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20 * 5, 1));
                    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 5, 1));
                }
            }
        }
    }
}
 
Example #2
Source File: KitMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onGrenadeExplode(final ProjectileHitEvent event) {
  if (event.getEntity().getShooter() instanceof Player) {
    Grenade grenade = Grenade.get(event.getEntity());
    if (grenade != null) {
      event
          .getWorld()
          .createExplosion(
              event.getEntity(),
              event.getEntity().getLocation(),
              grenade.power,
              grenade.fire,
              grenade.destroy);
      event.getEntity().remove();
    }
  }
}
 
Example #3
Source File: KillerProjectiles.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onDamagePlayer(ProjectileHitEvent event) {
    if (event.getHitEntity() instanceof Player) {

        Player player = (Player) event.getHitEntity();
        Projectile projectile = event.getEntity();
        Region r = RedProtect.get().rm.getTopRegion(projectile.getLocation());

        double damage;
        if (getConfig().getString("projectile-damage").endsWith("%")) {
            damage = (player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue() / 100) * Double.valueOf(getConfig().getString("projectile-damage", "100%").replace("%", ""));
        } else {
            damage = getConfig().getInt("projectile-damage");
        }

        if (r != null && r.getFlagBool("killer-projectiles") && getConfig().getStringList("allowed-types").contains(projectile.getType().name())) {
            player.setHealth(damage);
        }
    }
}
 
Example #4
Source File: TorchBow.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onProjectileHit(ProjectileHitEvent event, DelayedPlayerDetails details) {
	event.getEntity().remove();
	Block b = event.getEntity().getLocation().getBlock();
	if (b.isEmpty()) {
		b.setType(Material.TORCH);
	}
}
 
Example #5
Source File: Compat111.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
private void onChorusBreak(ProjectileHitEvent event) {
    if (!(event.getEntity().getShooter() instanceof Player)) return;

    if (event.getHitBlock() != null && event.getHitBlock().getType() == Material.CHORUS_FLOWER) {
        Player p = (Player) event.getEntity().getShooter();
        Region r = RedProtect.get().rm.getTopRegion(event.getHitBlock().getLocation());
        if (r != null && !r.canBuild(p)) {
            event.getEntity().remove();
            event.getHitBlock().setType(Material.AIR);
            Bukkit.getScheduler().runTask(RedProtect.get(), () -> event.getHitBlock().setType(Material.CHORUS_FLOWER));
            RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak");
        }
    }
}
 
Example #6
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example #7
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example #8
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example #9
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example #10
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example #11
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example #12
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHitEvent(ProjectileHitEvent event) {
	if (event.getEntity() instanceof Arrow) {
		ArrowFiredCache afc = CivCache.arrowsFired.get(event.getEntity().getUniqueId());
		if (afc != null) {
			afc.setHit(true);
		}
	}

	if (event.getEntity() instanceof Fireball) {
		CannonFiredCache cfc = CivCache.cannonBallsFired.get(event.getEntity().getUniqueId());
		if (cfc != null) {

			cfc.setHit(true);

			FireworkEffect fe = FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLACK).flicker(true).with(Type.BURST).build();

			Random rand = new Random();
			int spread = 30;
			for (int i = 0; i < 15; i++) {
				int x = rand.nextInt(spread) - spread/2;
				int y = rand.nextInt(spread) - spread/2;
				int z = rand.nextInt(spread) - spread/2;


				Location loc = event.getEntity().getLocation();
				Location location = new Location(loc.getWorld(), loc.getX(),loc.getY(), loc.getZ());
				location.add(x, y, z);

				TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 5), rand.nextInt(30));
			}

		}
	}
}
 
Example #13
Source File: SlimefunBowListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onArrowHit(ProjectileHitEvent e) {
    Slimefun.runSync(() -> {
        if (e.getEntity().isValid() && e.getEntity() instanceof Arrow) {
            projectiles.remove(e.getEntity().getUniqueId());
        }
    }, 4L);
}
 
Example #14
Source File: GrapplingHookListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onArrowHitSurface(ProjectileHitEvent e) {
    if (!isEnabled()) {
        return;
    }

    Slimefun.runSync(() -> {
        if (e.getEntity() instanceof Arrow) {
            handleGrapplingHook((Arrow) e.getEntity());
        }
    }, 2L);
}
 
Example #15
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
private void projectileHit(ProjectileHitEvent event) {
	Projectile projectile = event.getEntity();
	if (projectile.hasMetadata("CustomItem-bow")) {
		Object[] data = (Object[]) projectile.getMetadata("CustomItem-bow").get(0).value();
		((CustomBow) data[0]).onProjectileHit(event, (DelayedPlayerDetails) data[1]);
	}
}
 
Example #16
Source File: Magical.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onHit(ProjectileHitEvent event) {
	if (!this.isAllowed()) return;

	Projectile arrow = event.getEntity();
	if (!(arrow instanceof Arrow)) return;

	if (!(arrow.getShooter() instanceof Player)) return;

	Player player = (Player) arrow.getShooter();
	if(!player.hasPermission("minetinker.modifiers.magical.use")) return;

	String customName = arrow.getCustomName();
	if (customName == null) return;

	String[] name = customName.split(":");
	if (name.length != 3) return;
	if (!name[0].equals(this.getKey())) return;

	try {
		//int modLevel = Integer.parseInt(name[1]);

		Entity entity = Bukkit.getServer().getEntity(UUID.fromString(name[2]));
		if (entity != null) {
			entity.remove();
		}

		arrow.remove();
	} catch (NumberFormatException ignored) {}
}
 
Example #17
Source File: GrenadeListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onGrenadeExplode(final ProjectileHitEvent event) {
    if (event.getEntity().getShooter() instanceof Player) {
        Grenade grenade = Grenade.get(event.getEntity());
        if(grenade != null) {
            NMSHacks.createExplosion(event.getEntity(), event.getEntity().getLocation(), grenade.power, grenade.fire, grenade.destroy);
            event.getEntity().remove();
        }
    }
}
 
Example #18
Source File: ProjectileTrailMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileHit(ProjectileHitEvent event) {
    match.player(event.getActor()).ifPresent(shooter -> {
        final Projectile projectile = event.getEntity();
        projectile.removeMetadata(TRAIL_META, PGM.get());
        // Restore critical metadata to arrows if applicable
        if(projectile instanceof Arrow) {
            final Arrow arrow = (Arrow) projectile;
            if(arrow.hasMetadata(CRITICAL_META)) {
                arrow.setCritical(arrow.getMetadata(CRITICAL_META, PGM.get()).asBoolean());
            }
        }
    });
}
 
Example #19
Source File: ProjectileMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onProjectileHitEvent(ProjectileHitEvent event) {
    final Projectile projectile = event.getEntity();
    final ProjectileDefinition projectileDefinition = Projectiles.getProjectileDefinition(projectile);
    if(projectileDefinition == null) return;

    final Filter filter = projectileDefinition.destroyFilter();
    if(filter == null) return;

    final BlockIterator blockIterator = new BlockIterator(projectile.getWorld(), projectile.getLocation().toVector(), projectile.getVelocity().normalize(), 0d, 2);
    Block hitBlock = null;
    while(blockIterator.hasNext()) {
        hitBlock = blockIterator.next();
        if(hitBlock.getType() != Material.AIR) break;
    }

    if(hitBlock != null) {
        final MatchPlayer shooter = projectile.getShooter() instanceof Player ? getMatch().getPlayer((Player) projectile.getShooter()) : null;
        final IQuery query = shooter != null ? new PlayerBlockEventQuery(shooter, event, hitBlock.getState())
                                             : new BlockEventQuery(event, hitBlock);

        if(filter.query(query).isAllowed()) {
            final BlockTransformEvent bte = new BlockTransformEvent(event, hitBlock, Material.AIR);
            match.callEvent(bte);

            if(!bte.isCancelled()) {
                hitBlock.setType(Material.AIR);
                projectile.remove();
            }
        }
    }
}
 
Example #20
Source File: EggsScenarioListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onProjectileHit(ProjectileHitEvent e){
    if (e.getEntityType() != EntityType.EGG){
        return;
    }

    EntityType type = getRandomEntity();
    Location loc = e.getEntity().getLocation();
    loc.getWorld().spawnEntity(loc, type);
}
 
Example #21
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 #22
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 #23
Source File: EntityShootBow.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onArrowHit(ProjectileHitEvent event) {
	if (event.getEntityType() != EntityType.ARROW && event.getEntityType() != EntityType.SPECTRAL_ARROW)
		return;
	if (ArrowFromCustomBowHit.containsArrow(event.getEntity())) {
		BowStackContainer container = ArrowFromCustomBowHit.getBowStackContainer(event.getEntity());
		Bukkit.getServer().getPluginManager()
				.callEvent(new ArrowFromCustomBowHitEvent(event, container.getOwner(), container.getBowStack()));
	}
}
 
Example #24
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	return event.getHitBlock();
}
 
Example #25
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	return event.getHitBlock();
}
 
Example #26
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	return event.getHitBlock();
}
 
Example #27
Source File: FlagSplegg.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onProjectileHit(ProjectileHitEvent event) {
	Projectile projectile = event.getEntity();
	if (!(projectile instanceof Egg)) {
		return;
	}
	
	ProjectileSource source = projectile.getShooter();
	
	if (!(source instanceof Player)) {
		return;
	}
	
	SpleefPlayer shooter = getHeavySpleef().getSpleefPlayer(source);
	Game game = getHeavySpleef().getGameManager().getGame(shooter);
	if (game != this.game) {
		return;
	}
	
	projectile.remove();
	
	if (game == null || game.getGameState() != GameState.INGAME) {
		return;
	}
	
	// Use a BlockIterator to determine where the arrow has hit the ground
	BlockIterator blockIter = new BlockIterator(projectile.getWorld(), 
			projectile.getLocation().toVector(), 
			projectile.getVelocity().normalize(), 
			0, 4);
	
	Block blockHit = null;
	
	while (blockIter.hasNext()) {
		blockHit = blockIter.next();
		
		if (blockHit.getType() != Material.AIR) {
			break;
		}
	}
	
	if (!game.canSpleef(blockHit)) {
		//Cannot remove this block
		return;
	}
	
	game.addBlockBroken(shooter, blockHit);
	Material type = blockHit.getType();
	blockHit.setType(Material.AIR);
	
	World world = blockHit.getWorld();
	
	if (type == Material.TNT) {
		Location spawnLocation = blockHit.getLocation().add(0.5, 0, 0.5);
		TNTPrimed tnt = (TNTPrimed) world.spawnEntity(spawnLocation, EntityType.PRIMED_TNT);
		tnt.setMetadata(TNT_METADATA_KEY, new FixedMetadataValue(getHeavySpleef().getPlugin(), game));
		tnt.setYield(3);
		tnt.setFuseTicks(0);
	} else {
           Sound chickenEggPopSound = Game.getSoundEnumType("CHICKEN_EGG_POP", "CHICKEN_EGG");
           if (chickenEggPopSound != null) {
               projectile.getWorld().playSound(blockHit.getLocation(), chickenEggPopSound, 1.0f, 0.7f);
           }
	}
}
 
Example #28
Source File: FlagSnowballs.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onProjectileHit(ProjectileHitEvent event) {
	Projectile projectile = event.getEntity();
	if (!(projectile instanceof Snowball)) {
		return;
	}
	
	ProjectileSource shooter = projectile.getShooter();
	if (!(shooter instanceof Player)) {
		return;
	}
	
	SpleefPlayer player = getHeavySpleef().getSpleefPlayer(shooter);
	GameManager manager = getHeavySpleef().getGameManager();
	Game game;
	
	if ((game = manager.getGame(player)) == null) {
		return;
	}

	Location location = projectile.getLocation();
	Vector start = location.toVector();
	Vector dir = projectile.getVelocity().normalize();
	
	BlockIterator iterator = new BlockIterator(projectile.getWorld(), start, dir, 0, 4);
	
	Block blockHit = null;
	
	while (iterator.hasNext()) {
		blockHit = iterator.next();
		
		if (blockHit.getType() != Material.AIR) {
			break;
		}
	}
	
	if (!game.canSpleef(blockHit)) {
		//Cannot remove this block
		return;
	}
	
	projectile.remove();
	game.addBlockBroken(player, blockHit);
	
	blockHit.setType(Material.AIR);
	if (game.getPropertyValue(GameProperty.PLAY_BLOCK_BREAK)) {
		blockHit.getWorld().playEffect(blockHit.getLocation(), Effect.STEP_SOUND, blockHit.getTypeId());
	}
}
 
Example #29
Source File: VersionHelperLatest.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileSource getPlayerLingPot(ProjectileHitEvent e) {
    return e.getEntity().getShooter();
}
 
Example #30
Source File: VersionHelper113.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public ProjectileSource getPlayerLingPot(ProjectileHitEvent e) {
    return e.getEntity().getShooter();
}