@EventHandler
    public void onProjectileHit(ProjectileHitEvent projectile) {
      Heroes.debug.startTask("HeroesSkillListener");

      if (!(projectile.getEntity() instanceof Arrow)) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Arrow arrow = (Arrow) projectile.getEntity();

      if (!(arrow.getShooter() instanceof Player)) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      Player player = (Player) arrow.getShooter();
      Hero hero = SkillExplodingArrow.this.plugin.getCharacterManager().getHero(player);
      if (!hero.hasEffect("ExplodingArrowBuff")) {
        Heroes.debug.stopTask("HeroesSkillListener");
        return;
      }

      int radius =
          (int)
              Math.pow(
                  SkillConfigManager.getUseSetting(hero, this.skill, "radius", 5, false), 2.0D);

      float damage = SkillConfigManager.getUseSetting(hero, this.skill, "DAMAGE", 5, false);
      float blockdamage = damage;
      int block_dmg = SkillConfigManager.getUseSetting(hero, this.skill, "block-dmg", 0, false);

      if (block_dmg == 0) {
        blockdamage = 0.0F;

        for (Entity t_entity : player.getWorld().getEntities()) {
          if ((t_entity instanceof Player)) {
            Player heroes = (Player) t_entity;
            if ((heroes.equals(player))
                || (heroes.getLocation().distanceSquared(arrow.getLocation()) > radius)) continue;
            damageEntity(
                heroes, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
          } else if ((t_entity instanceof Creature)) {
            Creature mob = (Creature) t_entity;
            if (t_entity.getLocation().distanceSquared(arrow.getLocation()) <= radius) {
              damageEntity(
                  mob, player, (int) damage, EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
            }
          }
        }
      }

      arrow.getWorld().createExplosion(arrow.getLocation(), blockdamage);

      Heroes.debug.stopTask("HeroesSkillListener");
    }
Пример #2
0
	@EventHandler
	public void onProjectileHit(ProjectileHitEvent e) {
		if (!(e.getEntity() instanceof Arrow) && !(e.getEntity() instanceof Egg))
			return;

		Projectile projectile = e.getEntity();

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

		SpleefPlayer player = HeavySpleef.getInstance().getSpleefPlayer(projectile.getShooter());

		if (!player.isActive())
			return;

		Game game = player.getGame();

		if (projectile instanceof Arrow) {
			Arrow arrow = (Arrow) projectile;

			if (!game.getFlag(FlagType.BOWSPLEEF))
				return;

			// Use BlockIterator to detect the hit block
			BlockIterator iterator = new BlockIterator(arrow.getWorld(), arrow.getLocation().toVector(), arrow.getVelocity().normalize(), 0, 4);
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			World world = arrow.getWorld();

			if (hitBlock.getType() == Material.TNT) {
				return;
			}

			arrow.remove();

			player.addBrokenBlock(hitBlock);
			FallingBlock block = world.spawnFallingBlock(hitBlock.getLocation(), hitBlock.getType(), hitBlock.getData());
			block.setMetadata("bowspleef", new FixedMetadataValue(HeavySpleef.getInstance(), true));

			if (game.getFlag(FlagType.BLOCKBREAKEFFECT)) {
				world.playEffect(hitBlock.getLocation(), Effect.STEP_SOUND, hitBlock.getType());
			}
			hitBlock.setType(Material.AIR);
		} else if (projectile instanceof Egg) {
			Egg egg = (Egg) projectile;

			if (!game.getFlag(FlagType.SPLEGG))
				return;

			// Use BlockIterator to detect the hit block
			World world = egg.getWorld();
			BlockIterator iterator = new BlockIterator(egg.getWorld(), egg.getLocation().toVector(), egg.getVelocity().normalize(), 0, 4);

			egg.remove();
			Block hitBlock = null;

			while (iterator.hasNext()) {
				hitBlock = iterator.next();

				if (hitBlock.getType() != Material.AIR)
					break;
			}

			if (!game.canSpleef(player, hitBlock.getLocation()))
				return;

			player.addBrokenBlock(hitBlock);
			world.playSound(hitBlock.getLocation(), Sound.CHICKEN_EGG_POP, 0.7F, 1.0F);
			FuzzyReflection.playMobSpellEffect(hitBlock.getLocation().clone().add(0.5, 0.8, 0.5), 100, 0);
			hitBlock.setType(Material.AIR);
		}
	}