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);
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations