Search in sources :

Example 16 with CREFormatException

use of com.laytonsmith.core.exceptions.CRE.CREFormatException in project CommandHelper by EngineHub.

the class Static method ParseItemNotation.

/**
 * Returns an item stack from the given item notation. Defaulting to the specified qty, this will throw an exception
 * if the notation is invalid.
 *
 * @param functionName
 * @param notation
 * @param qty
 * @throws CREFormatException If the notation is invalid.
 * @return
 */
@Deprecated
public static MCItemStack ParseItemNotation(String functionName, String notation, int qty, Target t) {
    int type;
    short data = 0;
    try {
        int separatorIndex = notation.indexOf(':');
        if (separatorIndex != -1) {
            type = Integer.parseInt(notation.substring(0, separatorIndex));
            data = (short) Integer.parseInt(notation.substring(separatorIndex + 1));
        } else {
            type = Integer.parseInt(notation);
        }
    } catch (NumberFormatException e) {
        throw new CREFormatException("Invalid item notation: " + notation, t);
    }
    return StaticLayer.GetItemStack(type, data, qty);
}
Also used : CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException)

Aggregations

CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)16 CArray (com.laytonsmith.core.constructs.CArray)12 CString (com.laytonsmith.core.constructs.CString)9 Construct (com.laytonsmith.core.constructs.Construct)6 CNull (com.laytonsmith.core.constructs.CNull)4 MCEnchantment (com.laytonsmith.abstraction.MCEnchantment)3 MCItemStack (com.laytonsmith.abstraction.MCItemStack)3 CRECastException (com.laytonsmith.core.exceptions.CRE.CRECastException)3 CRERangeException (com.laytonsmith.core.exceptions.CRE.CRERangeException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 MCEntity (com.laytonsmith.abstraction.MCEntity)2 MCInventory (com.laytonsmith.abstraction.MCInventory)2 MCItemMeta (com.laytonsmith.abstraction.MCItemMeta)2 MCLivingEntity (com.laytonsmith.abstraction.MCLivingEntity)2 MCLocation (com.laytonsmith.abstraction.MCLocation)2 CRENotFoundException (com.laytonsmith.core.exceptions.CRE.CRENotFoundException)2 Map (java.util.Map)2 Vector3D (com.laytonsmith.PureUtilities.Vector3D)1 Cookie (com.laytonsmith.PureUtilities.Web.Cookie)1