示例#1
0
 public ItemStack setEnchantments(ItemStack item, String enchants) {
   ItemStack i = item.clone();
   if (enchants.isEmpty()) return i;
   String[] ln = enchants.split(",");
   for (String ec : ln) {
     if (ec.isEmpty()) continue;
     Color clr = colorByName(ec);
     if (clr != null) {
       if (isIdInList(item.getTypeId(), "298,299,300,301")) {
         LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
         meta.setColor(clr);
         i.setItemMeta(meta);
       }
     } else {
       String ench = ec;
       int level = 1;
       if (ec.contains(":")) {
         ench = ec.substring(0, ec.indexOf(":"));
         level = Math.max(1, getMinMaxRandom(ec.substring(ench.length() + 1)));
       }
       Enchantment e = Enchantment.getByName(ench.toUpperCase());
       if (e == null) continue;
       i.addUnsafeEnchantment(e, level);
     }
   }
   return i;
 }
示例#2
0
 @Override
 public int getNoDamageTicks() {
   if (getHandle().field_71145_cl > 0) {
     return Math.max(getHandle().field_71145_cl, getHandle().field_70172_ad);
   } else {
     return getHandle().field_70172_ad;
   }
 }
示例#3
0
 public List<Block> getBlocks() {
   List<Block> blocks = new ArrayList<Block>();
   if (loc1 == null || loc2 == null) return blocks;
   for (int x = (int) Math.min(loc1.getX(), loc2.getX());
       x <= (int) Math.max(loc1.getX(), loc2.getX());
       x++) {
     for (int y = (int) Math.min(loc1.getY(), loc2.getY());
         y <= (int) Math.max(loc1.getY(), loc2.getY());
         y++) {
       for (int z = (int) Math.min(loc1.getZ(), loc2.getZ());
           z <= (int) Math.max(loc1.getZ(), loc2.getZ());
           z++) {
         if (loc1.getWorld().getBlockAt(x, y, z).getType() == Material.AIR) {
           blocks.add(loc1.getWorld().getBlockAt(x, y, z));
         }
       }
     }
   }
   return blocks;
 }
示例#4
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;
  }
示例#5
0
 public Long timeToTicks(Long time) {
   // 1000 ms = 20 ticks
   return Math.max(1, (time / 50));
 }