Ejemplo n.º 1
0
  protected void triggersign(TriggerType type, Object args) {
    InputState is = this.getInput(1, (BlockRedstoneEvent) args);

    if (is == InputState.HIGH && !lastState) {
      lastState = true;

      Vector v =
          new Vector(
              to.getBlockX() - from.getBlockX(),
              to.getBlockY() - from.getBlockY(),
              to.getBlockZ() - from.getBlockZ());

      v.normalize();

      v.multiply(speed);

      while (from.getBlock().getType() != Material.AIR) {
        from = from.toVector().add(v.clone().normalize().multiply(.2)).toLocation(this.getWorld());
      }

      for (int i = 0; i < arrows; i++) {

        Arrow a = this.getWorld().spawn(from, Arrow.class);
        a.setVelocity(v.clone().add(getVariance(variance)));
        this.main.cleaner.register(a, 5000);
      }

      this.getWorld().playEffect(from, org.bukkit.Effect.BOW_FIRE, 0);
    } else if ((is == InputState.LOW || is == InputState.DISCONNECTED) && lastState) {
      lastState = false;
    } else {
      return;
    }
  }
Ejemplo n.º 2
0
  @Override
  public boolean onDamageOther(EntityDamageByEntityEvent e, Player p, int level) {
    if (e.getEntity() instanceof LivingEntity) {
      LivingEntity le = (LivingEntity) e.getEntity();

      try {
        fireworks.playFirework(
            le.getWorld(),
            le.getLocation(),
            FireworkEffect.builder().with(Type.BURST).withColor(Color.WHITE).build());
      } catch (Exception ex) {
        Logger.getLogger(Burst.class.getName()).log(Level.SEVERE, null, ex);
      }

      Vector unitVector =
          le.getLocation().toVector().subtract(e.getDamager().getLocation().toVector()).normalize();

      unitVector.setY(0.55 / level);

      le.setVelocity(unitVector.multiply(level * 2));

      e.setCancelled(true);

      return true;
    }
    return false;
  }
Ejemplo n.º 3
0
  @Override
  protected void magicSpellTriggered(RaCPlayer player, TraitResults result) {
    LivingEntity pushbackEntity = SearchEntity.inLineOfSight(30, player.getPlayer());

    if (pushbackEntity != null && EnemyChecker.areEnemies(player.getPlayer(), pushbackEntity)) {

      String targetName =
          pushbackEntity.getType() == EntityType.PLAYER
              ? ((Player) pushbackEntity).getName()
              : pushbackEntity.getType().name();

      LanguageAPI.sendTranslatedMessage(player, Keys.trait_pushaway_success, "target", targetName);

      Vector playerVector = player.getLocation().getDirection();
      if (up) {
        playerVector.copy(new Vector());
        playerVector.setY(blocks);
      } else {
        playerVector.setY(0);
        playerVector.multiply(this.blocks);
        playerVector.setY(0.2);
      }

      if (targetParticles != null)
        Vollotile.get().sendOwnParticleEffectToAll(targetParticles, pushbackEntity.getLocation());
      pushbackEntity.setVelocity(playerVector);

      result.setTriggered(true);
      return;
    }

    result.setTriggered(false);
    return;
  }
Ejemplo n.º 4
0
  /**
   * Divide the {@link Cube} into 8 equal subcubes.
   *
   * @return An array containing 8 equal subcubes.
   */
  public Cube[] divide() {
    // Extract world and determine the size of 1/8 the current cube.
    World world = point.getWorld();
    Vector half = size.clone();
    half.multiply(0.5);

    // Extract the x, y, and z coords of the start point.
    double x = point.getX();
    double y = point.getY();
    double z = point.getZ();

    // Generate the 8 subcubes.
    Cube[] cubes = new Cube[8];
    cubes[0] = new Cube(new Location(world, x, y, z), half);
    cubes[1] = new Cube(new Location(world, x + half.getX(), y, z), half);

    cubes[2] = new Cube(new Location(world, x, y + half.getY(), z), half);
    cubes[3] = new Cube(new Location(world, x + half.getX(), y + half.getY(), z), half);

    cubes[4] = new Cube(new Location(world, x, y, z + half.getZ()), half);
    cubes[5] = new Cube(new Location(world, x + half.getX(), y, z + half.getZ()), half);

    cubes[6] = new Cube(new Location(world, x, y + half.getY(), z + half.getZ()), half);
    cubes[7] =
        new Cube(new Location(world, x + half.getX(), y + half.getY(), z + half.getZ()), half);

    return cubes;
  }
Ejemplo n.º 5
0
  private void calculateRay(int ox, int oy, int oz, Collection<BlockVector> result) {
    double x = ox / 7.5 - 1;
    double y = oy / 7.5 - 1;
    double z = oz / 7.5 - 1;
    Vector direction = new Vector(x, y, z);
    direction.normalize();
    direction.multiply(0.3f); // 0.3 blocks away with each step

    Location current = location.clone();

    float currentPower = calculateStartPower();

    while (currentPower > 0) {
      GlowBlock block = world.getBlockAt(current);

      if (block.getType() != Material.AIR) {
        double blastDurability = getBlastDurability(block) / 5d;
        blastDurability += 0.3F;
        blastDurability *= 0.3F;
        currentPower -= blastDurability;

        if (currentPower > 0) {
          result.add(new BlockVector(block.getX(), block.getY(), block.getZ()));
        }
      }

      current.add(direction);
      currentPower -= 0.225f;
    }
  }
Ejemplo n.º 6
0
  public void teleport(final Vehicle vehicle) {
    Location traveller =
        new Location(
            this.world,
            vehicle.getLocation().getX(),
            vehicle.getLocation().getY(),
            vehicle.getLocation().getZ());
    Location exit = getExit(traveller);

    double velocity = vehicle.getVelocity().length();

    // Stop and teleport
    vehicle.setVelocity(new Vector());

    // Get new velocity
    final Vector newVelocity = new Vector();
    switch ((int) id.getBlock().getData()) {
      case 2:
        newVelocity.setZ(-1);
        break;
      case 3:
        newVelocity.setZ(1);
        break;
      case 4:
        newVelocity.setX(-1);
        break;
      case 5:
        newVelocity.setX(1);
        break;
    }
    newVelocity.multiply(velocity);

    final Entity passenger = vehicle.getPassenger();
    if (passenger != null) {
      final Vehicle v = exit.getWorld().spawn(exit, vehicle.getClass());
      vehicle.eject();
      vehicle.remove();
      passenger.teleport(exit);
      Stargate.server
          .getScheduler()
          .scheduleSyncDelayedTask(
              Stargate.stargate,
              new Runnable() {
                public void run() {
                  v.setPassenger(passenger);
                  v.setVelocity(newVelocity);
                }
              },
              1);
    } else {
      Vehicle mc = exit.getWorld().spawn(exit, vehicle.getClass());
      if (mc instanceof StorageMinecart) {
        StorageMinecart smc = (StorageMinecart) mc;
        smc.getInventory().setContents(((StorageMinecart) vehicle).getInventory().getContents());
      }
      mc.setVelocity(newVelocity);
      vehicle.remove();
    }
  }
Ejemplo n.º 7
0
  public void manageAirVectors() {
    for (int i = 0; i < tasks.size(); i++) {
      if (((FireComboStream) tasks.get(i)).isCancelled()) {
        tasks.remove(i);
        i--;
      }
    }
    if (tasks.size() == 0) {
      remove();
      return;
    }
    for (int i = 0; i < tasks.size(); i++) {
      FireComboStream fstream = (FireComboStream) tasks.get(i);
      Location loc = fstream.getLocation();

      if (GeneralMethods.isRegionProtectedFromBuild(this, loc)) {
        fstream.remove();
        return;
      }

      if (!isTransparent(loc.getBlock())) {
        if (!isTransparent(loc.clone().add(0, 0.2, 0).getBlock())) {
          fstream.remove();
          return;
        }
      }
      if (i % 3 == 0) {
        for (Entity entity : GeneralMethods.getEntitiesAroundPoint(loc, 2.5)) {
          if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) {
            remove();
            return;
          }
          if (!entity.equals(player) && !affectedEntities.contains(entity)) {
            affectedEntities.add(entity);
            if (knockback != 0) {
              Vector force = fstream.getDirection();
              entity.setVelocity(force.multiply(knockback));
            }
            if (damage != 0) {
              if (entity instanceof LivingEntity) {
                if (fstream.getAbility().equalsIgnoreCase("AirSweep")) {
                  DamageHandler.damageEntity(entity, damage, this);
                } else {
                  DamageHandler.damageEntity(entity, damage, this);
                }
              }
            }
          }
        }

        if (GeneralMethods.blockAbilities(player, FireCombo.getBlockableAbilities(), loc, 1)) {
          fstream.remove();
        } else AirAbility.removeAirSpouts(loc, player);
        WaterAbility.removeWaterSpouts(loc, player);
        EarthAbility.removeSandSpouts(loc, player);
      }
    }
  }
Ejemplo n.º 8
0
 @EventHandler
 public void onChat(AsyncPlayerChatEvent event) {
   Player player = event.getPlayer();
   String message = event.getMessage();
   if (message.equalsIgnoreCase("test")) {
     event.setCancelled(true);
     player.sendMessage(message);
     Vector vector = getPlayerVector(player);
     // player.setVelocity(vector.multiply(2));
     player.launchProjectile(Fireball.class).setVelocity(vector.multiply(5));
   }
 }
Ejemplo n.º 9
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void EnterCart(final VehicleEnterEvent event) {
    Entity e = event.getVehicle(); // get the vehicle
    Vector dir =
        event
            .getEntered()
            .getLocation()
            .getDirection(); // get who entered it and what direction they were looking

    if (e instanceof Minecart) {
      e.setVelocity(dir.multiply(1));
    }
  }
Ejemplo n.º 10
0
 public static void checkSecond() {
   for (Item i : Bukkit.getWorld("PrisonMap").getEntitiesByClass(Item.class)) {
     if (tnts.contains(i.getUniqueId())) {
       ParticleEffect.SMOKE_NORMAL.display(
           0.25f, 0.25f, 0.25f, 0.0001f, 5, i.getLocation().clone().add(0, 0.5, 0), 100);
       if (i.getTicksLived() > 30) {
         ParticleEffect.EXPLOSION_HUGE.display(
             0.5f, 0.5f, 0.5f, 0.1f, 5, i.getLocation().clone().add(0, 1, 0), 100);
         for (Entity e : i.getNearbyEntities(3.5, 3.5, 3.5)) {
           if (e instanceof Player) {
             Location midPoint = i.getLocation();
             Vector direction =
                 e.getLocation().toVector().subtract(midPoint.toVector()).normalize();
             direction.multiply(1.1).setY(0.7);
             e.setVelocity(direction);
             ((Player) e).damage(0.0);
           }
         }
         final List<Location> blocks = new ArrayList<Location>();
         int radius = 3;
         int bX = i.getLocation().getBlockX();
         int bY = i.getLocation().getBlockY();
         int bZ = i.getLocation().getBlockZ();
         for (int x = bX - radius; x <= bX + radius; x++) {
           for (int y = bY - radius; y <= bY + radius; y++) {
             for (int z = bZ - radius; z <= bZ + radius; z++) {
               double distance =
                   ((bX - x) * (bX - x) + ((bZ - z) * (bZ - z)) + ((bY - y) * (bY - y)));
               if (distance < radius * radius) {
                 Location loc = new Location(i.getWorld(), x, y, z);
                 if (loc.getBlock().getType() != Material.AIR) {
                   blocks.add(loc);
                 }
               }
             }
           }
         }
         for (Location loc : blocks) {
           Random r = new Random();
           int i1 = r.nextInt(3) + 1;
           if (Game.isBreakable(loc.getBlock().getType()) && (i1 == 1 || i1 == 2)) {
             loc.getBlock().setType(Material.AIR);
           }
         }
         Game.playSound(Sound.EXPLODE, i.getLocation(), 1f, 1f);
         tnts.remove(i.getUniqueId());
         i.teleport(i.getLocation().subtract(0, 500, 0));
       }
     }
   }
 }
Ejemplo n.º 11
0
 @Override
 public void run() {
   if (Bukkit.getPlayer(uuid) == null) Bukkit.getScheduler().cancelTask(id);
   else if (Bukkit.getPlayer(uuid).isDead()) Bukkit.getScheduler().cancelTask(id);
   else if (!Bukkit.getPlayer(uuid).isSneaking()) Bukkit.getScheduler().cancelTask(id);
   else {
     Player p = Bukkit.getPlayer(uuid);
     Vector vector = new Vector(0, 1, 0);
     vector.multiply(-0.1);
     p.setVelocity(vector);
     p.setFallDistance(0.0f);
     if (!p.isSneaking()) Bukkit.getScheduler().cancelTask(id);
   }
 }
Ejemplo n.º 12
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onPlayerMove(PlayerMoveEvent event) {
    ZoneManager manager = m_plugin.getZoneManager();
    Zone fromZone = manager.getZone(event.getFrom());
    Zone toZone = manager.getZone(event.getTo());
    if (toZone != null) {
      if (!toZone.canPlayerMove(event.getPlayer())) {
        Vector direction =
            event.getFrom().toVector().subtract(event.getTo().toVector()).normalize();
        event.getPlayer().setVelocity(direction.multiply(2));
        sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoMove"));
        return;
      }
    }

    if (event.getTo().equals(event.getFrom())) {
      return;
    }

    if ((fromZone == null && toZone != null)
        || (fromZone != null && toZone != null && !fromZone.getName().equals(toZone.getName()))) {
      event.getPlayer().sendMessage(toZone.getEnterMessage());
    } else if ((toZone == null && fromZone != null)
        || (fromZone != null && toZone != null && !toZone.getName().equals(fromZone.getName()))) {
      event.getPlayer().sendMessage(fromZone.getExitMessage());
    }

    if (toZone != null && fromZone != null) {
      if (toZone.getName() == fromZone.getName()) {
        Plot toPlot = toZone.getPlot(event.getTo());
        Plot fromPlot = fromZone.getPlot(event.getFrom());

        if ((fromPlot == null && toPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !fromPlot.getName().equals(toPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow entering plot \u00A7c" + toPlot.getName());
        } else if ((toPlot == null && fromPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !toPlot.getName().equals(fromPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow leaving plot \u00A7c" + fromPlot.getName());
        }
      }
    }
  }
Ejemplo n.º 13
0
    @EventHandler
    public void onCustomEvent(ToPlayerInRegionEvent event) {
      Location l = event.getLocation();
      RegionManager rm = getPlugin().getRegionManager();
      Region r = rm.getRegion(l);
      if (r == null) return;
      RegionType rt = rm.getRegionType(r.getType());

      int jumpMult = effect.regionHasEffect(rt.getEffects(), "man_cannon");

      // Check if the region is a teleporter
      if (jumpMult == 0) return;

      // Check to see if the Townships has enough reagents
      if (!effect.hasReagents(l)) {
        return;
      }

      // Run upkeep but don't need to know if upkeep occured
      effect.forceUpkeep(event);

      // Launch the player into the air
      Player player = event.getPlayer();
      float pitch = player.getEyeLocation().getPitch();
      int jumpForwards = 1;
      if (pitch > 45) {
        jumpForwards = 1;
      }
      if (pitch > 0) {
        pitch = -pitch;
      }
      float multiplier = ((90f + pitch) / 50f);
      Vector v =
          player
              .getVelocity()
              .setY(1)
              .add(
                  player
                      .getLocation()
                      .getDirection()
                      .setY(0)
                      .normalize()
                      .multiply(multiplier * jumpForwards));
      NCPExemptionManager.exemptPermanently(player, CheckType.MOVING);
      player.setVelocity(v.multiply(jumpMult));
      player.setFallDistance(-8f * jumpMult);
      NCPExemptionManager.unexempt(player, CheckType.MOVING);
    }
Ejemplo n.º 14
0
  private Collection<GlowPlayer> damageEntities() {
    float power = this.power;
    this.power *= 2f;

    Collection<GlowPlayer> affectedPlayers = new ArrayList<>();

    Collection<GlowLivingEntity> entities = getNearbyEntities();
    for (GlowLivingEntity entity : entities) {
      double disDivPower = distanceTo(entity) / (double) this.power;
      if (disDivPower > 1.0D) continue;

      Vector vecDistance = distanceToHead(entity);
      if (vecDistance.length() == 0.0) continue;

      vecDistance.normalize();

      double basicDamage = calculateDamage(entity, disDivPower);
      int explosionDamage =
          (int) ((basicDamage * basicDamage + basicDamage) * 4 * (double) power + 1.0D);

      if (!(entity instanceof GlowHumanEntity)) {
        EntityDamageEvent.DamageCause damageCause;
        if (source == null || source.getType() == EntityType.PRIMED_TNT) {
          damageCause = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
        } else {
          damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;
        }
        entity.damage(explosionDamage, source, damageCause);
      }

      double enchantedDamage = calculateEnchantedDamage(basicDamage, entity);
      vecDistance.multiply(enchantedDamage);

      Vector currentVelocity = entity.getVelocity();
      currentVelocity.add(vecDistance);
      entity.setVelocity(currentVelocity);

      if (entity instanceof GlowPlayer) {
        affectedPlayers.add((GlowPlayer) entity);
      }
    }

    this.power = power;

    return affectedPlayers;
  }
  public boolean advance() {
    Vector dir = loc.getDirection();
    dir.add(new Vector(0.0f, -0.008, 0.0f)); // Apply 'gravity'	
    loc.setDirection(dir);

    loc.add(dir.multiply(speed));
    loc.getWorld().createExplosion(loc, 0.0f, false);

    if (ItemManager.getId(loc.getBlock()) != CivData.AIR) {
      return true;
    }

    if (loc.distance(startLoc) > maxRange) {
      return true;
    }

    return false;
  }
Ejemplo n.º 16
0
 public static void checkThird() {
   for (Player p : Bukkit.getOnlinePlayers()) {
     if (Game.playerInGame(p) && ultimate.contains(p.getName())) {
       if (p.getLocation().clone().subtract(0, 1, 0).getBlock().getType() != Material.AIR) {
         int radius = 4;
         int bX = p.getLocation().getBlockX();
         int bY = p.getLocation().getBlockY();
         int bZ = p.getLocation().getBlockZ();
         for (int x = bX - radius; x <= bX + radius; x++) {
           for (int y = bY - radius; y <= bY + radius; y++) {
             for (int z = bZ - radius; z <= bZ + radius; z++) {
               double distance =
                   ((bX - x) * (bX - x) + ((bZ - z) * (bZ - z)) + ((bY - y) * (bY - y)));
               if (distance < radius * radius && !(distance < ((radius - 1) * (radius - 1)))) {
                 Location loc = new Location(p.getWorld(), x, y, z);
                 if (Game.isBreakable(loc.getBlock().getType())) {
                   ParticleEffect.EXPLOSION_LARGE.display(
                       0.1f, 0.1f, 0.1f, 0.1f, 3, loc.clone().add(0, 0.2, 0), 100);
                 }
               }
             }
           }
         }
         for (Entity e : p.getNearbyEntities(3, 2, 3)) {
           if (e instanceof Player) {
             Location midPoint = p.getLocation();
             Vector direction =
                 e.getLocation().toVector().subtract(midPoint.toVector()).normalize();
             direction.multiply(0.5).setY(0.3);
             e.setVelocity(direction);
             ((Player) e).damage(0.0);
           }
         }
       }
     }
   }
 }
Ejemplo n.º 17
0
  public void onRun() {
    Location location = getLocation();
    // Lines
    int mL = RandomUtils.random.nextInt(maxLines - 2) + 2;
    for (int m = 0; m < mL * 2; m++) {
      double x = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
      double y = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
      double z = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
      if (direction == Direction.DOWN) y = RandomUtils.random.nextInt(max * 2 - max) + max;
      else if (direction == Direction.UP)
        y = RandomUtils.random.nextInt(max * (-1) - max * (-2)) + max * (-2);
      Location target = location.clone().subtract(x, y, z);
      if (target == null) {
        cancel();
        return;
      }
      Vector link = target.toVector().subtract(location.toVector());
      float length = (float) link.length();
      link.normalize();

      float ratio = length / lineParticles;
      Vector v = link.multiply(ratio);
      Location loc = location.clone().subtract(v);
      for (int i = 0; i < lineParticles; i++) {
        loc.add(v);
        display(lineParticle, loc, lineColor);
      }
    }

    // Sphere
    for (int i = 0; i < sphereParticles; i++) {
      Vector vector = RandomUtils.getRandomVector().multiply(sphereRadius);
      location.add(vector);
      display(sphereParticle, location, sphereColor);
      location.subtract(vector);
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location =
                    TFM_DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = TFM_DepreciationAggregator.getTargetBlock(player, null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock =
                    TFM_DepreciationAggregator.getTargetBlock(
                        player, null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }

            case RAW_FISH:
              {
                final int RADIUS_HIT = 5;
                final int STRENGTH = 4;

                // Clownfish
                if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData())
                    == 2) {
                  if (TFM_AdminList.isSeniorAdmin(player, true)
                      || TFM_AdminList.isTelnetAdmin(player, true)) {
                    boolean didHit = false;

                    final Location playerLoc = player.getLocation();
                    final Vector playerLocVec = playerLoc.toVector();

                    final List<Player> players = player.getWorld().getPlayers();
                    for (final Player target : players) {
                      if (target == player) {
                        continue;
                      }

                      final Location targetPos = target.getLocation();
                      final Vector targetPosVec = targetPos.toVector();

                      try {
                        if (targetPosVec.distanceSquared(playerLocVec)
                            < (RADIUS_HIT * RADIUS_HIT)) {
                          TFM_Util.setFlying(player, false);
                          target.setVelocity(
                              targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
                          didHit = true;
                        }
                      } catch (IllegalArgumentException ex) {
                      }
                    }

                    if (didHit) {
                      final Sound[] sounds = Sound.values();
                      for (Sound sound : sounds) {
                        if (sound.toString().contains("HIT")) {
                          playerLoc
                              .getWorld()
                              .playSound(
                                  randomOffset(playerLoc, 5.0),
                                  sound,
                                  100.0f,
                                  randomDoubleRange(0.5, 2.0).floatValue());
                        }
                      }
                    }
                  } else {
                    final StringBuilder msg = new StringBuilder();
                    final char[] chars = (player.getName() + " is a clown.").toCharArray();
                    for (char c : chars) {
                      msg.append(TFM_Util.randomChatColor()).append(c);
                    }
                    TFM_Util.bcastMsg(msg.toString());

                    player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
                  }

                  event.setCancelled(true);
                  break;
                }
              }
          }
          break;
        }
    }
  }
Ejemplo n.º 19
0
  @EventHandler
  public void onGrapple(PlayerFishEvent event)
      throws NoSuchFieldException, SecurityException, IllegalArgumentException,
          IllegalAccessException {

    final Player player = event.getPlayer();

    // if (isIn(player, 37))
    {
      if (event.getState() == State.IN_GROUND) {

        if (hooks.containsKey(player.getName())) {

          final Location location =
              hooks
                  .get(player.getName())
                  .getLocation(); // hooks.get(player.getName()).getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR ? hooks.get(player.getName()).getLocation() : hooks.get(player.getName()).getLocation().getBlock().getRelative(BlockFace.UP).getLocation();

          if (location.getBlock().getType() == Material.AIR
              || location.getBlock().getType() == Material.SNOW) {

            // player.setVelocity(hooks.get(player.getName()).getLocation().toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector()).normalize().multiply(new Vector(2, 2, 2)));
            // Projectile fishing = player.launchProjectile(Snowball.class);
            final Vector velocity =
                location
                    .toVector()
                    .subtract(player.getLocation().subtract(0, 1, 0).toVector())
                    .normalize()
                    .multiply(new Vector(2, 2, 2));

            if (Math.abs(location.getBlockY() - player.getLocation().getBlockY()) < 2
                && location.distance(player.getLocation()) > 4) {

              player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));

              Bukkit.getServer()
                  .getScheduler()
                  .scheduleSyncDelayedTask(
                      Plugin.getPlugin(),
                      new Runnable() {

                        @Override
                        public void run() {
                          player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));
                          // player.setVelocity(location.toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector().normalize().multiply(2)));

                        }
                      },
                      1L);

            } else {

              player.setVelocity(velocity);

              Bukkit.getServer()
                  .getScheduler()
                  .scheduleSyncDelayedTask(
                      Plugin.getPlugin(),
                      new Runnable() {

                        @Override
                        public void run() {
                          player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));
                          // player.setVelocity(location.toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector().normalize().multiply(0.5)));

                        }
                      },
                      0L);
            }
            // fishing.setPassenger(player);
            // projectiles.add(fishing);
          }
        }
      }
    }
  }
  public void start() {
    game.setState(GameState.DEATHMATCH);

    List<Location> spawns = game.getCurrentArena().getDeathmatchSpawns();
    int i = 0;
    for (User user : game.getUsers()) {
      if (i >= spawns.size()) i = 0;
      user.getPlayer().teleport(spawns.get(i));
      i++;
    }

    Location suloc = spawns.get(0);
    for (SpectatorUser su : game.getSpecators()) {
      su.getPlayer().teleport(suloc);
      Vector v = new Vector(0, 2, 0);
      v.multiply(1.25);
      su.getPlayer().getLocation().setDirection(v);
    }

    task =
        Bukkit.getScheduler()
            .runTaskTimer(
                SurvivalGames.instance,
                new Runnable() {
                  public void run() {
                    if (time == 60) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout-warning"));
                    }

                    if (time % 60 == 0 && time != 0) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout")
                              .replace("%0%", Util.getFormatedTime(time)));
                    } else if (time % 10 == 0 && time < 60 && time > 10) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout")
                              .replace("%0%", Util.getFormatedTime(time)));
                    } else if (time <= 10 && time > 0) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout")
                              .replace("%0%", Util.getFormatedTime(time)));
                    } else if (time == 0) {

                      List<User> users = game.getUsers();
                      Collections.shuffle(users);

                      if (users.size() > 0) {
                        users
                            .get(0)
                            .getPlayer()
                            .addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 10000, 3));
                      }
                    }

                    game.updateBossBarMessage();
                    game.updateScoreboard();
                    time--;
                  }
                },
                0L,
                20L);
  }
Ejemplo n.º 21
0
  @Override
  public SpellResult perform(CastContext context) {
    Block targetBlock = context.getTargetBlock();
    Entity currentEntity = current == null ? null : current.get();
    current = null;
    if (currentEntity != null) {
      currentEntity.remove();
    }

    targetBlock = targetBlock.getRelative(BlockFace.UP);

    Location spawnLocation = targetBlock.getLocation();
    Location sourceLocation = context.getLocation();
    spawnLocation.setPitch(sourceLocation.getPitch());
    spawnLocation.setYaw(sourceLocation.getYaw());

    MageController controller = context.getController();
    if (entityData == null) {
      String randomType = RandomUtils.weightedRandom(entityTypeProbability);
      try {
        entityData = controller.getMob(randomType);
        if (entityData == null) {
          entityData =
              new com.elmakers.mine.bukkit.entity.EntityData(
                  EntityType.valueOf(randomType.toUpperCase()));
        }
      } catch (Throwable ex) {
        entityData = null;
      }
    }
    if (entityData == null) {
      return SpellResult.FAIL;
    }

    if (force) {
      controller.setForceSpawn(true);
    }
    Entity spawnedEntity = null;
    try {
      spawnedEntity = entityData.spawn(context.getController(), spawnLocation, spawnReason);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    if (force) {
      controller.setForceSpawn(false);
    }

    if (spawnedEntity == null) {
      return SpellResult.FAIL;
    }

    if (!loot) {
      spawnedEntity.setMetadata("nodrops", new FixedMetadataValue(controller.getPlugin(), true));
    }
    if (speed > 0) {
      Vector motion = direction;
      if (motion == null) {
        motion = context.getDirection();
      } else {
        motion = motion.clone();
      }

      if (dyOffset != 0) {
        motion.setY(motion.getY() + dyOffset);
      }
      motion.normalize();
      motion.multiply(speed);
      CompatibilityUtils.setEntityMotion(spawnedEntity, motion);
    }

    Collection<EffectPlayer> projectileEffects = context.getEffects("spawned");
    for (EffectPlayer effectPlayer : projectileEffects) {
      effectPlayer.start(spawnedEntity.getLocation(), spawnedEntity, null, null);
    }
    context.registerForUndo(spawnedEntity);

    if (track) {
      current = new WeakReference<Entity>(spawnedEntity);
    }
    if (setTarget) {
      context.setTargetEntity(spawnedEntity);
    }
    return SpellResult.CAST;
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (!TotalFreedomMod.allowWaterPlace) {
                  player
                      .getInventory()
                      .setItem(
                          player.getInventory().getHeldItemSlot(),
                          new ItemStack(Material.COOKIE, 1));
                  player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
            case LAVA_BUCKET:
              {
                if (!TotalFreedomMod.allowLavaPlace) {
                  player
                      .getInventory()
                      .setItem(
                          player.getInventory().getHeldItemSlot(),
                          new ItemStack(Material.COOKIE, 1));
                  player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
            case EXPLOSIVE_MINECART:
              {
                if (!TotalFreedomMod.allowTntMinecarts) {
                  player.getInventory().clear(player.getInventory().getHeldItemSlot());
                  player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
          }
          break;
        }
      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.mobThrowerEnabled()) {
                  Location player_pos = player.getLocation();
                  Vector direction = player_pos.getDirection().normalize();

                  LivingEntity rezzed_mob =
                      (LivingEntity)
                          player
                              .getWorld()
                              .spawnEntity(
                                  player_pos.add(direction.multiply(2.0)),
                                  playerdata.mobThrowerCreature());
                  rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                  playerdata.enqueueMob(rezzed_mob);

                  event.setCancelled(true);
                }
                break;
              }
            case SULPHUR:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.isMP44Armed()) {
                  if (playerdata.toggleMP44Firing()) {
                    playerdata.startArrowShooter(TotalFreedomMod.plugin);
                  } else {
                    playerdata.stopArrowShooter();
                  }

                  event.setCancelled(true);
                }
                break;
              }
            case BLAZE_ROD:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Block target_block;

                    if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                      target_block = player.getTargetBlock(null, 120);
                    } else {
                      target_block = event.getClickedBlock();
                    }

                    if (target_block != null) {
                      player.getWorld().createExplosion(target_block.getLocation(), 4F, true);
                      player.getWorld().strikeLightning(target_block.getLocation());
                    } else {
                      player.sendMessage("Can't resolve target block.");
                    }

                    event.setCancelled(true);
                  }
                }
                break;
              }
            case CARROT:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Location player_location = player.getLocation().clone();

                    Vector player_pos = player_location.toVector().add(new Vector(0.0, 1.65, 0.0));
                    Vector player_dir = player_location.getDirection().normalize();

                    double distance = 150.0;
                    Block target_block = player.getTargetBlock(null, Math.round((float) distance));
                    if (target_block != null) {
                      distance = player_location.distance(target_block.getLocation());
                    }

                    final List<Block> affected = new ArrayList<Block>();

                    Block last_block = null;
                    for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                      Block test_block =
                          player_pos
                              .clone()
                              .add(player_dir.clone().multiply(offset))
                              .toLocation(player.getWorld())
                              .getBlock();

                      if (!test_block.equals(last_block)) {
                        if (test_block.isEmpty()) {
                          affected.add(test_block);
                          test_block.setType(Material.TNT);
                        } else {
                          break;
                        }
                      }

                      last_block = test_block;
                    }

                    new BukkitRunnable() {
                      @Override
                      public void run() {
                        for (Block tnt_block : affected) {
                          TNTPrimed tnt_primed =
                              tnt_block.getWorld().spawn(tnt_block.getLocation(), TNTPrimed.class);
                          tnt_primed.setFuseTicks(5);
                          tnt_block.setType(Material.AIR);
                        }
                      }
                    }.runTaskLater(TotalFreedomMod.plugin, 30L);

                    event.setCancelled(true);
                  }
                }
                break;
              }
          }
          break;
        }
    }
  }
Ejemplo n.º 23
0
  public void target(TargetMode mode) {
    targetMode = mode == null ? TargetMode.STABILIZE : mode;
    switch (targetMode) {
      case FLEE:
      case HUNT:
      case DIRECTED:
        Target bestTarget = null;
        reverseTargetDistanceScore = true;
        if (targetType == TargetType.ANY || targetType == TargetType.MOB) {
          List<Entity> entities =
              CompatibilityUtils.getNearbyEntities(
                  center, huntMaxRange, huntMaxRange, huntMaxRange);
          for (Entity entity : entities) {
            // We'll get the players from the Mages list
            if (entity instanceof Player || !(entity instanceof LivingEntity) || entity.isDead())
              continue;
            if (!entity.getLocation().getWorld().equals(center.getWorld())) continue;
            LivingEntity li = (LivingEntity) entity;
            if (li.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            Target newScore =
                new Target(center, entity, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }
        if (targetType == TargetType.MAGE
            || targetType == TargetType.AUTOMATON
            || targetType == TargetType.ANY
            || targetType == TargetType.PLAYER) {
          Collection<Mage> mages = controller.getMages();
          for (Mage mage : mages) {
            if (mage == this.mage) continue;
            if (targetType == TargetType.AUTOMATON && mage.getPlayer() != null) continue;
            if (targetType == TargetType.PLAYER && mage.getPlayer() == null) continue;
            if (mage.isDead() || !mage.isOnline() || !mage.hasLocation()) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;
            if (!mage.getLocation().getWorld().equals(center.getWorld())) continue;

            if (!mage.isPlayer()) {
              // Check for automata of the same type, kinda hacky.. ?
              Block block = mage.getLocation().getBlock();
              if (block.getType() == Material.COMMAND) {
                BlockState blockState = block.getState();
                if (blockState != null && blockState instanceof CommandBlock) {
                  CommandBlock command = (CommandBlock) blockState;
                  String commandString = command.getCommand();
                  if (commandString != null
                      && commandString.length() > 0
                      && commandString.startsWith("cast " + spell.getKey())) {
                    continue;
                  }
                }
              }
            } else {
              Player player = mage.getPlayer();
              if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
            }

            Target newScore = new Target(center, mage, huntMinRange, huntMaxRange, huntFov, false);
            int score = newScore.getScore();
            if (bestTarget == null || score > bestTarget.getScore()) {
              bestTarget = newScore;
            }
          }
        }

        if (bestTarget != null) {
          String targetDescription =
              bestTarget.getEntity() == null
                  ? "NONE"
                  : ((bestTarget instanceof Player)
                      ? ((Player) bestTarget.getEntity()).getName()
                      : bestTarget.getEntity().getType().name());

          if (DEBUG) {
            controller
                .getLogger()
                .info(
                    " *Tracking "
                        + targetDescription
                        + " score: "
                        + bestTarget.getScore()
                        + " location: "
                        + center
                        + " -> "
                        + bestTarget.getLocation()
                        + " move "
                        + commandMoveRangeSquared);
          }
          Vector direction = null;

          if (targetMode == TargetMode.DIRECTED) {
            direction = bestTarget.getLocation().getDirection();
            if (DEBUG) {
              controller.getLogger().info(" *Directed: " + direction);
            }
          } else {
            Location targetLocation = bestTarget.getLocation();
            direction = targetLocation.toVector().subtract(center.toVector());
          }

          if (direction != null) {
            center.setDirection(direction);
          }

          // Check for obstruction
          // TODO Think about this more..
          /*
          Block block = spell.getInteractBlock();
          if (block.getType() != Material.AIR && block.getType() != POWER_MATERIAL && !!birthMaterial.is(block)) {
          	// TODO: Use location.setDirection in 1.7+
          	center = CompatibilityUtils.setDirection(center, new Vector(0, 1, 0));
          }
          */

          if (level != null
              && center.distanceSquared(bestTarget.getLocation()) < castRange * castRange) {
            level.onTick(mage, birthMaterial);
          }

          // After ticking, re-position for movement. This way spells still fire towards the target.
          if (targetMode == TargetMode.FLEE) {
            direction = direction.multiply(-1);
            // Don't Flee upward
            if (direction.getY() > 0) {
              direction.setY(-direction.getY());
            }
          }
        }
        break;
      case GLIDE:
        reverseTargetDistanceScore = true;
        break;
      default:
        reverseTargetDistanceScore = false;
    }
  }
  private int buildWallSegment(
      Player player,
      BlockCoord first,
      BlockCoord second,
      int blockCount,
      HashMap<String, SimpleBlock> simpleBlocks,
      int verticalSegments)
      throws CivException {
    Location locFirst = first.getLocation();
    Location locSecond = second.getLocation();

    Vector dir =
        new Vector(
            locFirst.getX() - locSecond.getX(),
            locFirst.getY() - locSecond.getY(),
            locFirst.getZ() - locSecond.getZ());
    dir.normalize();
    dir.multiply(0.5);
    HashMap<String, SimpleBlock> thisWallBlocks = new HashMap<String, SimpleBlock>();

    this.getTown().lastBuildableBuilt = null;

    getVerticalWallSegment(player, locSecond, thisWallBlocks);
    simpleBlocks.putAll(thisWallBlocks);
    verticalSegments++;

    double distance = locSecond.distance(locFirst);
    BlockCoord lastBlockCoord = new BlockCoord(locSecond);
    BlockCoord currentBlockCoord = new BlockCoord(locSecond);
    while (locSecond.distance(locFirst) > 1.0) {
      locSecond.add(dir);
      ChunkCoord coord = new ChunkCoord(locSecond);
      CivGlobal.addWallChunk(this, coord);

      currentBlockCoord.setFromLocation(locSecond);
      if (lastBlockCoord.equals(currentBlockCoord)) {
        continue;
      } else {
        lastBlockCoord.setFromLocation(locSecond);
      }

      blockCount++;
      if (blockCount > Wall.RECURSION_LIMIT) {
        throw new CivException(
            "ERROR: Building wall blocks exceeded recusion limit! Halted to keep server alive.");
      }

      getVerticalWallSegment(player, locSecond, thisWallBlocks);
      simpleBlocks.putAll(thisWallBlocks);
      verticalSegments++;

      // Distance should always be going down, as a failsave
      // check that it is. Abort if our distance goes up.
      double tmpDist = locSecond.distance(locFirst);
      if (tmpDist > distance) {
        break;
      }
    }

    /* build the last wall segment. */
    if (!wallBlocks.containsKey(new BlockCoord(locFirst))) {
      try {
        getVerticalWallSegment(player, locFirst, thisWallBlocks);
        simpleBlocks.putAll(thisWallBlocks);
        verticalSegments++;
      } catch (CivException e) {
        CivLog.warning("Couldn't build the last wall segment, oh well.");
      }
    }

    for (SimpleBlock sb : simpleBlocks.values()) {
      BlockCoord bcoord = new BlockCoord(sb);
      int old_id = ItemManager.getId(bcoord.getBlock());
      int old_data = ItemManager.getData(bcoord.getBlock());
      if (!wallBlocks.containsKey(bcoord)) {
        try {
          WallBlock wb = new WallBlock(bcoord, this, old_id, old_data, sb.getType(), sb.getData());

          wallBlocks.put(bcoord, wb);
          this.addStructureBlock(bcoord, true);
          wb.save();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
    return verticalSegments;
  }
Ejemplo n.º 25
0
  @Override
  protected void onPlayerMove(PlayerMoveEvent evt, Player P) {
    // TODO Auto-generated method stub
    super.onPlayerMove(evt, P);
    Player ply = evt.getPlayer();
    if (isSpectator(ply)) return;
    if (JocIniciat) {
      Player plyr = evt.getPlayer();

      Location to = evt.getTo();
      Location from = evt.getFrom();

      int equip = obtenirEquip(ply).getId() + 1;
      if (ply.getLocation().getY() < 102) {
        ply.setFireTicks(5000);
      }
      if (ply.getLocation().getY() < 60) {
        ply.damage(10000);
      }

      // Torres escuts
      int e = 1;
      while (e <= 2) {
        int i = 0;
        while (i <= 1) {
          Cuboid cub =
              pMapaActual()
                  .ObtenirCuboid("RegT" + Integer.toString(e) + Integer.toString(i), getWorld());
          Location center = cub.getCenter();
          if (cub.contains(to.getBlock())) {
            if (e == equip) {
              Vector vec = Utils.CrearVector(center, from).normalize().add(new Vector(0, 1, 0));
              getWorld().playSound(to, Sound.IRONGOLEM_HIT, 1F, 2.2F);
              getWorld().playEffect(to, Effect.MOBSPAWNER_FLAMES, 3);
              getWorld()
                  .playEffect(to.clone().add(new Vector(0, 1, 0)), Effect.MOBSPAWNER_FLAMES, 3);
              if (cub.contains(from.getBlock()) && plyr.getVelocity().length() >= 1) {
                plyr.teleport(from.add(vec));
                // Bukkit.broadcastMessage("ha entrat");
              } else {
                plyr.setVelocity(vec);
              }
              // evt.setCancelled(true);

            }
          }
          i = i + 1;
        }
        e = e + 1;
      }
      // SECURE NO-FALL
      //
      boolean isNoFallActive = false;

      ItemStack itemInHand = ply.getItemInHand();
      if (itemInHand.hasItemMeta()) {
        ItemMeta itemMeta = itemInHand.getItemMeta();
        if (itemMeta.hasDisplayName()) {
          if (itemMeta.getDisplayName().equals(getBridgeToolName())) {
            isNoFallActive = true;
          }
        }
      }

      if (isNoFallActive) {
        Vector v = Utils.CrearVector(evt.getFrom(), evt.getTo());
        v.multiply(1.45D);
        v.setY(0);
        Block bDown = evt.getTo().add(v).getBlock().getRelative(BlockFace.DOWN);
        if (bDown.isEmpty() && bDown.getRelative(BlockFace.DOWN).isEmpty()) {
          ItemStack placeableItemStack = getPlaceableItemStack(ply);
          if (placeableItemStack != null) {
            bDown.setType(placeableItemStack.getType());
            bDown.setData(placeableItemStack.getData().getData());
            ItemStack sampleIt = new ItemStack(placeableItemStack);
            sampleIt.setAmount(1);
            ply.getInventory().removeItem(sampleIt);
            itemInHand.setDurability((short) (itemInHand.getDurability() + 3));
          }
        }
      }
    }
  }
Ejemplo n.º 26
0
  private void getBlocking(EnderPearl pearl) {
    double gravity = 0.03F;
    try {
      if (pearl instanceof CustomNMSEntityEnderPearl)
        gravity = ((CustomNMSEntityEnderPearl) pearl).y_adjust_;
      else Bastion.getPlugin().getLogger().info("Humbug not found");

    } catch (NoClassDefFoundError e) {
      Bastion.getPlugin().getLogger().info("Humbug not found");
    }

    Vector speed = pearl.getVelocity();
    Vector twoDSpeed = speed.clone();
    twoDSpeed.setY(0);

    double horizontalSpeed = getLengthSigned(twoDSpeed);
    double verticalSpeed = speed.getY();

    Location loc = pearl.getLocation();

    double maxTicks = getMaxTicks(verticalSpeed, loc.getY(), -gravity);
    double maxDistance = getMaxDistance(horizontalSpeed, maxTicks);

    // check if it has any possibility of going through a bastion
    if (!(maxDistance > Bastion.getConfigManager().getBastionBlockEffectRadius() / 2
        || maxDistance < -1)) {
      return;
    }

    Player threw = null;
    if (pearl.getShooter() instanceof Player) {
      threw = (Player) pearl.getShooter();
    }

    Set<BastionBlock> possible =
        bastions.getPossibleTeleportBlocking(
            pearl.getLocation(), maxDistance); // all the bastion blocks within range of the pearl

    // no need to do anything if there aren't any bastions to run into.
    if (possible.isEmpty()) {
      return;
    }

    Location start = pearl.getLocation();
    Location end = start.clone();
    end.add(twoDSpeed.multiply(maxTicks));

    Set<BastionBlock> couldCollide =
        simpleCollide(
            possible,
            start.clone(),
            end.clone(),
            threw); // all the bastions where the pearl passes over or under their shadow

    if (couldCollide.isEmpty()) {
      return;
    }

    BastionBlock firstCollision = null;
    long firstCollisionTime = -1;
    for (BastionBlock bastion : couldCollide) {
      long currentCollidesBy =
          (long) collidesBy(bastion, start.clone(), end.clone(), speed, gravity, horizontalSpeed);
      if (currentCollidesBy != -1 && currentCollidesBy < firstCollisionTime) {
        firstCollisionTime = currentCollidesBy;
        firstCollision = bastion;
      }

      // make sure there is at least a starting value Probably better ways of doing this
      if (firstCollisionTime == -1 && currentCollidesBy != -1) {
        firstCollisionTime = currentCollidesBy;
        firstCollision = bastion;
      }
    }
    if (firstCollisionTime != -1) { // if we found something add it
      task.manage(new Flight(pearl, firstCollisionTime, firstCollision));
      return;
    }
  }
Ejemplo n.º 27
0
  @Override
  public void run() {
    for (Location l : Storage.blackholes.keySet()) {
      for (Entity e : Utilities.getNearbyEntities(l, 10, 10, 10)) {
        if (e instanceof Player) {
          if (((Player) e).getGameMode().equals(CREATIVE)) {
            continue;
          }
        }
        if (Storage.blackholes.get(l)) {
          Vector v = l.clone().subtract(e.getLocation()).toVector();
          v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 10);
          v.setY(v.getY() + (-.5f + Storage.rnd.nextFloat()) * 10);
          v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 10);
          e.setVelocity(v.multiply(.35f));
          e.setFallDistance(0);
        } else {
          Vector v = e.getLocation().subtract(l.clone()).toVector();
          v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 2);
          v.setY(v.getY() + Storage.rnd.nextFloat());
          v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 2);
          e.setVelocity(v.multiply(.35f));
        }
      }
    }
    // Arrows
    toRemove.clear();
    for (Set<CustomArrow> pro : Storage.advancedProjectiles.values()) {
      for (CustomArrow a : pro) {
        a.onFlight();
        a.tick++;
        if (a.entity.isDead() || a.tick > 600) {
          toRemove.add(a);
        }
      }
    }
    for (CustomArrow pro : toRemove) {
      Storage.advancedProjectiles.remove(pro.entity);
      pro.entity.remove();
    }
    for (Block block : Storage.webs) {
      if (Storage.rnd.nextInt(175) == 0 && block.getChunk().isLoaded()) {
        block.setType(AIR);
        websToRemove.add(block);
      }
    }
    for (Block block : websToRemove) {
      Storage.webs.remove(block);
    }
    websToRemove.clear();
    for (LivingEntity ent : Storage.derpingEntities) {
      Location loc = ent.getLocation();
      loc.setYaw(Storage.rnd.nextFloat() * 360F);
      loc.setPitch(Storage.rnd.nextFloat() * 180F - 90F);
      ent.teleport(loc);
    }
    tick++;
    // Other stuff
    for (FallingBlock b : Storage.anthMobs2) {
      if (!Storage.anthVortex.contains(Storage.anthMobs.get(b))) {
        for (Entity e : b.getNearbyEntities(7, 7, 7)) {
          if (e instanceof LivingEntity) {
            LivingEntity lE = (LivingEntity) e;
            if (!(lE instanceof Player) && lE instanceof Monster) {
              b.setVelocity(e.getLocation().subtract(b.getLocation()).toVector().multiply(.25));
              if (lE.getLocation().getWorld().equals(b.getLocation().getWorld())) {
                if (lE.getLocation().distance(b.getLocation()) < 1.2) {
                  EntityDamageEvent evt =
                      new EntityDamageEvent(lE, EntityDamageEvent.DamageCause.SUFFOCATION, 100);
                  Bukkit.getPluginManager().callEvent(evt);
                  lE.setLastDamageCause(evt);
                  if (!evt.isCancelled()) {
                    lE.damage(8f);
                  }
                }
              }
            }
          }
        }
      }
    }
    boolean r = Storage.fallBool;
    Storage.fallBool = !Storage.fallBool;
    for (FallingBlock b : Storage.anthMobs.keySet()) {
      if (Storage.anthVortex.contains(Storage.anthMobs.get(b))) {
        Location loc = Storage.anthMobs.get(b).getLocation();
        Vector v;
        if (b.getLocation().getWorld().equals(Storage.anthMobs.get(b).getLocation().getWorld())) {
          if (r && b.getLocation().distance(Storage.anthMobs.get(b).getLocation()) < 10) {
            v = b.getLocation().subtract(loc).toVector();
          } else {
            int x = Storage.rnd.nextInt(12) - 6;
            int z = Storage.rnd.nextInt(12) - 6;
            Location tLoc = loc.clone();
            tLoc.setX(tLoc.getX() + x);
            tLoc.setZ(tLoc.getZ() + z);
            v = tLoc.subtract(b.getLocation()).toVector();
          }
          v.multiply(.05);
          boolean close = false;
          for (int x = -3; x < 0; x++) {
            if (b.getLocation().getBlock().getRelative(0, x, 0).getType() != AIR) {
              close = true;
            }
          }
          if (close) {
            v.setY(5);
          } else {
            v.setY(-.1);
          }
          b.setVelocity(v);
        }
      }
    }

    for (Arrow e : Storage.tracer.keySet()) {
      Entity close = null;
      double distance = 100;
      int level = Storage.tracer.get(e);
      level = level + 2;
      for (Entity e1 : e.getNearbyEntities(level, level, level)) {
        if (e1.getLocation().getWorld().equals(e.getLocation().getWorld())) {
          double d = e1.getLocation().distance(e.getLocation());
          if (e.getLocation()
              .getWorld()
              .equals(((Entity) e.getShooter()).getLocation().getWorld())) {
            if (d < distance
                && e1 instanceof LivingEntity
                && !e1.equals(e.getShooter())
                && e.getLocation().distance(((Entity) e.getShooter()).getLocation()) > 15) {
              distance = d;
              close = e1;
            }
          }
        }
      }
      if (close != null) {
        Location location = close.getLocation();
        org.bukkit.util.Vector v = new org.bukkit.util.Vector(0D, 0D, 0D);
        Location pos = e.getLocation();
        double its =
            Math.sqrt(
                (location.getBlockX() - pos.getBlockX()) * (location.getBlockX() - pos.getBlockX())
                    + (location.getBlockY() - pos.getBlockY())
                        * (location.getBlockY() - pos.getBlockY())
                    + (location.getBlockZ() - pos.getBlockZ())
                        * (location.getBlockZ() - pos.getBlockZ()));
        if (its == 0) {
          its = (double) 1;
        }
        v.setX((location.getBlockX() - pos.getBlockX()) / its);
        v.setY((location.getBlockY() - pos.getBlockY()) / its);
        v.setZ((location.getBlockZ() - pos.getBlockZ()) / its);
        e.setVelocity(v.multiply(2));
      }
    }

    for (Guardian g : Storage.guardianMove.keySet()) {
      if (g.getLocation().distance(Storage.guardianMove.get(g).getLocation()) > 2
          && g.getTicksLived() < 160) {
        g.setVelocity(
            Storage.guardianMove
                .get(g)
                .getLocation()
                .toVector()
                .subtract(g.getLocation().toVector()));
      } else {
        Storage.guardianMove.remove(g);
      }
    }

    for (Player player : Bukkit.getOnlinePlayers()) {
      Config config = Config.get(player.getWorld());
      for (ItemStack stk : player.getInventory().getArmorContents()) {
        HashMap<CustomEnchantment, Integer> map = config.getEnchants(stk);
        for (CustomEnchantment ench : map.keySet()) {
          ench.onFastScan(player, map.get(ench));
        }
      }
      HashMap<CustomEnchantment, Integer> map = config.getEnchants(player.getItemInHand());
      for (CustomEnchantment ench : map.keySet()) {
        ench.onFastScanHand(player, map.get(ench));
      }
    }
    HashSet<Player> toDelete = new HashSet<>();
    for (Player player : Storage.hungerPlayers.keySet()) {
      if (Storage.hungerPlayers.get(player) < 1) {
        toDelete.add(player);
      } else {
        Storage.hungerPlayers.put(player, Storage.hungerPlayers.get(player) - 1);
      }
    }
    for (Player p : toDelete) {
      Storage.hungerPlayers.remove(p);
    }
    toDelete.clear();
    for (Player player : Storage.moverBlockDecay.keySet()) {
      Storage.moverBlockDecay.put(player, Storage.moverBlockDecay.get(player) + 1);
      if (Storage.moverBlockDecay.get(player) > 5) {
        Storage.moverBlocks.remove(player);
        toDelete.add(player);
      }
    }
    for (Player p : toDelete) {
      Storage.moverBlockDecay.remove(p);
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location = player.getTargetBlock(null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = player.getTargetBlock(null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock = player.getTargetBlock(null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }
          }
          break;
        }
    }
  }
Ejemplo n.º 29
0
    protected void applyForce() {
      if (!isActive()) return;

      // Calculate speeds based on previous delta, to try to adjust for server lag
      float timeDeltaSeconds = (System.currentTimeMillis() - lastTick) / 1000.0f;
      Vector force = new Vector(0, gravity * timeDeltaSeconds, 0);

      float elevateMagnitude = (float) elevateRate * timeDeltaSeconds;
      float speedMinMagnitude = (float) minSpeed * timeDeltaSeconds;
      float speedMaxMagnitude = (float) maxSpeed * timeDeltaSeconds;

      Location playerLocation = player.getLocation();

      float pitch = playerLocation.getPitch();
      float yaw = playerLocation.getYaw();

      Vector scaledForce = force.clone();

      // scaled based on distance from target height
      /// this is the main levitate action
      int playerHeight = playerLocation.getBlockY();
      int heightDelta = targetHeight - playerHeight;
      if (heightDelta > 0) {
        int heightBoost = heightDelta > 16 ? 16 : heightDelta;
        scaledForce.multiply(heightBoost);
      } else if (heightDelta < 0) {
        scaledForce.setY(0);
      }

      // Trying out a suggestion, in a hacky way- adjust pitch so that "level" is really looking
      // down a bit
      pitch += 15;

      // Adjust target height based on aim
      Vector aim =
          new Vector(
              (0 - Math.sin(Math.toRadians(yaw))),
              (0 - Math.sin(Math.toRadians(pitch))),
              Math.cos(Math.toRadians(yaw)));
      aim.normalize();

      // only ascend if aiming mostly up, and if near the target
      if (heightDelta < 5 && pitch < -45) {
        hoverHeight += (elevateMagnitude * aim.getY());

        // We'll let the player go up higher than max height.
        if (hoverHeight > 255) hoverHeight = 255;
        if (hoverHeight < defaultHoverHeight) hoverHeight = defaultHoverHeight;
        updateTargetHeight();
      }

      // Periodically poll for ground level changes
      if (checkCounter++ > checkFrequency) {
        checkForGround();
      }

      // Steer- faster at higher altitudes, and scaled based on angle away from center (look up or
      // down to stop)
      float multiplier = speedMinMagnitude;
      if (!player.isSneaking()) {
        int heightFactor =
            hoverHeight > maxSpeedAtElevation ? maxSpeedAtElevation : (int) hoverHeight;
        multiplier *= (float) speedMaxMagnitude * heightFactor / maxSpeedAtElevation;
      }
      float verticalMultipler = 1.0f - (float) Math.abs(aim.getY());
      aim.multiply(multiplier * verticalMultipler);
      aim.setY(0);
      scaledForce.add(aim);

      // Logger.getLogger("Minecraft").info("Applying force: (" + scaledForce.getX() + ", " +
      // scaledForce.getY() + ", "+ scaledForce.getZ() + ")");
      player.setVelocity(scaledForce);

      this.lastTick = System.currentTimeMillis();
    }
Ejemplo n.º 30
0
  @Override
  public void progress() {
    progressCounter++;
    if (player.isDead() || !player.isOnline()) {
      remove();
      return;
    } else if (currentLoc != null && GeneralMethods.isRegionProtectedFromBuild(this, currentLoc)) {
      remove();
      return;
    }

    if (abilityName.equalsIgnoreCase("Twister")) {
      if (destination == null) {
        state = AbilityState.TWISTER_MOVING;
        direction = player.getEyeLocation().getDirection().clone().normalize();
        direction.setY(0);
        origin = player.getLocation().add(direction.clone().multiply(2));
        destination = player.getLocation().add(direction.clone().multiply(range));
        currentLoc = origin.clone();
      }
      if (origin.distanceSquared(currentLoc) < origin.distanceSquared(destination)
          && state == AbilityState.TWISTER_MOVING) {
        currentLoc.add(direction.clone().multiply(speed));
      } else if (state == AbilityState.TWISTER_MOVING) {
        state = AbilityState.TWISTER_STATIONARY;
        time = System.currentTimeMillis();
      } else if (System.currentTimeMillis() - time >= twisterRemoveDelay) {
        remove();
        return;
      } else if (GeneralMethods.isRegionProtectedFromBuild(this, currentLoc)) {
        remove();
        return;
      }

      Block topBlock = GeneralMethods.getTopBlock(currentLoc, 3, -3);
      if (topBlock == null) {
        remove();
        return;
      }
      currentLoc.setY(topBlock.getLocation().getY());

      double height = twisterHeight;
      double radius = twisterRadius;
      for (double y = 0; y < height; y += twisterHeightParticles) {
        double animRadius = ((radius / height) * y);
        for (double i = -180; i <= 180; i += twisterDegreeParticles) {
          Vector animDir = GeneralMethods.rotateXZ(new Vector(1, 0, 1), i);
          Location animLoc = currentLoc.clone().add(animDir.multiply(animRadius));
          animLoc.add(0, y, 0);
          playAirbendingParticles(animLoc, 1, 0, 0, 0);
        }
      }
      playAirbendingSound(currentLoc);

      for (int i = 0; i < height; i += 3) {
        for (Entity entity :
            GeneralMethods.getEntitiesAroundPoint(currentLoc.clone().add(0, i, 0), radius * 0.75)) {
          if (!affectedEntities.contains(entity) && !entity.equals(player)) {
            affectedEntities.add(entity);
          }
        }
      }

      for (Entity entity : affectedEntities) {
        Vector forceDir =
            GeneralMethods.getDirection(entity.getLocation(), currentLoc.clone().add(0, height, 0));
        if (entity instanceof Player) {
          if (Commands.invincible.contains(((Player) entity).getName())) {
            break;
          }
        }
        entity.setVelocity(forceDir.clone().normalize().multiply(0.3));
      }
    } else if (abilityName.equalsIgnoreCase("AirStream")) {
      if (destination == null) {
        origin = player.getEyeLocation();
        currentLoc = origin.clone();
      }
      Entity target = GeneralMethods.getTargetedEntity(player, range);
      if (target instanceof Player) {
        if (Commands.invincible.contains(((Player) target).getName())) {
          return;
        }
      }

      if (target != null && target.getLocation().distanceSquared(currentLoc) > 49) {
        destination = target.getLocation();
      } else {
        destination = GeneralMethods.getTargetedLocation(player, range, getTransparentMaterial());
      }

      direction = GeneralMethods.getDirection(currentLoc, destination).normalize();
      currentLoc.add(direction.clone().multiply(speed));

      if (player.getWorld() != currentLoc.getWorld()) {
        remove();
        return;
      } else if (!player.isSneaking()) {
        remove();
        return;
      } else if (player.getWorld().equals(currentLoc.getWorld())
          && Math.abs(player.getLocation().distanceSquared(currentLoc)) > range * range) {
        remove();
        return;
      } else if (affectedEntities.size() > 0
          && System.currentTimeMillis() - time >= airStreamEntityCarryDuration) {
        remove();
        return;
      } else if (!isTransparent(currentLoc.getBlock())) {
        remove();
        return;
      } else if (currentLoc.getY() - origin.getY() > airStreamMaxEntityHeight) {
        remove();
        return;
      } else if (GeneralMethods.isRegionProtectedFromBuild(this, currentLoc)) {
        remove();
        return;
      } else if (FireAbility.isWithinFireShield(currentLoc)) {
        remove();
        return;
      } else if (isWithinAirShield(currentLoc)) {
        remove();
        return;
      } else if (!isTransparent(currentLoc.getBlock())) {
        currentLoc.subtract(direction.clone().multiply(speed));
      }

      for (int i = 0; i < 10; i++) {
        BukkitRunnable br =
            new BukkitRunnable() {
              final Location loc = currentLoc.clone();
              final Vector dir = direction.clone();

              @Override
              public void run() {
                for (int angle = -180; angle <= 180; angle += 45) {
                  Vector orthog = GeneralMethods.getOrthogonalVector(dir.clone(), angle, 0.5);
                  playAirbendingParticles(loc.clone().add(orthog), 1, 0F, 0F, 0F);
                }
              }
            };
        br.runTaskLater(ProjectKorra.plugin, i * 2);
        tasks.add(br);
      }

      for (Entity entity : GeneralMethods.getEntitiesAroundPoint(currentLoc, 2.8)) {
        if (affectedEntities.size() == 0) {
          // Set the timer to remove the ability
          time = System.currentTimeMillis();
        }
        if (!entity.equals(player) && !affectedEntities.contains(entity)) {
          affectedEntities.add(entity);
          if (entity instanceof Player) {
            flights.add(new Flight((Player) entity, player));
          }
        }
      }

      for (Entity entity : affectedEntities) {
        Vector force = GeneralMethods.getDirection(entity.getLocation(), currentLoc);
        entity.setVelocity(force.clone().normalize().multiply(speed));
        entity.setFallDistance(0F);
      }
    } else if (abilityName.equalsIgnoreCase("AirSweep")) {
      if (origin == null) {
        direction = player.getEyeLocation().getDirection().normalize();
        origin = player.getLocation().add(direction.clone().multiply(10));
      }
      if (progressCounter < 8) {
        return;
      }
      if (destination == null) {
        destination =
            player
                .getLocation()
                .add(player.getEyeLocation().getDirection().normalize().multiply(10));
        Vector origToDest = GeneralMethods.getDirection(origin, destination);
        for (double i = 0; i < 30; i++) {
          Vector vec =
              GeneralMethods.getDirection(
                  player.getLocation(), origin.clone().add(origToDest.clone().multiply(i / 30)));

          FireComboStream fs =
              new FireComboStream(null, vec, player.getLocation(), range, speed, "AirSweep");
          fs.setDensity(1);
          fs.setSpread(0F);
          fs.setUseNewParticles(true);
          fs.setParticleEffect(getAirbendingParticles());
          fs.setCollides(false);
          fs.runTaskTimer(ProjectKorra.plugin, (long) (i / 2.5), 1L);
          tasks.add(fs);
        }
      }
      manageAirVectors();
    }
  }