Java Code Examples for org.bukkit.entity.Projectile#remove()
The following examples show how to use
org.bukkit.entity.Projectile#remove() .
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: TalismanListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
/** * This method is used for the {@link Talisman} of the whirlwind, it returns a copy * of a {@link Projectile} that was fired at a {@link Player}. * * @param p * The {@link Player} who was hit * @param projectile * The {@link Projectile} that hit this {@link Player} */ private void returnProjectile(Player p, Projectile projectile) { Vector direction = p.getEyeLocation().getDirection().multiply(2.0); Location loc = p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()); Projectile returnedProjectile = (Projectile) p.getWorld().spawnEntity(loc, projectile.getType()); returnedProjectile.setShooter(projectile.getShooter()); returnedProjectile.setVelocity(direction); if (projectile instanceof AbstractArrow) { AbstractArrow firedArrow = (AbstractArrow) projectile; AbstractArrow returnedArrow = (AbstractArrow) returnedProjectile; returnedArrow.setDamage(firedArrow.getDamage()); returnedArrow.setPickupStatus(firedArrow.getPickupStatus()); returnedArrow.setPierceLevel(firedArrow.getPierceLevel()); } projectile.remove(); }
Example 2
Source File: ProjectileMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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 3
Source File: ProjectileMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler public void onProjectileHitEvent(ProjectileHitEvent event) { Projectile projectile = event.getEntity(); ProjectileDefinition projectileDefinition = getProjectileDefinition(projectile); if (projectileDefinition == null) return; Filter filter = projectileDefinition.destroyFilter; if (filter == null) return; BlockIterator it = new BlockIterator( projectile.getWorld(), projectile.getLocation().toVector(), projectile.getVelocity().normalize(), 0d, 2); Block hitBlock = null; while (it.hasNext()) { hitBlock = it.next(); if (hitBlock.getType() != Material.AIR) { break; } } if (hitBlock != null) { MatchPlayer player = projectile.getShooter() instanceof Player ? match.getPlayer((Player) projectile.getShooter()) : null; Query query = player != null ? new PlayerBlockQuery(event, player, hitBlock.getState()) : new BlockQuery(event, hitBlock); if (filter.query(query).isAllowed()) { BlockTransformEvent bte = new BlockTransformEvent(event, hitBlock, Material.AIR); match.callEvent(bte); if (!bte.isCancelled()) { hitBlock.setType(Material.AIR); projectile.remove(); } } } }
Example 4
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Trap TNT being primed by flaming arrows * @param e - event */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onTNTPrimed(final EntityChangeBlockEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); plugin.getLogger().info("DEBUG: block = " + e.getBlock().getType()); plugin.getLogger().info("DEBUG: entity = " + e.getEntityType()); plugin.getLogger().info("DEBUG: material changing to " + e.getTo()); } if (actionAllowed(e.getEntity().getLocation(), SettingsFlag.FIRE)) { return; } if (e.getBlock() == null) { return; } // Check for TNT if (!e.getBlock().getType().equals(Material.TNT)) { //plugin.getLogger().info("DEBUG: not tnt"); return; } // Check world if (!inWorld(e.getBlock())) { return; } // Check if this is on an island Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation()); if (island == null || island.isSpawn()) { return; } // Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow if (e.getEntity() instanceof Projectile) { //plugin.getLogger().info("DEBUG: projectile"); Projectile projectile = (Projectile) e.getEntity(); // Find out who fired it if (projectile.getShooter() instanceof Player) { //plugin.getLogger().info("DEBUG: player shot arrow. Fire ticks = " + projectile.getFireTicks()); if (projectile.getFireTicks() > 0) { //plugin.getLogger().info("DEBUG: arrow on fire"); Player shooter = (Player)projectile.getShooter(); if (!plugin.getGrid().locationIsAtHome(shooter, true, e.getBlock().getLocation())) { //plugin.getLogger().info("DEBUG: shooter is not at home"); // Only say it once a second // Debounce event (it can be called twice for the same action) if (!tntBlocks.contains(e.getBlock().getLocation())) { Util.sendMessage(shooter, ChatColor.RED + plugin.myLocale(shooter.getUniqueId()).islandProtected); tntBlocks.add(e.getBlock().getLocation()); plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { @Override public void run() { tntBlocks.remove(e.getBlock().getLocation()); }}, 20L); } // Remove the arrow projectile.remove(); e.setCancelled(true); } } } } }
Example 5
Source File: FlagSnowballs.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@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()); } }