Search in sources :

Example 1 with CREEnchantmentException

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

the class ObjectGenerator method enchants.

public Map<MCEnchantment, Integer> enchants(CArray enchantArray, Target t) {
    Map<MCEnchantment, Integer> ret = new HashMap<>();
    for (String key : enchantArray.stringKeySet()) {
        try {
            CArray ea = (CArray) enchantArray.get(key, t);
            String setype = ea.get("etype", t).val();
            MCEnchantment etype = StaticLayer.GetConvertor().GetEnchantmentByName(setype);
            int elevel = Static.getInt32(ea.get("elevel", t), t);
            if (etype == null) {
                if (setype.equals("SWEEPING")) {
                    // data from 1.11.2, changed in 1.12
                    etype = StaticLayer.GetEnchantmentByName("SWEEPING_EDGE");
                }
                if (etype == null) {
                    throw new CREEnchantmentException("Unknown enchantment type at " + key, t);
                }
            }
            ret.put(etype, elevel);
        } catch (ClassCastException cce) {
            throw new CREFormatException("Expected an array at index " + key, t);
        }
    }
    return ret;
}
Also used : MCEnchantment(com.laytonsmith.abstraction.MCEnchantment) HashMap(java.util.HashMap) CArray(com.laytonsmith.core.constructs.CArray) CREEnchantmentException(com.laytonsmith.core.exceptions.CRE.CREEnchantmentException) CString(com.laytonsmith.core.constructs.CString) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException)

Aggregations

MCEnchantment (com.laytonsmith.abstraction.MCEnchantment)1 CArray (com.laytonsmith.core.constructs.CArray)1 CString (com.laytonsmith.core.constructs.CString)1 CREEnchantmentException (com.laytonsmith.core.exceptions.CRE.CREEnchantmentException)1 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)1 HashMap (java.util.HashMap)1