Search in sources :

Example 6 with CDouble

use of com.laytonsmith.core.constructs.CDouble in project CommandHelper by EngineHub.

the class RandomTests method testClone.

@Test
public void testClone() throws CloneNotSupportedException {
    CArray c1 = C.Array(C.Void(), C.Void()).clone();
    CBoolean c2 = C.Boolean(true).clone();
    CDouble c4 = C.Double(1).clone();
    CFunction c5 = new CFunction("", Target.UNKNOWN).clone();
    CInt c6 = C.Int(1).clone();
    CNull c7 = C.Null().clone();
    CString c8 = C.String("").clone();
    Construct c9 = C.Void().clone();
    Command c10 = new Command("/c", Target.UNKNOWN).clone();
    IVariable c12 = new IVariable(Auto.TYPE, "@name", C.Null(), Target.UNKNOWN).clone();
    Variable c13 = new Variable("$name", "", false, false, Target.UNKNOWN);
}
Also used : CInt(com.laytonsmith.core.constructs.CInt) IVariable(com.laytonsmith.core.constructs.IVariable) Variable(com.laytonsmith.core.constructs.Variable) Command(com.laytonsmith.core.constructs.Command) CBoolean(com.laytonsmith.core.constructs.CBoolean) IVariable(com.laytonsmith.core.constructs.IVariable) CArray(com.laytonsmith.core.constructs.CArray) CDouble(com.laytonsmith.core.constructs.CDouble) CFunction(com.laytonsmith.core.constructs.CFunction) Construct(com.laytonsmith.core.constructs.Construct) CNull(com.laytonsmith.core.constructs.CNull) CString(com.laytonsmith.core.constructs.CString) Test(org.junit.Test)

Example 7 with CDouble

use of com.laytonsmith.core.constructs.CDouble in project CommandHelper by EngineHub.

the class EntityEvents method parseEntityDamageEvent.

public static Map<String, Construct> parseEntityDamageEvent(MCEntityDamageEvent event, Map<String, Construct> map) {
    if (event != null) {
        MCEntity victim = event.getEntity();
        map.put("type", new CString(victim.getType().name(), Target.UNKNOWN));
        map.put("id", new CString(victim.getUniqueId().toString(), Target.UNKNOWN));
        map.put("cause", new CString(event.getCause().name(), Target.UNKNOWN));
        map.put("amount", new CDouble(event.getDamage(), Target.UNKNOWN));
        map.put("finalamount", new CDouble(event.getFinalDamage(), Target.UNKNOWN));
        map.put("world", new CString(event.getEntity().getWorld().getName(), Target.UNKNOWN));
        map.put("location", ObjectGenerator.GetGenerator().location(event.getEntity().getLocation()));
        if (event instanceof MCEntityDamageByEntityEvent) {
            MCEntity damager = ((MCEntityDamageByEntityEvent) event).getDamager();
            if (damager instanceof MCPlayer) {
                map.put("damager", new CString(((MCPlayer) damager).getName(), Target.UNKNOWN));
            } else {
                map.put("damager", new CString(damager.getUniqueId().toString(), Target.UNKNOWN));
            }
            if (damager instanceof MCProjectile) {
                MCProjectileSource shooter = ((MCProjectile) damager).getShooter();
                if (shooter instanceof MCPlayer) {
                    map.put("shooter", new CString(((MCPlayer) shooter).getName(), Target.UNKNOWN));
                } else if (shooter instanceof MCEntity) {
                    map.put("shooter", new CString(((MCEntity) shooter).getUniqueId().toString(), Target.UNKNOWN));
                } else if (shooter instanceof MCBlockProjectileSource) {
                    map.put("shooter", ObjectGenerator.GetGenerator().location(((MCBlockProjectileSource) shooter).getBlock().getLocation()));
                }
            }
        }
    }
    return map;
}
Also used : MCBlockProjectileSource(com.laytonsmith.abstraction.blocks.MCBlockProjectileSource) MCEntityDamageByEntityEvent(com.laytonsmith.abstraction.events.MCEntityDamageByEntityEvent) MCEntity(com.laytonsmith.abstraction.MCEntity) MCPlayer(com.laytonsmith.abstraction.MCPlayer) CDouble(com.laytonsmith.core.constructs.CDouble) CString(com.laytonsmith.core.constructs.CString) MCProjectile(com.laytonsmith.abstraction.MCProjectile) MCProjectileSource(com.laytonsmith.abstraction.MCProjectileSource)

Example 8 with CDouble

use of com.laytonsmith.core.constructs.CDouble in project CommandHelper by EngineHub.

the class ObjectGenerator method potions.

public CArray potions(List<MCLivingEntity.MCEffect> effectList, Target t) {
    CArray ea = new CArray(t);
    for (MCLivingEntity.MCEffect eff : effectList) {
        CArray effect = CArray.GetAssociativeArray(t);
        effect.set("id", new CInt(eff.getPotionID(), t), t);
        effect.set("strength", new CInt(eff.getStrength(), t), t);
        effect.set("seconds", new CDouble(eff.getTicksRemaining() / 20.0, t), t);
        effect.set("ambient", CBoolean.get(eff.isAmbient()), t);
        effect.set("particles", CBoolean.get(eff.hasParticles()), t);
        ea.push(effect, t);
    }
    return ea;
}
Also used : CInt(com.laytonsmith.core.constructs.CInt) CArray(com.laytonsmith.core.constructs.CArray) CDouble(com.laytonsmith.core.constructs.CDouble) MCLivingEntity(com.laytonsmith.abstraction.MCLivingEntity)

Example 9 with CDouble

use of com.laytonsmith.core.constructs.CDouble in project CommandHelper by EngineHub.

the class Static method getMSObject.

/**
 * Given a java object, returns a MethodScript object.
 *
 * @param object
 * @param t
 * @return
 */
public static Construct getMSObject(Object object, Target t) {
    if (object == null) {
        return CNull.NULL;
    } else if (object instanceof Boolean) {
        return CBoolean.get((boolean) object);
    } else if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer) || (object instanceof Long)) {
        return new CInt((long) object, t);
    } else if ((object instanceof Float) || (object instanceof Double)) {
        return new CDouble((double) object, t);
    } else if (object instanceof Character) {
        return new CString((char) object, t);
    } else if (object instanceof String) {
        return new CString((String) object, t);
    } else if (object instanceof StringBuffer) {
        return new CResource<>((StringBuffer) object, new CResource.ResourceToString() {

            @Override
            public String getString(CResource res) {
                return res.getResource().toString();
            }
        }, t);
    } else if (object instanceof XMLDocument) {
        return new CResource<>((XMLDocument) object, t);
    } else if (object instanceof Construct) {
        return (Construct) object;
    } else if (object instanceof boolean[]) {
        boolean[] array = (boolean[]) object;
        CArray r = new CArray(t);
        for (boolean b : array) {
            r.push(CBoolean.get(b), t);
        }
        return r;
    } else if (object instanceof byte[]) {
        return CByteArray.wrap((byte[]) object, t);
    } else if (object instanceof char[]) {
        char[] array = (char[]) object;
        CArray r = new CArray(t);
        for (char c : array) {
            r.push(new CString(c, t), t);
        }
        return r;
    } else if (object instanceof short[]) {
        short[] array = (short[]) object;
        CArray r = new CArray(t);
        for (short s : array) {
            r.push(new CInt(s, t), t);
        }
        return r;
    } else if (object instanceof int[]) {
        int[] array = (int[]) object;
        CArray r = new CArray(t);
        for (int i : array) {
            r.push(new CInt(i, t), t);
        }
        return r;
    } else if (object instanceof long[]) {
        long[] array = (long[]) object;
        CArray r = new CArray(t);
        for (long l : array) {
            r.push(new CInt(l, t), t);
        }
        return r;
    } else if (object instanceof float[]) {
        float[] array = (float[]) object;
        CArray r = new CArray(t);
        for (float f : array) {
            r.push(new CDouble(f, t), t);
        }
        return r;
    } else if (object instanceof double[]) {
        double[] array = (double[]) object;
        CArray r = new CArray(t);
        for (double d : array) {
            r.push(new CDouble(d, t), t);
        }
        return r;
    } else if (object instanceof Object[]) {
        CArray r = new CArray(t);
        for (Object o : (Object[]) object) {
            r.push((o == object) ? r : getMSObject(o, t), t);
        }
        return r;
    } else if (object instanceof Collection) {
        return getMSObject(((Collection) object).toArray(), t);
    } else if (object instanceof Map) {
        Map map = ((Map) object);
        CArray r = new CArray(t);
        for (Object key : map.keySet()) {
            Object o = map.get(key);
            r.set(key.toString(), (o == object) ? r : getMSObject(o, t), t);
        }
        return r;
    } else {
        return new CString(object.toString(), t);
    }
}
Also used : CArray(com.laytonsmith.core.constructs.CArray) CString(com.laytonsmith.core.constructs.CString) XMLDocument(com.laytonsmith.PureUtilities.XMLDocument) CString(com.laytonsmith.core.constructs.CString) CBoolean(com.laytonsmith.core.constructs.CBoolean) CResource(com.laytonsmith.core.constructs.CResource) CDouble(com.laytonsmith.core.constructs.CDouble) CDouble(com.laytonsmith.core.constructs.CDouble) CInt(com.laytonsmith.core.constructs.CInt) Construct(com.laytonsmith.core.constructs.Construct) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with CDouble

use of com.laytonsmith.core.constructs.CDouble in project CommandHelper by EngineHub.

the class Static method getNumber.

/**
 * Returns a CNumber construct (CInt or CDouble) from any java number.
 *
 * @param number The java number to convert.
 * @param t The code target.
 * @return A construct equivalent to the given java number, whose the type is the better to represent it.
 */
public static CNumber getNumber(Number number, Target t) {
    long longValue = number.longValue();
    double doubleValue = number.doubleValue();
    return longValue == doubleValue ? new CInt(longValue, t) : new CDouble(doubleValue, t);
}
Also used : CInt(com.laytonsmith.core.constructs.CInt) CDouble(com.laytonsmith.core.constructs.CDouble)

Aggregations

CDouble (com.laytonsmith.core.constructs.CDouble)11 CArray (com.laytonsmith.core.constructs.CArray)8 CInt (com.laytonsmith.core.constructs.CInt)8 CString (com.laytonsmith.core.constructs.CString)7 Construct (com.laytonsmith.core.constructs.Construct)7 CBoolean (com.laytonsmith.core.constructs.CBoolean)4 CFunction (com.laytonsmith.core.constructs.CFunction)3 CNull (com.laytonsmith.core.constructs.CNull)3 IVariable (com.laytonsmith.core.constructs.IVariable)3 ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)3 CLabel (com.laytonsmith.core.constructs.CLabel)2 CResource (com.laytonsmith.core.constructs.CResource)2 CVoid (com.laytonsmith.core.constructs.CVoid)2 Variable (com.laytonsmith.core.constructs.Variable)2 CRECastException (com.laytonsmith.core.exceptions.CRE.CRECastException)2 ConfigCompileGroupException (com.laytonsmith.core.exceptions.ConfigCompileGroupException)2 ConfigRuntimeException (com.laytonsmith.core.exceptions.ConfigRuntimeException)2 ProgramFlowManipulationException (com.laytonsmith.core.exceptions.ProgramFlowManipulationException)2 FunctionList (com.laytonsmith.core.functions.FunctionList)2 ArrayList (java.util.ArrayList)2