コード例 #1
0
ファイル: Enchanter.java プロジェクト: Holyvirus/Blacksmith
  public static int getEnchantCost(Player p, String e, int lvl) {
    Permission pH = BlackSmith.getPlugin().getPermHandler().getEngine();
    config conf = config.Obtain();
    int c = 0;

    try {
      c = conf.getInt("BlackSmith.EnchantmentBases." + e);
    } catch (Exception ex) {
      p.sendMessage(
          "Whoops, the price for this enchant is not defined correctly! Please inform an admin immediatly");
      ChatListener.remove(p);
    }

    return pH.has(p, "blacksmith.enchant.free") ? 0 : c * lvl;
  }
コード例 #2
0
ファイル: Enchanter.java プロジェクト: Holyvirus/Blacksmith
  public static void enchant(Player p, String e) {
    config conf = config.Obtain();
    Permission pH = BlackSmith.getPlugin().getPermHandler().getEngine();
    Enchantment en = null;
    int lvl = 0;
    ItemStack i = null;
    if (p.getItemInHand() != null) {
      if (p.getItemInHand().getTypeId() == ((ItemStack) item.get(p.getName())).getTypeId()) {
        i = p.getItemInHand();
      } else {
        ChatListener.add(p, 1);
        p.sendMessage(ChatColor.RED + "You have changed the item in your hand, please try again!");
        return;
      }
    } else {
      ChatListener.add(p, 1);
      p.sendMessage(ChatColor.RED + "You have changed the item in your hand, please try again!");
    }

    try {
      en = enchants.get(p.getName()).keySet().iterator().next();
      lvl = enchants.get(p.getName()).get(en);
    } catch (Exception ex) {
      if (conf.getBoolean("BlackSmith.global.debug")) ex.printStackTrace();
    }

    double b = eH.getBalance(p);
    double cost = getEnchantCost(p, e, lvl);

    if (b > cost) {
      eH.withdraw(p, cost);

      try {
        i.addEnchantment(en, lvl);
        ChatListener.remove(p);
      } catch (IllegalArgumentException ex) {
        if (pH.has(p, "blacksmith.enchant.unsafe")) {
          i.addUnsafeEnchantment(en, lvl);
          ChatListener.remove(p);
        } else {
          p.sendMessage("You are not allowed to enchant unsafely, try again!");
          ChatListener.add(p, 1);
        }
      }
    }
  }