@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerSprint(PlayerToggleSprintEvent event) {
    Player player = event.getPlayer();
    if (!player.isSprinting()) {
      BendingPlayer bender = BendingPlayer.getBendingPlayer(player);
      if (bender.isBender(BendingElement.AIR)
          && EntityTools.canBendPassive(player, BendingElement.AIR)) {
        AirSpeed ab =
            new AirSpeed(AbilityManager.getManager().getRegisteredAbility(AirSpeed.NAME), player);
        if (ab.canBeInitialized()) {
          ab.start();
          if (ab.getState() != BendingAbilityState.START
              && ab.getState() != BendingAbilityState.ENDED) {
            AbilityManager.getManager().addInstance(ab);
            return;
          }
        }
      }

      if (bender.isBender(BendingElement.MASTER)
          && EntityTools.canBendPassive(player, BendingElement.MASTER)) {
        Speed ab = new Speed(AbilityManager.getManager().getRegisteredAbility(Speed.NAME), player);
        if (ab.canBeInitialized()) {
          ab.start();
          if (ab.getState() != BendingAbilityState.START
              && ab.getState() != BendingAbilityState.ENDED) {
            AbilityManager.getManager().addInstance(ab);
            return;
          }
        }
      }
    }
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerSwing(PlayerAnimationEvent event) {
    Player player = event.getPlayer();
    if (this.interact.contains(player.getUniqueId())) {
      this.interact.remove(player.getUniqueId());
      return;
    }
    if (Bloodbending.isBloodbended(player) || Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }

    String ability = EntityTools.getBendingAbility(player);
    RegisteredAbility registered = AbilityManager.getManager().getRegisteredAbility(ability);
    if (registered == null) {
      return;
    }

    if (EntityTools.canBend(player, registered)
        && (registered.canBeUsedWithTools()
            || !EntityTools.isTool(player.getInventory().getItemInMainHand().getType()))) {
      Map<Object, BendingAbility> abilities = AbilityManager.getManager().getInstances(ability);
      boolean shouldCreateNew = true;
      for (BendingAbility a : abilities.values()) {
        if (player.equals(a.getPlayer()) && !((BendingActiveAbility) a).swing()) {
          shouldCreateNew = false;
        }
      }
      if (shouldCreateNew) {
        BendingActiveAbility ab = AbilityManager.getManager().buildAbility(ability, player);
        if (ab == null) {
          Bending.getInstance()
              .getLogger()
              .log(
                  Level.SEVERE,
                  "Ability "
                      + ability
                      + " failed to construct with buildAbility for player "
                      + player.getName());
          return;
        }
        if (ab.canBeInitialized()) {
          ab.swing();
          if (ab.getState() != BendingAbilityState.START
              && ab.getState() != BendingAbilityState.ENDED) {
            AbilityManager.getManager().addInstance(ab);
          }
        }
      }
    }
  }
Esempio n. 3
0
  @Override
  public void progress() {
    if ((System.currentTimeMillis() - time) >= interval) {
      time = System.currentTimeMillis();

      // Compute effect
      for (LivingEntity entity : EntityTools.getLivingEntitiesAroundPoint(origin, RADIUS)) {
        affect(entity);
      }

      if (noDisplayTick <= 0) {
        // Compute particles
        for (double theta = 0; theta < 360; theta += 36) {
          for (double phi = 0; phi < 360; phi += 36) {
            double x =
                particleDistance * Math.cos(Math.toRadians(theta)) * Math.sin(Math.toRadians(phi));
            double y =
                particleDistance * Math.sin(Math.toRadians(theta)) * Math.sin(Math.toRadians(phi));
            double z = particleDistance * Math.cos(Math.toRadians(phi));
            origin.getWorld().playEffect(origin.clone().add(x, y, z), Effect.SMOKE, 4, (int) RANGE);
          }
        }
        particleDistance -= 1;
        if (particleDistance < 0) {
          particleDistance = RADIUS;
        }
        noDisplayTick = 4;
      }
      noDisplayTick--;
    }
  }
  @EventHandler(priority = EventPriority.LOWEST)
  public void onPlayerDeath(PlayerDeathEvent event) {
    EntityDamageEvent ede = event.getEntity().getLastDamageCause();

    if ((ede != null) && (ede.getCause() != null) && (ede.getCause() == DamageCause.LAVA)) {
      Player player = event.getEntity();
      Location loc = player.getLocation();
      LavaTrain lT = LavaTrain.getLavaTrain(loc.getBlock());
      if (lT != null) {
        event.setDeathMessage(
            player.getName() + " died swimming in " + lT.getPlayer().getName() + "'s lava train");
      }
    }

    if (ede instanceof BendingDamageEvent) {
      Player player = event.getEntity();
      BendingDamageEvent bede = (BendingDamageEvent) ede;
      if (bede.getAbility() == null) {
        event.setDeathMessage(player.getName() + " died from unknown bending");
      } else {
        event.setDeathMessage(
            ChatColor.DARK_RED
                + player.getName()
                + ChatColor.RESET
                + " died from "
                + ChatColor.DARK_GREEN
                + bede.getAbility().getPlayer().getName()
                + ChatColor.RESET
                + "'s "
                + PluginTools.getColor(Settings.getColor(bede.getAbility().getElement()))
                + bede.getAbility().getName());
      }
    }

    // Fireblade & Suffocate
    List<ItemStack> toRemove = new LinkedList<ItemStack>();
    for (ItemStack item : event.getDrops()) {
      if (Suffocate.isTempHelmet(item)) {
        toRemove.add(item);
      }
    }
    event.getDrops().removeAll(toRemove);

    if (EntityTools.isGrabed(event.getEntity())) {
      EntityTools.unGrab(event.getEntity());
    }
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerFish(PlayerFishEvent event) {
    Player player = event.getPlayer();

    String ability = EntityTools.getBendingAbility(player);

    if (Bloodbending.isBloodbended(player) || Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }

    RegisteredAbility register = AbilityManager.getManager().getRegisteredAbility(ability);

    if (MetalBending.NAME.equals(ability) && EntityTools.canBend(player, register)) {
      MetalWire.pull(player, event.getHook());
    }
  }
Esempio n. 6
0
 @Override
 public boolean sneak() {
   if (getState() == BendingAbilityState.START) {
     origin = EntityTools.getTargetBlock(player, RANGE).getLocation();
     time = System.currentTimeMillis();
     particleDistance = RADIUS;
     setState(BendingAbilityState.PROGRESSING);
   }
   return false;
 }
Esempio n. 7
0
 @Override
 public boolean canTick() {
   if (!super.canTick()) {
     return false;
   }
   if (blade == null
       || !isFireBlade(player.getInventory().getItemInMainHand())
       || !NAME.equals(EntityTools.getBendingAbility(player))) {
     return false;
   }
   return true;
 }
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onPlayerKick(PlayerKickEvent event) {
    if (Bloodbending.isBloodbended(event.getPlayer())) {
      event.setCancelled(true);
      event.setReason(null);
    }
    if (EntityTools.isFallImmune(event.getPlayer())) {
      event.setCancelled(true);
      event.setReason(null);
    }

    Bending.getInstance().getBendingDatabase().release(event.getPlayer().getUniqueId());
  }
Esempio n. 9
0
  @Override
  public boolean swing() {
    if (getState() == BendingAbilityState.START) {
      blade = new ItemStack(Material.GOLD_SWORD);
      ItemMeta meta = blade.getItemMeta();
      meta.setLore(Arrays.asList(LORE_NAME));
      blade.setItemMeta(meta);
      EntityTools.giveItemInMainHand(player, blade);

      setState(BendingAbilityState.PROGRESSING);
    }
    return false;
  }
Esempio n. 10
0
 private boolean increase(Block block) {
   if (block == null) return false;
   if (hasAnyMoved(block)) return false;
   setMoved(block);
   Block botblock = block.getRelative(BlockFace.DOWN);
   int length = 1;
   if (BlockTools.isEarthbendable(player, botblock)) {
     length = 2;
   }
   if (BlockTools.moveEarth(player, block, new Vector(0, 1, 0), length, false)) {
     for (Entity entity :
         EntityTools.getEntitiesAroundPoint(block.getLocation().clone().add(0, 1, 0), 2)) {
       if (entity.getEntityId() != player.getEntityId() && !entities.contains(entity)) {
         if (!(entity instanceof FallingBlock)) {
           entities.add(entity);
         }
       }
     }
     return true;
   }
   return false;
 }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerDamage(EntityDamageEvent event) {
    if (event.getEntity() instanceof Player) {
      Player player = (Player) event.getEntity();
      BendingPlayer bender = BendingPlayer.getBendingPlayer(player);
      String ability = bender.getAbility();

      if (event.getCause() == DamageCause.FALL) {
        BendingPassiveAbility ab = null;
        if (bender != null && bender.isBender(BendingElement.EARTH)) {
          ab =
              new EarthPassive(
                  AbilityManager.getManager().getRegisteredAbility(EarthPassive.NAME), player);
          if (ab.start()) {
            AbilityManager.getManager().addInstance(ab);
            player.setFallDistance(0);
            event.setDamage(0);
            event.setCancelled(true);
            return;
          }

          if (MetalWire.hasNoFallDamage(player)) {
            player.setFallDistance(0);
            event.setDamage(0);
            event.setCancelled(true);
            return;
          }
        }

        if (bender != null
            && bender.isBender(BendingElement.AIR)
            && EntityTools.canBendPassive(player, BendingElement.AIR)) {
          if (AirBurst.NAME.equals(ability)) {
            BendingActiveAbility burst =
                AbilityManager.getManager().buildAbility(AirBurst.NAME, player);
            if (burst.canBeInitialized()) {
              burst.fall();
              if (burst.getState() != BendingAbilityState.START
                  && burst.getState() != BendingAbilityState.ENDED) {
                AbilityManager.getManager().addInstance(burst);
              }
            }
          }
          player.setFallDistance(0);
          event.setDamage(0);
          event.setCancelled(true);
          return;
        }

        if (!event.isCancelled() && EntityTools.isBender(player, BendingElement.WATER)) {
          ab =
              new WaterPassive(
                  AbilityManager.getManager().getRegisteredAbility(WaterPassive.NAME), player);
          AbilityManager.getManager().addInstance(ab);
          if (ab.start()) {
            player.setFallDistance(0);
            event.setDamage(0);
            event.setCancelled(true);
            return;
          }
        }

        if (!event.isCancelled()
            && bender.isBender(BendingElement.MASTER)
            && EntityTools.canBendPassive(player, BendingElement.MASTER)) {
          event.setDamage((int) (event.getDamage() * (Settings.MASTER_FALL_REDUCTION / 100.)));
          if (event.getEntity().getFallDistance() < 10) {
            event.setCancelled(true);
            return;
          }
        }

        if (!event.isCancelled() && EntityTools.isFallImmune(player)) {
          event.setCancelled(true);
          return;
        }
      }

      if (EntityTools.canBendPassive(player, BendingElement.FIRE)
          && EntityTools.isBender(player, BendingElement.FIRE)
          && ((event.getCause() == DamageCause.FIRE)
              || (event.getCause() == DamageCause.FIRE_TICK))) {
        event.setCancelled(!Enflamed.canBurn(player));
      }

      if (EntityTools.isBender(player, BendingElement.EARTH)
          && ((event.getCause() == DamageCause.SUFFOCATION)
              && TempBlock.isTempBlock(player.getEyeLocation().getBlock()))) {
        event.setDamage(0);
        event.setCancelled(true);
      }

      if (bender != null) {
        Map<Object, BendingAbility> instances =
            AbilityManager.getManager().getInstances(AvatarShield.NAME);
        if (instances.containsKey(player)) {
          AvatarShield ab = (AvatarShield) instances.get(player);
          if (ab.hit()) {
            event.setCancelled(true);
          }
        }
      }
    }
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerSneak(PlayerToggleSneakEvent event) {
    Player player = event.getPlayer();
    if (player == null) {
      Bending.getInstance().getLogger().warning("Null player in PlayerSneak");
      return;
    }
    BendingPlayer bender = BendingPlayer.getBendingPlayer(player);
    if (Bloodbending.isBloodbended(player) || Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }

    String ability = EntityTools.getBendingAbility(player);
    RegisteredAbility register = AbilityManager.getManager().getRegisteredAbility(ability);
    if (!player.isSneaking()
        && ((ability == null) || (register == null) || !register.isShift())
        && (player.getGameMode() == GameMode.SURVIVAL
            || player.getGameMode() == GameMode.ADVENTURE
            || !player.isFlying())) {
      if (bender.isBender(BendingElement.WATER)
          && EntityTools.canBendPassive(player, BendingElement.WATER)
          && !WaterSpout.isBending(player)) {
        FastSwimming ab =
            new FastSwimming(
                AbilityManager.getManager().getRegisteredAbility(FastSwimming.NAME), player);
        if (ab.canBeInitialized()) {
          ab.start();
          if (ab.getState() != BendingAbilityState.START
              && ab.getState() != BendingAbilityState.ENDED) {
            AbilityManager.getManager().addInstance(ab);
            return;
          }
        }
      }
    }

    if (EntityTools.canBend(player, register) && !player.isSneaking()) {
      Map<Object, BendingAbility> abilities = AbilityManager.getManager().getInstances(ability);
      boolean shouldCreateNew = true;
      for (BendingAbility a : abilities.values()) {
        if (a.getPlayer().equals(player) && !((BendingActiveAbility) a).sneak()) {
          shouldCreateNew = false;
        }
      }
      if (shouldCreateNew) {
        BendingActiveAbility ab = AbilityManager.getManager().buildAbility(ability, player);
        if (ab == null) {
          Bending.getInstance()
              .getLogger()
              .log(
                  Level.SEVERE,
                  "Ability "
                      + ability
                      + " failed to construct with buildAbility for player "
                      + player.getName());
          return;
        }
        if (ab.canBeInitialized()) {
          ab.sneak();
          if (ab.getState() != BendingAbilityState.START
              && ab.getState() != BendingAbilityState.ENDED) {
            AbilityManager.getManager().addInstance(ab);
          }
        }
      }
    }
  }