Java Code Examples for org.bukkit.event.entity.ProjectileHitEvent#getEntity()

The following examples show how to use org.bukkit.event.entity.ProjectileHitEvent#getEntity() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
Source File: ProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@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 9
Source File: VersionHelper18.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public Entity getEntLingPot(ProjectileHitEvent e) {
    return e.getEntity();
}
 
Example 10
Source File: VersionHelper112.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public Entity getEntLingPot(ProjectileHitEvent e) {
    return e.getEntity();
}
 
Example 11
Source File: VersionHelperLatest.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public Entity getEntLingPot(ProjectileHitEvent e) {
    return e.getEntity();
}
 
Example 12
Source File: VersionHelper113.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public Entity getEntLingPot(ProjectileHitEvent e) {
    return e.getEntity();
}
 
Example 13
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 14
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());
	}
}