use of com.laytonsmith.core.constructs.CNull 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.CNull in project CommandHelper by EngineHub.
the class ConfigRuntimeException method GetReaction.
/**
* If a exception bubbles all the way up to the top, this should be called first, to see what reaction the plugin
* should take. Generally speaking, you'll want to use {@link #HandleUncaughtException} instead of this, though if
* you need to take custom action, you can determine the user's preferred reaction with this method.
*
* @param e
* @return
*/
public static Reaction GetReaction(ConfigRuntimeException e, Environment env) {
// If there is an exception handler, call it to see what it says.
Reaction reaction = Reaction.REPORT;
if (env.getEnv(GlobalEnv.class).GetExceptionHandler() != null) {
CClosure c = env.getEnv(GlobalEnv.class).GetExceptionHandler();
CArray ex = ObjectGenerator.GetGenerator().exception(e, env, Target.UNKNOWN);
if (e.getEnv() != null) {
MCCommandSender sender = e.getEnv().getEnv(CommandHelperEnvironment.class).GetCommandSender();
c.getEnv().getEnv(CommandHelperEnvironment.class).SetCommandSender(sender);
}
Construct ret = CNull.NULL;
try {
c.execute(new Construct[] { ex });
} catch (FunctionReturnException retException) {
ret = retException.getReturn();
}
if (ret instanceof CNull || Prefs.ScreamErrors()) {
reaction = Reaction.REPORT;
} else {
if (Static.getBoolean(ret, Target.UNKNOWN)) {
reaction = Reaction.IGNORE;
} else {
reaction = Reaction.FATAL;
}
}
}
return reaction;
}
use of com.laytonsmith.core.constructs.CNull in project CommandHelper by EngineHub.
the class InventoryManagement method IsMatch.
/**
* Gets whether or not the two items are a match based on the given item array map.
*
* @param map The original item array map of what to compare
* @param is The MCItemStack to compare all other items with, converted from the item array map
* @param iis The current MCItemStack we're comparing
* @param t
* @return Whether or not the items are a match
*/
private static boolean IsMatch(CArray map, MCItemStack is, MCItemStack iis, Target t) {
if (!is.getType().equals(iis.getType())) {
return false;
}
if ((map == null || map.containsKey("data")) && is.getDurability() != iis.getDurability()) {
return false;
}
if (map != null && map.containsKey("meta")) {
Construct c = map.get("meta", t);
if (c instanceof CNull) {
if (iis.hasItemMeta()) {
return false;
}
} else {
if (!iis.hasItemMeta()) {
return false;
}
CArray metamap = (CArray) c;
MCItemMeta im = is.getItemMeta();
MCItemMeta iim = iis.getItemMeta();
if (metamap.containsKey("display")) {
if (im.hasDisplayName()) {
if (!iim.hasDisplayName() || !im.getDisplayName().equals(iim.getDisplayName())) {
return false;
}
} else if (iim.hasDisplayName()) {
return false;
}
}
if (metamap.containsKey("lore") && im.hasLore() && !im.getLore().equals(iim.getLore())) {
return false;
}
if (metamap.containsKey("enchants") && !im.getEnchants().equals(iim.getEnchants())) {
return false;
}
}
}
return true;
}
use of com.laytonsmith.core.constructs.CNull in project CommandHelper by EngineHub.
the class MObject method set.
/**
* Sets the field to the given parameter. If the field is a non-dynamic property, it is actually set in the object
* (and converted properly), otherwise it is simply added to the dynamic field list.
*
* @param field
* @param value
* @param t
*/
public final void set(String field, Construct value, Target t) {
String alias = alias(field);
if (alias != null) {
field = alias;
}
for (Field f : this.getClass().getFields()) {
if (f.isAnnotationPresent(nofield.class)) {
// Skip this one
continue;
}
if (f.getName().equals(field)) {
// This is it, so let's set it, (converting if necessary) then break
Object val;
Class fType = f.getType();
if (value instanceof CNull) {
// TODO
// Easy case
val = null;
} else {
if (fType == byte.class) {
val = Static.getInt8(value, t);
} else if (fType == short.class) {
val = Static.getInt16(value, t);
} else if (fType == int.class) {
val = Static.getInt32(value, t);
} else if (fType == long.class) {
val = Static.getInt(value, t);
} else if (fType == char.class) {
if (value.val().length() == 0) {
val = null;
} else {
val = value.val().charAt(0);
}
} else if (fType == boolean.class) {
val = Static.getBoolean(value, t);
} else if (fType == float.class) {
val = Static.getDouble32(value, t);
} else if (fType == double.class) {
val = Static.getDouble(value, t);
} else if (fType == MMap.class) {
CArray ca = Static.getArray(value, t);
MMap m = new MMap();
for (String key : ca.stringKeySet()) {
m.put(key, ca.get(key, t));
}
val = m;
} else if (fType == MList.class) {
CArray ca = Static.getArray(value, t);
MList m = new MList();
if (ca.inAssociativeMode()) {
throw new CRECastException("Expected non-associative array, but an associative array was found instead.", t);
}
for (int i = 0; i < ca.size(); i++) {
m.add(ca.get(i, t));
}
val = m;
} else if (Construct.class.isAssignableFrom(fType)) {
val = value;
} else if (MObject.class.isAssignableFrom(fType)) {
CArray ca = Static.getArray(value, t);
val = MObject.Construct(fType, ca);
} else {
// Programming error.
throw new Error(this.getClass().getName() + " contained the public field " + f.getName() + " of type " + fType.getName() + ", which is an unsupported field type.");
}
}
try {
// val is now set correctly, guaranteed.
f.set(this, val);
// These exceptions cannot happen.
} catch (IllegalArgumentException | IllegalAccessException ex) {
throw new Error(ex);
}
}
}
// Always put the dynamic parameter, regardless
fields.put(field, value);
}
use of com.laytonsmith.core.constructs.CNull in project CommandHelper by EngineHub.
the class ObjectGenerator method vector.
/**
* Modifies an existing vector using a given vector object. Because Vector3D is immutable, this method does not
* actually modify the existing vector, but creates a new one.
*
* @param v the original vector
* @param c the vector array
* @param t the target
* @return the Vector
*/
public Vector3D vector(Vector3D v, Construct c, Target t) {
if (c instanceof CArray) {
CArray va = (CArray) c;
double x = v.X();
double y = v.Y();
double z = v.Z();
if (!va.isAssociative()) {
if (va.size() == 3) {
// 3rd dimension vector
x = Static.getNumber(va.get(0, t), t);
y = Static.getNumber(va.get(1, t), t);
z = Static.getNumber(va.get(2, t), t);
} else if (va.size() == 2) {
// 2nd dimension vector
x = Static.getNumber(va.get(0, t), t);
y = Static.getNumber(va.get(1, t), t);
} else if (va.size() == 1) {
x = Static.getNumber(va.get(0, t), t);
}
} else {
if (va.containsKey("x")) {
x = Static.getNumber(va.get("x", t), t);
}
if (va.containsKey("y")) {
y = Static.getNumber(va.get("y", t), t);
}
if (va.containsKey("z")) {
z = Static.getNumber(va.get("z", t), t);
}
}
return new Vector3D(x, y, z);
} else if (c instanceof CNull) {
// fulfilling the todo?
return v;
} else {
throw new CREFormatException("Expecting an array, received " + c.getCType(), t);
}
}
Aggregations