Java Code Examples for org.bukkit.entity.Projectile#getShooter()
The following examples show how to use
org.bukkit.entity.Projectile#getShooter() .
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: IslandGuard.java From askyblock with GNU General Public License v2.0 | 7 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onItemFrameDamage(final EntityDamageByEntityEvent e) { // Check world if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) { return; } if (e.getDamager() instanceof Projectile) { if (DEBUG) plugin.getLogger().info("DEBUG: Projectile damage to itemframe"); // Find out who fired the arrow Projectile p = (Projectile) e.getDamager(); if (DEBUG) plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString()); if (p.getShooter() instanceof Skeleton || p.getShooter() instanceof Golem) { if (DEBUG) plugin.getLogger().info("DEBUG: Shooter is mob"); if (!Settings.allowMobDamageToItemFrames) { if (DEBUG) plugin.getLogger().info("DEBUG: Damage not allowed, cancelling"); e.setCancelled(true); } } } }
Example 2
Source File: IslandGuard1_9.java From askyblock with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) { if (!IslandGuard.inWorld(e.getEntity().getLocation())) { return; } // Try to get the shooter Projectile projectile = (Projectile) e.getEntity(); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { UUID uuid = ((Player)projectile.getShooter()).getUniqueId(); // Store it and remove it when the effect is gone thrownPotions.put(e.getAreaEffectCloud().getEntityId(), uuid); plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { @Override public void run() { thrownPotions.remove(e.getAreaEffectCloud().getEntityId()); }}, e.getAreaEffectCloud().getDuration()); } }
Example 3
Source File: ParticleEffectListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler public void projectileLaunch(ProjectileLaunchEvent e) { Projectile projectile = e.getEntity(); if (projectile instanceof Snowball || projectile instanceof Egg || projectile instanceof Arrow) { if (projectile.getShooter() instanceof Player) { Player player = (Player) projectile.getShooter(); GameMap gMap = MatchManager.get().getPlayerMap(player); if (gMap != null) { PlayerStat ps = PlayerStat.getPlayerStats(player.getUniqueId()); if (ps != null) { String key = ps.getProjectileEffect(); ProjectileEffectOption peo = (ProjectileEffectOption) ProjectileEffectOption.getPlayerOptionByKey(key); if (peo != null) { List<ParticleEffect> effects = peo.getEffects(); if (key != null && effects != null) { if (!key.equalsIgnoreCase("none")) { SkyWarsReloaded.getOM().addProjectile(projectile, effects); } } } } } } } }
Example 4
Source File: SentinelEventHandler.java From Sentinel with MIT License | 6 votes |
/** * 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 5
Source File: PlayerDamageListener.java From UhcCore with GNU General Public License v3.0 | 6 votes |
private void handleArrow(EntityDamageByEntityEvent event){ PlayersManager pm = GameManager.getGameManager().getPlayersManager(); if(event.getEntity() instanceof Player && event.getDamager() instanceof Arrow){ Projectile arrow = (Projectile) event.getDamager(); final Player shot = (Player) event.getEntity(); if(arrow.getShooter() instanceof Player){ if(!GameManager.getGameManager().getPvp()){ event.setCancelled(true); return; } UhcPlayer uhcDamager = pm.getUhcPlayer((Player) arrow.getShooter()); UhcPlayer uhcDamaged = pm.getUhcPlayer(shot); if(!friendlyFire && uhcDamager.getState().equals(PlayerState.PLAYING) && uhcDamager.isInTeamWith(uhcDamaged)){ uhcDamager.sendMessage(Lang.PLAYERS_FF_OFF); event.setCancelled(true); } } } }
Example 6
Source File: EntityListener.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@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 7
Source File: ProjectileParticlesModule.java From CardinalPGM with MIT License | 5 votes |
public static void sendArrowParticle(Projectile arrow, float x, float y, float z) { Location loc = arrow.getLocation(); PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.REDSTONE, true, (float)loc.getX(), (float)loc.getY(), (float)loc.getZ(), x, y, z, 1f, 0); PacketUtils.broadcastPacketByUUID(packet, allArrows); if (arrow.getShooter() instanceof Player && selfArrows.contains(((Player) arrow.getShooter()).getUniqueId())) PacketUtils.sendPacket((Player) arrow.getShooter(), packet); }
Example 8
Source File: ListenerDamage.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
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 9
Source File: EntityListener.java From Guilds with MIT License | 5 votes |
@EventHandler public void onDamage(EntityDamageByEntityEvent event) { if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Projectile)) { return; } Projectile projectile = (Projectile) event.getDamager(); if (!(projectile.getShooter() instanceof Player)) { return; } Player damaged = (Player) event.getEntity(); Player damager = (Player) projectile.getShooter(); if (settingsManager.getProperty(GuildSettings.RESPECT_WG_PVP_FLAG)) { event.setCancelled(ClaimUtils.checkPvpDisabled(damaged)); return; } if (guildHandler.isSameGuild(damaged, damager) && damaged != damager) { event.setCancelled(!settingsManager.getProperty(GuildSettings.GUILD_DAMAGE)); return; } if (guildHandler.isAlly(damaged, damager)) { event.setCancelled(!settingsManager.getProperty(GuildSettings.ALLY_DAMAGE)); } }
Example 10
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 11
Source File: Infinity.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onShoot(ProjectileLaunchEvent 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.infinity.use")) return; ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.CROSSBOW.contains(tool.getType())) return; if (!modManager.isToolViable(tool)) return; if (!modManager.hasMod(tool, this)) return; if(!((Arrow) arrow).hasCustomEffects()) { if (player.getInventory().addItem(new ItemStack(Material.ARROW, 1)).size() != 0) { //adds items to (full) inventory player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.ARROW, 1)); //drops item when inventory is full } // no else as it gets added in if ((Arrow) arrow).setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY); ChatWriter.logModifier(player, event, this, tool); } }
Example 12
Source File: MultiShot.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onShoot(ProjectileLaunchEvent 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.multishot.use")) { return; } ItemStack tool = player.getInventory().getItemInMainHand(); if (ToolType.CROSSBOW.contains(tool.getType()) && getConfig().getBoolean("UseEnchantOnCrossbow")) { return; } if (!modManager.isToolViable(tool)) { return; } int modLevel = modManager.getModLevel(tool, this); if (modLevel <= 0) { return; } Vector vel = arrow.getVelocity().clone(); Location loc = arrow.getLocation().clone(); boolean hasInfinity = modManager.hasMod(tool, Infinity.instance()); boolean hasFiery = modManager.hasMod(tool, Fiery.instance()) && player.hasPermission("minetinker.modifiers.fiery.use"); ChatWriter.logModifier(player, event, this, tool, Fiery.instance().getKey() + "(" + hasFiery + ")", Infinity.instance().getKey() + "(" + hasInfinity + ")"); for (int i = 1; i <= modLevel; i++) { if (!player.getGameMode().equals(GameMode.CREATIVE)) { if (!hasInfinity && needsArrows) { if (!player.getInventory().contains(Material.ARROW)) { break; } for (ItemStack item : player.getInventory().getContents()) { if (item == null) { continue; } if (item.getType() == Material.ARROW) { item.setAmount(item.getAmount() - 1); break; } } } } Bukkit.getScheduler().runTaskLater(MineTinker.getPlugin(), () -> { Arrow arr = loc.getWorld().spawnArrow(loc, vel, (float) vel.length(), (float) spread); if(hasFiery) arr.setFireTicks(2000); arr.setShooter(player); if (hasInfinity || player.getGameMode().equals(GameMode.CREATIVE)) { arr.setPickupStatus(AbstractArrow.PickupStatus.CREATIVE_ONLY); } arr.setCritical(((Arrow) arrow).isCritical()); arr.setDamage(((Arrow) arrow).getDamage()); }, i); } }
Example 13
Source File: Fiery.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onShoot(ProjectileLaunchEvent 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.fiery.use")) return; ItemStack tool = player.getInventory().getItemInMainHand(); if (!ToolType.CROSSBOW.contains(tool.getType())) return; if (!modManager.isToolViable(tool)) return; if (!modManager.hasMod(tool, this)) return; arrow.setFireTicks(2000); }
Example 14
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onProjectileHit(EntityInteractEvent e) { if (e.getEntity() == null || !(e.getEntity() instanceof Projectile)) { return; } Projectile p = (Projectile)e.getEntity(); if (p.getShooter() != null && p.getShooter() instanceof Player && e.getBlock() != null) { Player player = (Player)p.getShooter(); if (!inWorld(player) || player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().playerIsOnIsland(player)) { return; } Island island = plugin.getGrid().getProtectedIslandAt(e.getBlock().getLocation()); switch(e.getBlock().getType()) { case WOOD_BUTTON: case STONE_BUTTON: if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.LEVER_BUTTON))) { return; } if (island != null && island.getIgsFlag(SettingsFlag.LEVER_BUTTON)) { return; } Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandProtected); e.setCancelled(true); break; case WOOD_PLATE: case STONE_PLATE: case GOLD_PLATE: case IRON_PLATE: // Pressure plates if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.PRESSURE_PLATE))) { return; } if (island != null && island.getIgsFlag(SettingsFlag.PRESSURE_PLATE)) { return; } Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandProtected); e.setCancelled(true); break; default: break; } } }
Example 15
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 16
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them. * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onSplashPotionSplash(final PotionSplashEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); plugin.getLogger().info("splash entity = " + e.getEntity()); plugin.getLogger().info("splash entity type = " + e.getEntityType()); plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities()); //plugin.getLogger().info("splash hit entity = " + e.getHitEntity()); } if (!IslandGuard.inWorld(e.getEntity().getLocation())) { return; } // Try to get the shooter Projectile projectile = e.getEntity(); if (DEBUG) plugin.getLogger().info("splash shooter = " + projectile.getShooter()); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { Player attacker = (Player)projectile.getShooter(); // Run through all the affected entities for (LivingEntity entity: e.getAffectedEntities()) { if (DEBUG) plugin.getLogger().info("DEBUG: affected splash entity = " + entity); // Self damage if (attacker.equals(entity)) { if (DEBUG) plugin.getLogger().info("DEBUG: Self damage from splash potion!"); continue; } Island island = plugin.getGrid().getIslandAt(entity.getLocation()); boolean inNether = false; if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) { inNether = true; } // Monsters being hurt if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) { // Normal island check if (island != null && island.getMembers().contains(attacker.getUniqueId())) { // Members always allowed continue; } if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) { continue; } // Not allowed Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected); e.setCancelled(true); return; } // Mobs being hurt if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) { if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) { continue; } if (DEBUG) plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking"); Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected); e.setCancelled(true); return; } // Establish whether PVP is allowed or not. boolean pvp = false; if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); pvp = true; } // Players being hurt PvP if (entity instanceof Player) { if (pvp) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); } else { if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed"); Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea); e.setCancelled(true); return; } } } } }
Example 17
Source File: FlyingMobEvents.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Deal with pre-explosions */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void WitherExplode(final ExplosionPrimeEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } // Only cover withers in the island world if (!IslandGuard.inWorld(e.getEntity()) || e.getEntity() == null) { return; } // The wither or wither skulls can both blow up if (e.getEntityType() == EntityType.WITHER) { //plugin.getLogger().info("DEBUG: Wither"); // Check the location if (mobSpawnInfo.containsKey(e.getEntity())) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); } if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) { // Cancel the explosion if (DEBUG) { plugin.getLogger().info("DEBUG: cancelling wither pre-explosion"); } e.setCancelled(true); } } // Testing only e.setCancelled(true); } if (e.getEntityType() == EntityType.WITHER_SKULL) { //plugin.getLogger().info("DEBUG: Wither skull"); // Get shooter Projectile projectile = (Projectile)e.getEntity(); if (projectile.getShooter() instanceof Wither) { //plugin.getLogger().info("DEBUG: shooter is wither"); Wither wither = (Wither)projectile.getShooter(); // Check the location if (mobSpawnInfo.containsKey(wither)) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); } if (!mobSpawnInfo.get(wither).inIslandSpace(e.getEntity().getLocation())) { // Cancel the explosion if (DEBUG) { plugin.getLogger().info("DEBUG: cancel wither skull explosion"); } e.setCancelled(true); } } } } }
Example 18
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 19
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()); } }
Example 20
Source File: ModifyBowProjectileMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void fixEntityDamage(EntityDamageByEntityEvent event) { Entity projectile = event.getDamager(); if (projectile.hasMetadata("customProjectile")) { // If the custom projectile replaced an arrow, recreate some effects specific to arrows if (projectile.hasMetadata("damage")) { boolean critical = projectile.getMetadata("critical").get(0).asBoolean(); int knockback = projectile.getMetadata("knockback").get(0).asInt(); double damage = projectile.getMetadata("damage").get(0).asDouble(); double speed = projectile.getVelocity().length(); // Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod); if (critical) { finalDamage += match.getRandom().nextInt(finalDamage / 2 + 2); } event.setDamage(finalDamage); // Flame arrows - target burns for 5 seconds always if (projectile.getFireTicks() > 0) { event.getEntity().setFireTicks(100); } // Reproduce the knockback calculation for punch bows if (knockback > 0) { Vector projectileVelocity = projectile.getVelocity(); double horizontalSpeed = Math.sqrt( projectileVelocity.getX() * projectileVelocity.getX() + projectileVelocity.getZ() * projectileVelocity.getZ()); Vector velocity = event.getEntity().getVelocity(); velocity.setX( velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed); velocity.setY(velocity.getY() + 0.1); velocity.setZ( velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed); event.getEntity().setVelocity(velocity); } // If the projectile is not an arrow, play an impact sound. if (event.getEntity() instanceof Player && (projectile instanceof Projectile && !(projectile instanceof Arrow))) { Projectile customProjectile = (Projectile) projectile; if (customProjectile.getShooter() instanceof Player) { Player bukkitShooter = (Player) customProjectile.getShooter(); MatchPlayer shooter = match.getPlayer(bukkitShooter); if (shooter != null && event.getEntity() != null) { shooter.playSound(PROJECTILE_SOUND); } } } } // Apply any potion effects attached to the projectile if (event.getEntity() instanceof LivingEntity) { for (PotionEffect potionEffect : this.potionEffects) { ((LivingEntity) event.getEntity()).addPotionEffect(potionEffect); } } } }