public ItemProjectile(Player caster, float power) {
      this.caster = caster;
      this.power = power;
      Location location = caster.getEyeLocation().add(0, yOffset, 0);
      location.setPitch(0f);
      if (vertSpeedUsed) {
        vel = caster.getLocation().getDirection().setY(0).multiply(speed).setY(vertSpeed);
      } else {
        vel = caster.getLocation().getDirection().multiply(speed);
      }
      entity = caster.getWorld().dropItem(location, item.clone());
      MagicSpells.getVolatileCodeHandler().setGravity(entity, projectileHasGravity);
      playSpellEffects(EffectPosition.PROJECTILE, entity);
      playTrackingLinePatterns(
          EffectPosition.DYNAMIC_CASTER_PROJECTILE_LINE,
          caster.getLocation(),
          entity.getLocation(),
          caster,
          entity);
      entity.teleport(location);
      entity.setPickupDelay(1000000);
      entity.setVelocity(vel);

      taskId = MagicSpells.scheduleRepeatingTask(this, 3, 3);
    }
 @EventHandler
 public void onInteract(PlayerInteractEvent pie) {
   if (pie.getAction().equals(Action.RIGHT_CLICK_BLOCK)
       || pie.getAction().equals(Action.RIGHT_CLICK_AIR)) {
     Player player = pie.getPlayer();
     World world = player.getWorld();
     if (player.getInventory().getItemInHand() != null) {
       ItemStack item = player.getInventory().getItemInHand();
       if (item.getType().equals(Material.DOUBLE_PLANT)) {
         pie.setCancelled(true);
         Item bomb = world.dropItem(player.getEyeLocation(), new ItemStack(Material.GOLD_BLOCK));
         bomb.setPickupDelay(Integer.MAX_VALUE);
         bomb.setVelocity(player.getLocation().getDirection().multiply(0.5));
         double radius = 1.5;
         for (double i = 0; i <= 20D; i += 0.1) {
           Item coin = world.dropItem(bomb.getLocation(), new ItemStack(Material.DOUBLE_PLANT));
           double x = Math.sin(radius * i);
           double z = Math.cos(radius * i);
           Bukkit.getScheduler()
               .scheduleSyncDelayedTask(
                   Factions.instance,
                   new Runnable() {
                     public void run() {}
                   },
                   1);
         }
       }
     }
   }
 }
 @Override
 void onUpdate() {
   final Item ITEM =
       ent.getWorld()
           .dropItem(
               ((Sheep) ent).getEyeLocation(),
               ItemFactory.create(
                   Material.WOOL, (byte) r.nextInt(017), UUID.randomUUID().toString()));
   ITEM.setPickupDelay(30000);
   ITEM.setVelocity(
       new Vector(r.nextDouble() - 0.5, r.nextDouble() / 2.0 + 0.3, r.nextDouble() - 0.5)
           .multiply(0.4));
   items.add(ITEM);
   Bukkit.getScheduler()
       .runTaskLater(
           Core.getPlugin(),
           new Runnable() {
             @Override
             public void run() {
               ITEM.remove();
               items.remove(ITEM);
             }
           },
           5);
 }
 @Override
 void onInteractRightClick() {
   getPlayer().playSound(getPlayer().getLocation(), Sound.EXPLODE, 1, 1);
   Item item =
       getPlayer()
           .getWorld()
           .dropItem(
               getPlayer().getEyeLocation(),
               ItemFactory.create(Material.MELON_BLOCK, (byte) 0x0, UUID.randomUUID().toString()));
   item.setPickupDelay(0);
   item.setVelocity(getPlayer().getEyeLocation().getDirection().multiply(1.3d));
   melonBlocks.add(item);
 }
  @EventHandler
  public void onPlayerMonkeyBomb(PlayerInteractEvent event) {
    if (!(event.getAction().equals(Action.RIGHT_CLICK_AIR))
        || !(event.getAction().equals(Action.RIGHT_CLICK_AIR))) {
      return;
    }
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
      if (event.getClickedBlock().getType().equals(Material.SIGN)
          || event.getClickedBlock().getType().equals(Material.SIGN_POST)
          || event.getClickedBlock().getType().equals(Material.WALL_SIGN)) {
        return;
      }
    }
    final Player player = event.getPlayer();
    if (plugin.manager.isPlayerInGame(player)) {
      Game game = plugin.manager.getGame(player);
      if (!(game.mode == ArenaStatus.INGAME)) {
        return;
      }
      if (player.getItemInHand().getType().equals(Material.MAGMA_CREAM)) {
        player.getInventory().removeItem(new ItemStack(Material.MAGMA_CREAM, 1));
        final Item item =
            player
                .getWorld()
                .dropItemNaturally(player.getEyeLocation(), new ItemStack(Material.MAGMA_CREAM));
        // Location Iloc = item.getLocation();
        item.setVelocity(player.getLocation().getDirection().multiply(1));
        item.setPickupDelay(1000);
        /*for(Entity e: game.spawnManager.mobs)
        {

        }*/
        Bukkit.getScheduler()
            .scheduleSyncDelayedTask(
                plugin,
                new Runnable() {
                  @Override
                  public void run() {
                    Location loc = item.getLocation();
                    player
                        .getWorld()
                        .createExplosion(loc.getX(), loc.getY(), loc.getZ(), 4.0F, false, false);
                    item.remove();
                  }
                },
                140);
      }
    }
  }
Example #6
0
 public static void attemptSecond(Player p) {
   if (cooldown2.containsKey(p.getName())) {
     p.sendMessage(
         ChatColor.RED
             + "Cooldown: "
             + ChatColor.YELLOW
             + cooldown2.get(p.getName())
             + ChatColor.RED
             + ".");
     return;
   }
   cooldown2.put(p.getName(), 2.0);
   Item i =
       p.getWorld().dropItem(p.getLocation().clone().add(0, 1.8, 0), new ItemStack(Material.TNT));
   i.setPickupDelay(1000);
   i.setVelocity(p.getLocation().getDirection().multiply(0.7));
   Game.playSound(Sound.FIZZ, p.getLocation(), 0.6f, 0.3f);
   tnts.add(i.getUniqueId());
 }
Example #7
0
  public static void itemToRemove(
      Location l, Material tipo, byte id, long tempoToRemove, boolean randomVector, Vector vector) {
    final ItemStack item = new ItemStack(tipo, 1, id);

    final Item drop = l.getWorld().dropItem(l, item);
    drop.setPickupDelay(Integer.MAX_VALUE);
    if (randomVector) {
      drop.setVelocity(vector);
    }
    Bukkit.getScheduler()
        .scheduleSyncDelayedTask(
            plugin,
            new Runnable() {

              @Override
              public void run() {
                drop.remove();
              }
            },
            tempoToRemove * 20);
  }
 @Override
 public PostCastAction castSpell(Player player, SpellCastState state, float power, String[] args) {
   if (state == SpellCastState.NORMAL) {
     if (projectileClass != null) {
       Projectile projectile = player.launchProjectile(projectileClass);
       playSpellEffects(EffectPosition.PROJECTILE, projectile);
       playTrackingLinePatterns(
           EffectPosition.DYNAMIC_CASTER_PROJECTILE_LINE,
           player.getLocation(),
           projectile.getLocation(),
           player,
           projectile);
       projectile.setBounce(false);
       MagicSpells.getVolatileCodeHandler().setGravity(projectile, projectileHasGravity);
       if (velocity > 0) {
         projectile.setVelocity(player.getLocation().getDirection().multiply(velocity));
       }
       if (horizSpread > 0 || vertSpread > 0) {
         Vector v = projectile.getVelocity();
         v.add(
             new Vector(
                 (random.nextDouble() - .5) * horizSpread,
                 (random.nextDouble() - .5) * vertSpread,
                 (random.nextDouble() - .5) * horizSpread));
         projectile.setVelocity(v);
       }
       if (applySpellPowerToVelocity) {
         projectile.setVelocity(projectile.getVelocity().multiply(power));
       }
       projectile.setMetadata(
           METADATA_KEY,
           new FixedMetadataValue(MagicSpells.plugin, "ProjectileSpell_" + internalName));
       projectiles.put(
           projectile,
           new ProjectileInfo(
               player,
               power,
               (effectInterval > 0 ? new RegularProjectileMonitor(projectile) : null)));
       playSpellEffects(EffectPosition.CASTER, projectile);
     } else if (projectileItem != null) {
       Item item = player.getWorld().dropItem(player.getEyeLocation(), projectileItem.clone());
       MagicSpells.getVolatileCodeHandler().setGravity(item, projectileHasGravity);
       Vector v = player.getLocation().getDirection().multiply(velocity > 0 ? velocity : 1);
       if (horizSpread > 0 || vertSpread > 0) {
         v.add(
             new Vector(
                 (random.nextDouble() - .5) * horizSpread,
                 (random.nextDouble() - .5) * vertSpread,
                 (random.nextDouble() - .5) * horizSpread));
       }
       if (applySpellPowerToVelocity) {
         v.multiply(power);
       }
       item.setVelocity(v);
       item.setPickupDelay(10);
       itemProjectiles.put(
           item, new ProjectileInfo(player, power, new ItemProjectileMonitor(item)));
       playSpellEffects(EffectPosition.CASTER, item);
     }
   }
   return PostCastAction.HANDLE_NORMALLY;
 }
Example #9
0
 @Override
 public void run() {
   try {
     while (this.plugin.buffer.size() > 0) {
       final Item item = this.plugin.buffer.pollFirstEntry().getValue();
       if (item.isValid()) {
         final Location cauldronLoc = item.getLocation().getBlock().getLocation().clone();
         if (this.plugin.magicBenches.contains(cauldronLoc)) { // So now we act !
           final ItemStack itemStack = item.getItemStack();
           if (itemStack.getEnchantments().size() != 0) {
             final Result res =
                 this.plugin.randomizer.randomize(itemStack); // The itemStack/item is now modified
             byte data = 0; // Wool color
             float ratio = 1f; // Volume & pitch of thunder sound
             switch (res) {
               case CLEAN:
                 data = 15; // Black
                 ratio = 0.2f;
                 break;
               case LOSS:
                 data = 14; // Red
                 ratio = 0.4f;
                 break;
               case NONE:
                 data = 0; // White
                 ratio = 0.6f;
                 break;
               case BOOST:
                 data = 4; // Yellow
                 ratio = 0.8f;
                 break;
               case OVERBOOST:
                 data = 5; // Green
                 ratio = 1f;
                 break;
             }
             this.plugin.magicBenches.remove(cauldronLoc);
             cauldronLoc
                 .getWorld()
                 .playSound(cauldronLoc, Sound.AMBIENCE_THUNDER, ratio, ratio * 2f);
             cauldronLoc.subtract(0, 1, 0); // Is now Egg location
             cauldronLoc.getWorld().playEffect(item.getLocation(), Effect.ENDER_SIGNAL, 0);
             if (cauldronLoc.getBlock().getType() != Material.DRAGON_EGG) {
               // Prevent possible cheat : if the player remove the egg before this happen, we
               // remove every enchants
               // As the interact event is cancelled in ME_Listener, this should never happen.
               for (final Enchantment e : itemStack.getEnchantments().keySet()) {
                 itemStack.removeEnchantment(e);
               }
               cauldronLoc.getWorld().playSound(cauldronLoc, Sound.ENDERDRAGON_DEATH, 1.0f, 1.5f);
             }
             cauldronLoc.getBlock().setType(Material.AIR); // Delete the Egg
             this.plugin.fakeWool(
                 cauldronLoc,
                 data,
                 this.plugin.getNearbyPlayers(item, 10, 5, 10)); // Wool color effect
           }
         }
       }
       if (item.isValid()) {
         item.setPickupDelay(0);
       }
     }
   } catch (final Exception e) {
     e.printStackTrace();
   }
 }