Search in sources :

Example 1 with MCPotionType

use of com.laytonsmith.abstraction.enums.MCPotionType in project CommandHelper by EngineHub.

the class ObjectGenerator method potionData.

public MCPotionData potionData(CArray pd, Target t) {
    MCPotionType type = MCPotionType.valueOf(pd.get("type", t).val().toUpperCase());
    boolean extended = false;
    boolean upgraded = false;
    if (pd.containsKey("extended")) {
        Construct cext = pd.get("extended", t);
        if (cext instanceof CBoolean) {
            extended = ((CBoolean) cext).getBoolean();
        } else {
            throw new CREFormatException("Expected potion value for key \"extended\" to be a boolean", t);
        }
    }
    if (pd.containsKey("upgraded")) {
        Construct cupg = pd.get("upgraded", t);
        if (cupg instanceof CBoolean) {
            upgraded = ((CBoolean) cupg).getBoolean();
        } else {
            throw new CREFormatException("Expected potion value for key \"upgraded\" to be a boolean", t);
        }
    }
    try {
        return StaticLayer.GetPotionData(type, extended, upgraded);
    } catch (IllegalArgumentException ex) {
        throw new CREFormatException(ex.getMessage(), t, ex);
    }
}
Also used : CBoolean(com.laytonsmith.core.constructs.CBoolean) Construct(com.laytonsmith.core.constructs.Construct) MCPotionType(com.laytonsmith.abstraction.enums.MCPotionType) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException)

Aggregations

MCPotionType (com.laytonsmith.abstraction.enums.MCPotionType)1 CBoolean (com.laytonsmith.core.constructs.CBoolean)1 Construct (com.laytonsmith.core.constructs.Construct)1 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)1