Exemplo n.º 1
0
  public String[] getLore() {
    if (nmsStack == null) {
      return null;
    }

    if (nmsStack.getTag() == null) {
      return null;
    }

    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");

    if (displayCompound == null) {
      return null;
    }

    NBTTagList loreList = displayCompound.getList("Lore", NBTStaticHelper.TAG_STRING);
    if (loreList == null) {
      return null;
    }

    if (loreList.size() < 1) {
      return null;
    }

    String[] lore = new String[loreList.size()];
    for (int i = 0; i < loreList.size(); i++) {
      lore[i] = loreList.getString(i).replace("\"", "");
      ;
    }

    return lore;
  }
Exemplo n.º 2
0
  public AttributeUtil(ItemStack stack) {
    // Create a CraftItemStack (under the hood)
    this.nmsStack = CraftItemStack.asNMSCopy(stack);

    if (this.nmsStack == null) {
      return;
    }

    // if (nmsStack == null) {
    //	CivLog.error("Couldn't make NMS copyyy of:"+stack);
    // this.nmsStack = CraftItemStack.asNMSCopy(ItemManager.createItemStack(CivData.WOOL, 1));
    //	if (this.nmsStack == null) {
    //	return;
    // }
    //  }

    // Load NBT
    if (nmsStack.getTag() == null) {
      parent = new NBTTagCompound();
      nmsStack.setTag(parent);
    } else {
      parent = nmsStack.getTag();
    }

    // Load attribute list
    if (parent.hasKey("AttributeModifiers")) {
      attributes = parent.getList("AttributeModifiers", NBTStaticHelper.TAG_COMPOUND);
    } else {
      /* No attributes on this item detected. */
      attributes = new NBTTagList();
      parent.set("AttributeModifiers", attributes);
    }
  }
Exemplo n.º 3
0
  public void setColor(Long long1) {
    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");

    if (displayCompound == null) {
      displayCompound = new NBTTagCompound();
    }

    displayCompound.set("color", new NBTTagInt(long1.intValue()));
    nmsStack.getTag().set("display", displayCompound);
  }
Exemplo n.º 4
0
  public boolean hasLegacyEnhancements() {
    if (nmsStack == null) {
      return false;
    }

    if (nmsStack.getTag() == null) {
      return false;
    }

    return nmsStack.getTag().hasKey("civ_enhancements");
  }
Exemplo n.º 5
0
  public void removeCivCraftCompound() {
    if (nmsStack == null) {
      return;
    }

    NBTTagCompound civcraftCompound = nmsStack.getTag().getCompound("civcraft");
    if (civcraftCompound == null) {
      return;
    }

    nmsStack.getTag().remove("civcraft");
  }
Exemplo n.º 6
0
  public void setSkullOwner(String string) {
    if (nmsStack == null) {
      return;
    }

    NBTTagCompound skullCompound = nmsStack.getTag().getCompound("SkullOwner");
    if (skullCompound == null) {
      skullCompound = new NBTTagCompound();
    }

    skullCompound.set("Name", new NBTTagString(string));
    nmsStack.getTag().set("SkullOwner", skullCompound);
  }
Exemplo n.º 7
0
  public void setHideFlag(int flags) {
    if (nmsStack == null) {
      return;
    }

    nmsStack.getTag().setInt("HideFlags", flags);
  }
Exemplo n.º 8
0
  public boolean hasColor() {
    if (nmsStack == null) {
      return false;
    }

    if (nmsStack.getTag() == null) {
      return false;
    }

    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");
    if (displayCompound == null) {
      return false;
    }

    return displayCompound.hasKey("color");
  }
Exemplo n.º 9
0
  public LinkedList<LoreEnhancement> getEnhancements() {
    LinkedList<LoreEnhancement> returnList = new LinkedList<LoreEnhancement>();

    if (!hasEnhancements()) {
      return returnList;
    }

    NBTTagCompound compound = nmsStack.getTag().getCompound("item_enhancements");

    for (Object keyObj : compound.c()) {
      if (!(keyObj instanceof String)) {
        continue;
      }

      String key = (String) keyObj;
      Object obj = compound.get(key);

      if (obj instanceof NBTTagCompound) {
        NBTTagCompound enhCompound = (NBTTagCompound) obj;
        String name = enhCompound.getString("name").replace("\"", "");

        if (name != null) {
          LoreEnhancement enh = LoreEnhancement.enhancements.get(name);
          if (enh != null) {
            returnList.add(enh);
          }
        }
      }
    }

    return returnList;
  }
Exemplo n.º 10
0
  public int getColor() {
    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");
    if (displayCompound == null) {
      return 0;
    }

    return displayCompound.getInt("color");
  }
Exemplo n.º 11
0
  public boolean hasEnhancement(String enhName) {
    NBTTagCompound compound = nmsStack.getTag().getCompound("item_enhancements");
    if (compound == null) {
      return false;
    }

    return compound.hasKey(enhName);
  }
Exemplo n.º 12
0
  public void setLore(String[] strings) {
    // this.lore.add(str);
    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");

    if (displayCompound == null) {
      displayCompound = new NBTTagCompound();
    }

    NBTTagList loreList = new NBTTagList();

    for (String str : strings) {
      loreList.add(new NBTTagString(str));
    }

    displayCompound.set("Lore", loreList);
    nmsStack.getTag().set("display", displayCompound);
  }
Exemplo n.º 13
0
  public void setName(String name) {
    if (nmsStack == null) {
      return;
    }

    if (nmsStack.getTag() == null) {
      nmsStack.setTag(new NBTTagCompound());
    }

    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");

    if (displayCompound == null) {
      displayCompound = new NBTTagCompound();
    }

    displayCompound.set("Name", new NBTTagString(ChatColor.RESET + name));
    nmsStack.getTag().set("display", displayCompound);
  }
Exemplo n.º 14
0
  public void setCivCraftProperty(String key, String value) {

    if (nmsStack == null) {
      return;
    }

    if (nmsStack.getTag() == null) {
      nmsStack.setTag(new NBTTagCompound());
    }

    NBTTagCompound civcraftCompound = nmsStack.getTag().getCompound("civcraft");

    if (civcraftCompound == null) {
      civcraftCompound = new NBTTagCompound();
    }

    civcraftCompound.set(key, new NBTTagString(value));
    nmsStack.getTag().set("civcraft", civcraftCompound);
  }
Exemplo n.º 15
0
  public String getName() {
    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");

    if (displayCompound == null) {
      displayCompound = new NBTTagCompound();
    }

    String name = displayCompound.getString("Name").toString();
    name = name.replace("\"", "");
    return name;
  }
Exemplo n.º 16
0
  public boolean isShiny() {
    if (nmsStack == null) {
      return false;
    }

    if (nmsStack.getTag() == null) {
      return false;
    }

    NBTTagCompound enchCompound = nmsStack.getTag().getCompound("ench");
    if (enchCompound == null) {
      return false;
    }

    if (enchCompound.hasKey("id") && enchCompound.getShort("id") == (short) 62) {
      return true;
    }

    return false;
  }
Exemplo n.º 17
0
  public void setShiny() {
    if (nmsStack == null) {
      return;
    }

    if (nmsStack.getTag() == null) {
      nmsStack.setTag(new NBTTagCompound());
    }

    NBTTagCompound enchCompound = nmsStack.getTag().getCompound("ench");
    if (enchCompound == null) {
      enchCompound = new NBTTagCompound();
    }

    enchCompound.setShort("id", (short) 62); // Enchant id 62 = Lure
    enchCompound.setShort("lvl", (short) 1);

    nmsStack.getTag().set("ench", enchCompound);
    this.setHideFlag(1);
  }
Exemplo n.º 18
0
  /**
   * Retrieve the modified item stack.
   *
   * @return The modified item stack.
   */
  public ItemStack getStack() {
    if (nmsStack == null) {
      return ItemManager.createItemStack(CivData.WOOL, 0);
    }

    if (nmsStack.getTag() != null) {
      if (attributes.size() == 0) {
        parent.remove("AttributeModifiers");
      }
    }

    return CraftItemStack.asCraftMirror(nmsStack);
  }
Exemplo n.º 19
0
  public String getEnhancementData(String enhName, String key) {
    if (!hasEnhancement(enhName)) {
      return null;
    }

    NBTTagCompound compound = nmsStack.getTag().getCompound("item_enhancements");
    NBTTagCompound enhCompound = compound.getCompound(enhName);

    if (!enhCompound.hasKey(key)) {
      return null;
    }

    return enhCompound.getString(key);
  }
Exemplo n.º 20
0
  public void addEnhancement(String enhancementName, String key, String value) {
    if (enhancementName.equalsIgnoreCase("name")) {
      throw new IllegalArgumentException();
    }

    NBTTagCompound compound = nmsStack.getTag().getCompound("item_enhancements");

    if (compound == null) {
      compound = new NBTTagCompound();
    }

    NBTTagCompound enhCompound = compound.getCompound(enhancementName);
    if (enhCompound == null) {
      enhCompound = new NBTTagCompound();
    }

    if (key != null) {
      _setEnhancementData(enhCompound, key, value);
    }
    enhCompound.set("name", new NBTTagString(enhancementName));

    compound.set(enhancementName, enhCompound);
    nmsStack.getTag().set("item_enhancements", compound);
  }
Exemplo n.º 21
0
  public void addLore(String str) {
    if (nmsStack == null) {
      return;
    }

    if (nmsStack.getTag() == null) {
      nmsStack.setTag(new NBTTagCompound());
    }
    // this.lore.add(str);
    NBTTagCompound displayCompound = nmsStack.getTag().getCompound("display");

    if (displayCompound == null) {
      displayCompound = new NBTTagCompound();
    }

    NBTTagList loreList = displayCompound.getList("Lore", NBTStaticHelper.TAG_STRING);
    if (loreList == null) {
      loreList = new NBTTagList();
    }

    loreList.add(new NBTTagString(str));
    displayCompound.set("Lore", loreList);
    nmsStack.getTag().set("display", displayCompound);
  }
Exemplo n.º 22
0
  public void removeCivCraftProperty(String string) {
    if (nmsStack == null) {
      return;
    }

    NBTTagCompound civcraftCompound = nmsStack.getTag().getCompound("civcraft");
    if (civcraftCompound == null) {
      return;
    }

    civcraftCompound.remove(string);

    if (civcraftCompound.isEmpty()) {
      removeCivCraftCompound();
    }
  }
Exemplo n.º 23
0
  public String getCivCraftProperty(String key) {
    if (nmsStack == null) {
      return null;
    }
    NBTTagCompound civcraftCompound = nmsStack.getTag().getCompound("civcraft");

    if (civcraftCompound == null) {
      return null;
    }

    NBTTagString strTag = (NBTTagString) civcraftCompound.get(key);
    if (strTag == null) {
      return null;
    }

    return strTag.toString().replace("\"", "");
  }