예제 #1
0
  public ItemStack parseItemStack(String itemstr) {
    if (itemstr.isEmpty()) return null;

    String istr = itemstr;
    String enchant = "";
    String name = "";

    if (istr.contains("$")) {
      name = istr.substring(0, istr.indexOf("$"));
      istr = istr.substring(name.length() + 1);
    }
    if (istr.contains("@")) {
      enchant = istr.substring(istr.indexOf("@") + 1);
      istr = istr.substring(0, istr.indexOf("@"));
    }
    int id = -1;
    int amount = 1;
    short data = 0;
    String[] si = istr.split("\\*");

    if (si.length > 0) {
      if (si.length == 2) amount = Math.max(getMinMaxRandom(si[1]), 1);
      String ti[] = si[0].split(":");
      if (ti.length > 0) {
        if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
        else {
          Material m = Material.getMaterial(ti[0].toUpperCase());
          if (m == null) {
            logOnce("wrongitem" + ti[0], "Could not parse item material name (id) " + ti[0]);
            return null;
          }
          id = m.getId();
        }
        if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Short.parseShort(ti[1]);
        ItemStack item = new ItemStack(id, amount, data);
        if (!enchant.isEmpty()) {
          item = setEnchantments(item, enchant);
        }
        if (!name.isEmpty()) {
          ItemMeta im = item.getItemMeta();
          im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name.replace("_", " ")));
          item.setItemMeta(im);
        }
        return item;
      }
    }
    return null;
  }
예제 #2
0
 public boolean removeItemInHand(Player p, String itemstr) {
   if (!itemstr.isEmpty()) {
     int id = -1;
     int amount = 1;
     int data = -1;
     String[] si = itemstr.split("\\*");
     if (si.length > 0) {
       if ((si.length == 2) && si[1].matches("[1-9]+[0-9]*")) amount = Integer.parseInt(si[1]);
       String ti[] = si[0].split(":");
       if (ti.length > 0) {
         if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
         else id = Material.getMaterial(ti[0]).getId();
         if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
         return removeItemInHand(p, id, data, amount);
       }
     }
   }
   return false;
 }
예제 #3
0
  public int removeItemInInventory(Inventory inv, String istr) {
    String itemstr = istr;
    int left = 1;
    if (left <= 0) return -1;
    int id = -1;
    int data = -1;
    String name = "";

    if (itemstr.contains("$")) {
      name = itemstr.substring(0, itemstr.indexOf("$"));
      itemstr = itemstr.substring(name.length() + 1);
    }

    String[] si = itemstr.split("\\*");
    if (si.length == 0) return left;
    if ((si.length == 2) && si[1].matches("[1-9]+[0-9]*")) left = Integer.parseInt(si[1]);
    String ti[] = si[0].split(":");

    if (ti.length > 0) {
      if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
      else id = Material.getMaterial(ti[0]).getId();
      if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
    }
    if (id <= 0) return left;
    for (int i = 0; i < inv.getContents().length; i++) {
      ItemStack slot = inv.getItem(i);
      if (slot == null) continue;
      if (!compareItemName(slot, name)) continue;
      if (id != slot.getTypeId()) continue;
      if ((data > 0) && (data != slot.getDurability())) continue;
      int slotamount = slot.getAmount();
      if (slotamount == 0) continue;
      if (slotamount <= left) {
        left = left - slotamount;
        inv.setItem(i, null);
      } else {
        slot.setAmount(slotamount - left);
        left = 0;
      }
      if (left == 0) return 0;
    }
    return left;
  }
예제 #4
0
 public boolean compareItemStrIgnoreName(
     int item_id, int item_data, int item_amount, String itemstr) {
   if (!itemstr.isEmpty()) {
     int id = -1;
     int amount = 1;
     int data = -1;
     String[] si = itemstr.split("\\*");
     if (si.length > 0) {
       if ((si.length == 2) && si[1].matches("[1-9]+[0-9]*")) amount = Integer.parseInt(si[1]);
       String ti[] = si[0].split(":");
       if (ti.length > 0) {
         if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
         else id = Material.getMaterial(ti[0]).getId();
         if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
         return ((item_id == id)
             && ((data < 0) || (item_data == data))
             && (item_amount >= amount));
       }
     }
   }
   return false;
 }
예제 #5
0
  public int countItemInInventory(Inventory inv, String istr) {
    String itemstr = istr;
    int count = 0;
    int id = -1;
    int data = -1;
    String name = "";
    if (itemstr.contains("$")) {
      name = itemstr.substring(0, itemstr.indexOf("$"));
      itemstr = itemstr.substring(name.length() + 1);
    }

    String[] si = itemstr.split("\\*");
    if (si.length == 0) return 0;

    String ti[] = si[0].split(":");
    if (ti.length > 0) {
      try {
        if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
        else id = Material.getMaterial(ti[0].toUpperCase()).getId();
      } catch (Exception e) {
        logOnce(istr, "Wrong material type/id " + ti[0] + " at line " + istr);
        return 0;
      }
      if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Integer.parseInt(ti[1]);
    }
    if (id <= 0) return 0;

    for (ItemStack slot : inv.getContents()) {
      if (slot == null) continue;
      if (!compareItemName(slot, name)) continue;
      if (id == slot.getTypeId()) {
        if ((data < 0) || (data == slot.getDurability())) count += slot.getAmount();
      }
    }
    return count;
  }
예제 #6
0
 public static void load() {
   final FileConfiguration config = UDSPlugin.getPlugin().getConfig();
   BLOCK_CREEPERS = config.getBoolean("block.creeper");
   BLOCK_ENDERMEN = config.getBoolean("block.endermen");
   BLOCK_SILVERFISH = config.getBoolean("block.silverfish");
   BLOCK_TNT = config.getBoolean("block.tnt");
   BLOCK_WITHER = config.getBoolean("block.wither");
   MAP_DATA = (byte) config.getInt("map-data");
   BASE_COST = config.getInt("cost.base");
   BUILD_COST = config.getInt("cost.build");
   CITY_COST = config.getInt("cost.city");
   CLAN_COST = config.getInt("cost.clan");
   EXPAND_COST = config.getInt("cost.expand");
   HOME_COST = config.getInt("cost.home");
   MAP_COST = config.getInt("cost.map");
   SHOP_COST = config.getInt("cost.shop");
   VIP_COST = config.getInt("cost.vip");
   UNDO_COUNT = config.getInt("range.undo");
   DRAIN_RANGE = config.getInt("range.drain");
   MOVE_RANGE = config.getInt("range.move");
   EDIT_RANGE = config.getInt("range.edit");
   COMPASS_RANGE = config.getInt("range.compass");
   BUTCHER_RANGE = config.getInt("range.butcher");
   VIP_SPAWNS = config.getInt("vip.spawns");
   WORLD_BORDER = config.getInt("range.world");
   WORLD_BORDER_SQRD = WORLD_BORDER * WORLD_BORDER;
   SPAWNER_EXP = config.getInt("exp.spawner");
   REQUEST_TTL = config.getLong("request-timeout") * TimeUtils.SECOND;
   MINECART_TTL = config.getLong("minecart.life") * TimeUtils.SECOND;
   PVP_TIME = config.getLong("pvp-time") * TimeUtils.SECOND;
   SLOW_TIME = config.getLong("auto-save") * TimeUtils.MINUTE;
   DRAGON_RESPAWN = config.getLong("respawn-dragon") * TimeUtils.MINUTE;
   VIP_TIME = config.getLong("vip.time") * TimeUtils.DAY;
   CURRENCIES = config.getString("currency.plural");
   WELCOME_MSG = config.getString("welcome.message");
   WELCOME_ADMIN = config.getString("welcome.admin");
   SERVER_OWNER = config.getString("server-owner");
   CURRENCY = config.getString("currency.singular");
   MAIN_WORLD = config.getString("world-name");
   WELCOME_GIFT = Material.getMaterial(config.getString("welcome.gift"));
   if (WELCOME_GIFT == null) WELCOME_GIFT = Material.EMERALD;
   SERVER_RULES = config.getStringList("server-rules");
   PISTON_POWER = config.getDouble("piston-power");
   SHARES = config.getStringList("inventory-shares");
   GMAIL_ADDRESS = config.getString("gmail.email");
   SKULL = config.getDouble("head-drop-chance");
   GMAIL_PASSWORD = config.getString("gmail.password");
   VIP_WHITELIST.clear();
   for (int typeId : config.getIntegerList("item-whitelist")) {
     VIP_WHITELIST.add(Material.getMaterial(typeId));
   }
   KITS.clear();
   for (String kit : config.getStringList("kits")) {
     final String[] kitSplit = kit.split(",");
     final List<ItemStack> items =
         new ArrayList<ItemStack>(ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1).length);
     for (Object item : ArrayUtils.subarray(kitSplit, 3, kitSplit.length - 1)) {
       items.add(new ItemStack(Material.getMaterial(Integer.parseInt((String) item))));
     }
     KITS.add(
         new Kit(
             kitSplit[0],
             Integer.parseInt(kitSplit[1]),
             items,
             PlayerRank.getByName(kitSplit[2])));
   }
   MOB_REWARDS.clear();
   for (EntityType entityType : EntityType.values()) {
     String entityName = "mob-rewards." + entityType.getName();
     if (entityName != null) {
       entityName = entityName.toLowerCase();
       MOB_REWARDS.put(entityType, config.getInt(entityName));
     }
   }
   GLOBAL_FLAGS.clear();
   for (RegionFlag flag : RegionFlag.values()) {
     final String flagname = "global-flags." + flag.toString().toLowerCase();
     GLOBAL_FLAGS.put(flag, config.getBoolean(flagname));
   }
 }