示例#1
0
  private void applyKnockback(Player attacker, LivingEntity attacked, int damageType) {
    ItemStack handItem = attacker.getItemInHand();
    float knockback = 0;

    // If arrow knockback is on, and the damage is arrow type, then...
    if (FC_Rpg.balanceConfig.getArrowKnockback() == true && damageType == 1) {
      // Add knockback.
      knockback += 1;

      // Add in additional knockback based on the punch enchants strength.
      if (handItem.containsEnchantment(Enchantment.ARROW_KNOCKBACK))
        knockback += handItem.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK);
    } else if (FC_Rpg.balanceConfig.getSwordKnockback()) {
      // Increase knockback based on damage type.
      if (handItem.containsEnchantment(Enchantment.KNOCKBACK))
        knockback += handItem.getEnchantmentLevel(Enchantment.KNOCKBACK);
    }

    // If there is a knockback the we apply it.
    if (knockback > 0)
      attacked.setVelocity(
          attacked
              .getVelocity()
              .add(
                  attacked
                      .getLocation()
                      .toVector()
                      .subtract(attacker.getLocation().toVector())
                      .normalize()
                      .multiply(knockback)));
  }
示例#2
0
 private static boolean sameEnchants(ItemStack a, ItemStack b) {
   if (a.getEnchantments().size() == b.getEnchantments().size()) {
     for (Enchantment e : a.getEnchantments().keySet()) {
       if (!b.containsEnchantment(e) || b.getEnchantmentLevel(e) != a.getEnchantmentLevel(e)) {
         return false;
       }
     }
     return true;
   }
   return false;
 }
示例#3
0
  public static void enchantValidate(Player p, String e, int rlvl) { // shut up for now :P
    HashMap<Enchantment, Integer> fen = new HashMap<Enchantment, Integer>();
    ItemStack i = null;
    int lvl = 0;
    Enchantment en = Enchantment.getById(getEnchantId(e));

    if (p.getItemInHand().getTypeId() == ((ItemStack) item.get(p.getName())).getTypeId()) {
      i = p.getItemInHand();
      if (i.getAmount() == 1) {
        if (i.containsEnchantment(en)) {
          int plvl = i.getEnchantmentLevel(en);
          lvl = plvl + rlvl;
        } else {
          lvl = rlvl;
        }
        fen.put(en, lvl);
        enchants.put(p.getName(), fen);
        ChatListener.add(p, 2);
        p.sendMessage(
            "The enchant will cost you: "
                + getEnchantCost(p, e.toLowerCase(), rlvl)
                + "! Should I continue? Please type \"yes\" or \"no\"!");
      } else {
        p.sendMessage(
            ChatColor.RED + "You have more then one item in your slot, please try again!");
      }
    }
  }
  /**
   * Checks ths cost to upgrade the given stack. If return value is not present, we cannot upgrade
   * the given stack with this enchantment.
   *
   * @param stack the stack to check
   * @return the cost if possible
   */
  public Optional<ItemStack> costToUpgrade(ItemStack stack) {
    int currentLevel = stack.getEnchantmentLevel(enchantment);

    // out of range or null cost, cannot do
    if (!canEnchantAtLevel(currentLevel + 1)) return Optional.absent();

    return Optional.of(costs[currentLevel]);
  }
示例#5
0
 // Anti Looting X
 @EventHandler
 public void removeSword(PlayerItemHeldEvent e) {
   ItemStack i = e.getPlayer().getInventory().getItem(e.getNewSlot());
   if (i != null) {
     if (i.getType() != Material.AIR && i.containsEnchantment(Enchantment.LOOT_BONUS_MOBS)) {
       if (i.getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS) >= 10) {
         i.removeEnchantment(Enchantment.LOOT_BONUS_MOBS);
       }
     }
   }
 }
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent e) {
    List<ItemStack> drops = new ArrayList<ItemStack>();
    SlimefunItem sfItem = BlockStorage.check(e.getBlock());
    ItemStack item = e.getPlayer().getItemInHand();
    int fortune = 1;
    if (sfItem != null && !(sfItem instanceof HandledBlock))
      drops.add(BlockStorage.retrieve(e.getBlock()));
    else if (item != null) {
      if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS)
          && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
        fortune = main.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
        if (fortune <= 0) fortune = 1;
        fortune =
            (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + main.randomize(5) : 1)
                * (fortune + 1);
      }

      for (ItemHandler handler : SlimefunItem.getHandlers("BlockBreakHandler")) {
        if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break;
      }
    }

    if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)
        && e.getBlock().getType().toString().endsWith("_ORE")) {
      if (Talisman.checkFor(e, SlimefunItem.getByName("MINER_TALISMAN"))) {
        if (drops.isEmpty()) drops = (List<ItemStack>) e.getBlock().getDrops();
        for (ItemStack drop : new ArrayList<ItemStack>(drops)) {
          if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
        }
      }
    }

    if (!drops.isEmpty()) {
      e.getBlock().setType(Material.AIR);
      for (ItemStack drop : drops) {
        e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop);
      }
    }
  }
  /**
   * Increments this enchant on the given stack. If the item doesn't have this enchant it will be
   * set to level 1
   *
   * @param stack the stack to increment
   */
  public void unsafeEnchantIncrement(ItemStack stack) {
    Preconditions.checkNotNull(stack);

    stack.addUnsafeEnchantment(enchantment, stack.getEnchantmentLevel(enchantment) + 1);
  }
示例#8
0
  /**
   * Handles removing & dropping the blocks from Tree Feller.
   *
   * @param toBeFelled List of Blocks to be removed from the tree
   * @param player The player using the ability
   * @param profile The PlayerProfile of the player
   */
  private static void removeBlocks(
      ArrayList<Block> toBeFelled, Player player, PlayerProfile profile) {
    if (toBeFelled.size() >= Config.getInstance().getTreeFellerThreshold()) {
      player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFellerThreshold"));
      return;
    }

    int xp = 0;
    ItemStack inHand = player.getItemInHand();
    int level = 0;
    if (inHand.containsEnchantment(Enchantment.DURABILITY)) {
      level = inHand.getEnchantmentLevel(Enchantment.DURABILITY);
    }
    int durabilityLoss = durabilityLossCalulate(toBeFelled, level);

    /* This is to prevent using wood axes everytime you tree fell */
    if (ModChecks.isCustomTool(inHand)) {
      if (inHand.getDurability() + durabilityLoss
          >= ModChecks.getToolFromItemStack(inHand).getDurability()) {
        player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));

        int health = player.getHealth();

        if (health >= 2) {
          Combat.dealDamage(player, random.nextInt(health - 1));
        }
        inHand.setDurability((short) (inHand.getType().getMaxDurability()));
        return;
      }
    } else if ((inHand.getDurability() + durabilityLoss >= inHand.getType().getMaxDurability())
        || inHand.getType().equals(Material.AIR)) {
      player.sendMessage(LocaleLoader.getString("Woodcutting.Skills.TreeFeller.Splinter"));

      int health = player.getHealth();

      if (health >= 2) {
        Combat.dealDamage(player, random.nextInt(health - 1));
      }
      inHand.setDurability((short) (inHand.getType().getMaxDurability()));
      return;
    }

    /* Damage the tool */
    inHand.setDurability((short) (inHand.getDurability() + durabilityLoss));

    // Prepare ItemStacks
    ItemStack item = null;
    ItemStack oak = (new MaterialData(Material.LOG, TreeSpecies.GENERIC.getData())).toItemStack(1);
    ItemStack spruce =
        (new MaterialData(Material.LOG, TreeSpecies.REDWOOD.getData())).toItemStack(1);
    ItemStack birch = (new MaterialData(Material.LOG, TreeSpecies.BIRCH.getData())).toItemStack(1);
    ItemStack jungle =
        (new MaterialData(Material.LOG, TreeSpecies.JUNGLE.getData())).toItemStack(1);

    for (Block x : toBeFelled) {
      if (Misc.blockBreakSimulate(x, player, true)) {
        if (Config.getInstance().getBlockModsEnabled() && ModChecks.isCustomLogBlock(x)) {
          if (ModChecks.isCustomLogBlock(x)) {
            CustomBlock block = ModChecks.getCustomBlock(x);
            item = block.getItemDrop();

            if (!mcMMO.placeStore.isTrue(x)) {
              WoodCutting.woodCuttingProcCheck(player, x);
              xp = block.getXpGain();
            }

            /* Remove the block */
            x.setData((byte) 0x0);
            x.setType(Material.AIR);

            int minimumDropAmount = block.getMinimumDropAmount();
            int maximumDropAmount = block.getMaximumDropAmount();

            item = block.getItemDrop();

            if (minimumDropAmount != maximumDropAmount) {
              Misc.dropItems(x.getLocation(), item, minimumDropAmount);
              Misc.randomDropItems(
                  x.getLocation(), item, 50, maximumDropAmount - minimumDropAmount);
            } else {
              Misc.dropItems(x.getLocation(), item, minimumDropAmount);
            }
          } else if (ModChecks.isCustomLeafBlock(x)) {
            CustomBlock block = ModChecks.getCustomBlock(x);
            item = block.getItemDrop();

            final int SAPLING_DROP_CHANCE = 10;

            /* Remove the block */
            x.setData((byte) 0x0);
            x.setType(Material.AIR);

            Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);
          }
        } else if (x.getType() == Material.LOG) {
          Tree tree = (Tree) x.getState().getData();
          TreeSpecies species = tree.getSpecies();

          switch (species) {
            case GENERIC:
              item = oak;
              break;

            case REDWOOD:
              item = spruce;
              break;

            case BIRCH:
              item = birch;
              break;

            case JUNGLE:
              item = jungle;
              break;

            default:
              break;
          }

          if (!mcMMO.placeStore.isTrue(x)) {
            WoodCutting.woodCuttingProcCheck(player, x);

            switch (species) {
              case GENERIC:
                xp += Config.getInstance().getWoodcuttingXPOak();
                break;

              case REDWOOD:
                xp += Config.getInstance().getWoodcuttingXPSpruce();
                break;

              case BIRCH:
                xp += Config.getInstance().getWoodcuttingXPBirch();
                break;

              case JUNGLE:
                xp +=
                    Config.getInstance().getWoodcuttingXPJungle()
                        / 2; // Nerf XP from Jungle Trees when using Tree Feller
                break;

              default:
                break;
            }
          }

          /* Remove the block */
          x.setData((byte) 0x0);
          x.setType(Material.AIR);

          /* Drop the block */
          Misc.dropItem(x.getLocation(), item);
        } else if (x.getType() == Material.LEAVES) {
          final int SAPLING_DROP_CHANCE = 10;

          // Drop the right type of sapling
          item = (new MaterialData(Material.SAPLING, (byte) (x.getData() & 3))).toItemStack(1);

          Misc.randomDropItem(x.getLocation(), item, SAPLING_DROP_CHANCE);

          // Remove the block
          x.setData((byte) 0);
          x.setType(Material.AIR);
        }
      }
    }

    if (Permissions.getInstance().woodcutting(player)) {
      Skills.xpProcessing(player, profile, SkillType.WOODCUTTING, xp);
    }
  }