Пример #1
0
  /*
   * @Return: True if they have an ability matching the held item. False if
   * they do not have any abilities matching held item
   */
  public boolean useAbility(Player sender, Player target) {
    // check if they're holding anything
    if (sender.getItemInHand() == null) {
      return false;
    }

    ItemStack i = sender.getItemInHand();

    // sees if they are fightclassed
    FightClass f = FightClass.get(sender);
    // goes through each ability, seeeing if any of the MID's match the
    // lore of the item
    for (Ability a : f.getAbilities()) {
      if (i.getItemMeta().hasLore()
          && i.getItemMeta().getLore().get(0).equalsIgnoreCase(a.getMID())) {
        // check if cost is able to be paid, and pay it
        if (a.useCost(sender)) {
          if (!sender.equals(target)) {
            a.effect(sender, target);
          }
        } else {
          // nothing
        }
        return true;
      }
    }
    return false;
  }
Пример #2
0
 public static void initiateClass(Player sender, FightClass fightclass) {
   // give items
   for (ItemStack is : fightclass.getItems()) {
     sender.getInventory().addItem(is);
   }
   // give abilities (activated by these items)
   for (Ability a : fightclass.getAbilities()) {
     sender.getInventory().addItem(a.getItem());
   }
 }
Пример #3
0
  /*
   * Return: True if they have an ability matching the held item. False if
   * they do not have any abilities matching held item
   */
  public boolean useAbility(Player sender, Block b) {
    // check if they're holding anything
    if (sender.getItemInHand() == null) {
      return false;
    }

    ItemStack i = sender.getItemInHand();

    // sees if they are fightclassed
    FightClass f = FightClass.get(sender);
    // goes through each ability, seeeing if any of the MID's match the
    // lore of the item
    for (Ability a : f.getAbilities()) {
      if (i.getItemMeta().hasLore()
          && i.getItemMeta().getLore().get(0).equalsIgnoreCase(a.getMID())) {
        // check if cost is able to be paid, and pay it
        if (a.useCost(sender)) {

          // check to see if there is a target
          Player target = null;
          boolean s = true;
          Location l = sender.getLocation();

          /*
           * loop through nearby entites to positions x blocks in the
           * direction the player is looking, starting at 0 and ending
           * at a.getRange()
           */
          for (int x = 2; x < a.getRange() && (s); x++) {
            Location lt = l;

            Collection<Entity> et =
                lt.getWorld().getNearbyEntities(lt.add(lt.getDirection().multiply(x)), 2, 2, 2);

            if (!et.isEmpty()) {
              for (Entity entity : et) {
                if (entity instanceof Player) {
                  if (!(((Player) entity).equals(sender))) {
                    target = (Player) entity;
                    s = false;
                  }
                }
              }
            }
          }

          // see if target got set to anything
          if (target != null) {
            a.effect(sender, target);
          } else {
            if (a instanceof BlockTargettingAbility) {
              if (b != null && !b.getType().equals(Material.AIR)) {
                ((BlockTargettingAbility) a).effect(sender, b);
              } else {
                // nothing, needs a block for target it
                // BlockTargettingAbility
              }
            }
            a.effect(sender);
          }
        } else {
          // nothing
        }
        return true;
      }
    }
    return false;
  }