Esempio n. 1
0
  /**
   * An Item Object consists of data about a particular item stack. Information included is: type,
   * data, qty, and an array of enchantment objects (labeled enchants): etype (enchantment type) and
   * elevel (enchantment level). For backwards compatibility, this information is also listed in
   * numerical slots as well as associative slots. If the MCItemStack is null, or the underlying
   * item is nonexistant (or air) CNull is returned.
   *
   * @param is
   * @return
   */
  public Construct item(MCItemStack is, Target t) {
    if (is == null || is.getAmount() == 0) {
      return new CNull(t);
    }
    int type = is.getTypeId();

    int data;
    if (type < 256) {
      // Use the data
      data = (is.getData() != null ? is.getData().getData() : 0);
    } else {
      // Use the durability
      data = is.getDurability();
    }
    int qty = is.getAmount();
    CArray enchants = new CArray(t);
    for (Map.Entry<MCEnchantment, Integer> entry : is.getEnchantments().entrySet()) {
      CArray enchObj = CArray.GetAssociativeArray(t);
      enchObj.set("etype", new CString(entry.getKey().getName(), t), t);
      enchObj.set("elevel", new CInt(entry.getValue(), t), t);
      enchants.push(enchObj);
    }
    Construct meta = itemMeta(is, t);
    CArray ret = CArray.GetAssociativeArray(t);
    ret.set("type", Integer.toString(type));
    ret.set("data", Integer.toString(data));
    ret.set("qty", Integer.toString(qty));
    ret.set("enchants", enchants, t);
    ret.set("meta", meta, t);
    return ret;
  }
Esempio n. 2
0
 public CArray velocity(MCEntity.Velocity v, Target t) {
   double x, y, z, mag;
   x = y = z = mag = 0;
   if (v != null) {
     x = v.x;
     y = v.y;
     z = v.z;
     mag = v.magnitude;
   }
   CArray ret = CArray.GetAssociativeArray(t);
   ret.set("magnitude", new CDouble(mag, t), t);
   ret.set("x", new CDouble(x, t), t);
   ret.set("y", new CDouble(y, t), t);
   ret.set("z", new CDouble(z, t), t);
   return ret;
 }
Esempio n. 3
0
 /**
  * Gets a Location Object, given a MCLocation
  *
  * @param l
  * @return
  */
 public CArray location(MCLocation l) {
   CArray ca = CArray.GetAssociativeArray(Target.UNKNOWN);
   Construct x = new CDouble(l.getX(), Target.UNKNOWN);
   Construct y = new CDouble(l.getY(), Target.UNKNOWN);
   Construct z = new CDouble(l.getZ(), Target.UNKNOWN);
   Construct world = new CString(l.getWorld().getName(), Target.UNKNOWN);
   Construct yaw = new CDouble(l.getYaw(), Target.UNKNOWN);
   Construct pitch = new CDouble(l.getPitch(), Target.UNKNOWN);
   ca.set("0", x, Target.UNKNOWN);
   ca.set("1", y, Target.UNKNOWN);
   ca.set("2", z, Target.UNKNOWN);
   ca.set("3", world, Target.UNKNOWN);
   ca.set("4", yaw, Target.UNKNOWN);
   ca.set("5", pitch, Target.UNKNOWN);
   ca.set("x", x, Target.UNKNOWN);
   ca.set("y", y, Target.UNKNOWN);
   ca.set("z", z, Target.UNKNOWN);
   ca.set("world", world, Target.UNKNOWN);
   ca.set("yaw", yaw, Target.UNKNOWN);
   ca.set("pitch", pitch, Target.UNKNOWN);
   return ca;
 }
Esempio n. 4
0
 public Construct itemMeta(MCItemStack is, Target t) {
   Construct ret, display, lore, color, title, author, pages, owner, stored;
   if (!is.hasItemMeta()) {
     ret = new CNull(t);
   } else {
     ret = CArray.GetAssociativeArray(t);
     MCItemMeta meta = is.getItemMeta();
     if (meta.hasDisplayName()) {
       display = new CString(meta.getDisplayName(), t);
     } else {
       display = new CNull(t);
     }
     if (meta.hasLore()) {
       lore = new CArray(t);
       for (String l : meta.getLore()) {
         ((CArray) lore).push(new CString(l, t));
       }
     } else {
       lore = new CNull(t);
     }
     ((CArray) ret).set("display", display, t);
     ((CArray) ret).set("lore", lore, t);
     if (meta instanceof MCLeatherArmorMeta) {
       color = color(((MCLeatherArmorMeta) meta).getColor(), t);
       ((CArray) ret).set("color", color, t);
     }
     if (meta instanceof MCBookMeta) {
       if (((MCBookMeta) meta).hasTitle()) {
         title = new CString(((MCBookMeta) meta).getTitle(), t);
       } else {
         title = new CNull(t);
       }
       if (((MCBookMeta) meta).hasAuthor()) {
         author = new CString(((MCBookMeta) meta).getAuthor(), t);
       } else {
         author = new CNull(t);
       }
       if (((MCBookMeta) meta).hasPages()) {
         pages = new CArray(t);
         for (String p : ((MCBookMeta) meta).getPages()) {
           ((CArray) pages).push(new CString(p, t));
         }
       } else {
         pages = new CNull(t);
       }
       ((CArray) ret).set("title", title, t);
       ((CArray) ret).set("author", author, t);
       ((CArray) ret).set("pages", pages, t);
     }
     if (meta instanceof MCSkullMeta) {
       if (((MCSkullMeta) meta).hasOwner()) {
         owner = new CString(((MCSkullMeta) meta).getOwner(), t);
       } else {
         owner = new CNull(t);
       }
       ((CArray) ret).set("owner", owner, t);
     }
     if (meta instanceof MCEnchantmentStorageMeta) {
       if (((MCEnchantmentStorageMeta) meta).hasStoredEnchants()) {
         stored = new CArray(t);
         for (Map.Entry<MCEnchantment, Integer> entry :
             ((MCEnchantmentStorageMeta) meta).getStoredEnchants().entrySet()) {
           CArray eObj = CArray.GetAssociativeArray(t);
           eObj.set("etype", new CString(entry.getKey().getName(), t), t);
           eObj.set("elevel", new CInt(entry.getValue(), t), t);
           ((CArray) stored).push(eObj);
         }
       } else {
         stored = new CNull(t);
       }
       ((CArray) ret).set("stored", stored, t);
     }
   }
   return ret;
 }