Пример #1
0
  @Override
  public void shoot(PlayerInteractEvent event) {
    if (event.getMaterial() == null) return;
    final List<String> itemLore = event.getItem().getItemMeta().getLore();

    if (WeaponWatch.durability.get(itemLore) == null) WeaponWatch.durability.put(itemLore, 4);
    if (WeaponWatch.durability.get(itemLore) == 0) return;
    if (WeaponWatch.cooldown.contains(itemLore)) return;

    if (shotsLeft.get(itemLore) != null && shotsLeft.get(itemLore) == 0) {
      WeaponWatch.cooldown.add(itemLore);
      shotsLeft.remove(itemLore);
      new BukkitRunnable() {
        @Override
        public void run() {
          WeaponWatch.durability.put(itemLore, WeaponWatch.durability.get(itemLore) - 1);
          WeaponWatch.cooldown.remove(itemLore);
        }
      }.runTaskLater(DuckMain.getPlugin(), 80);
    }

    int shotsPerRound = 6; // @Balancing: Specify shots per round here

    if (shotsLeft.get(itemLore) == null) shotsLeft.put(itemLore, shotsPerRound);
    else shotsLeft.put(itemLore, shotsLeft.get(itemLore) - 1);

    DuckMain.getWorld().playSound(event.getPlayer().getLocation(), Sound.ENTITY_BLAZE_HURT, 10, 1);
    Arrow a =
        event
            .getPlayer()
            .launchProjectile(Arrow.class, event.getPlayer().getLocation().getDirection());
    a.setShooter(event.getPlayer());
    a.setVelocity(a.getVelocity().multiply(6));
    a.setCustomName("MachineGun");
  }
 @Override
 public void run() {
   Arrow shot = player.launchProjectile(Arrow.class);
   shot.setVelocity(shot.getVelocity().multiply(2.0));
 }
Пример #3
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);
		}
	}