use of com.laytonsmith.abstraction.MCFireworkBuilder in project CommandHelper by EngineHub.
the class ObjectGenerator method fireworkEffect.
public MCFireworkEffect fireworkEffect(CArray fe, Target t) {
MCFireworkBuilder builder = StaticLayer.GetConvertor().GetFireworkBuilder();
if (fe.containsKey("flicker")) {
builder.setFlicker(Static.getBoolean(fe.get("flicker", t), t));
}
if (fe.containsKey("trail")) {
builder.setTrail(Static.getBoolean(fe.get("trail", t), t));
}
if (fe.containsKey("colors")) {
Construct colors = fe.get("colors", t);
if (colors instanceof CArray) {
CArray ccolors = (CArray) colors;
if (ccolors.size() == 0) {
builder.addColor(MCColor.WHITE);
} else {
for (Construct color : ccolors.asList()) {
MCColor mccolor;
if (color instanceof CString) {
mccolor = StaticLayer.GetConvertor().GetColor(color.val(), t);
} else if (color instanceof CArray) {
mccolor = color((CArray) color, t);
} else if (color instanceof CInt && ccolors.size() == 3) {
// Appears to be a single color
builder.addColor(color(ccolors, t));
break;
} else {
throw new CREFormatException("Expecting individual color to be an array or string, but found " + color.typeof(), t);
}
builder.addColor(mccolor);
}
}
} else if (colors instanceof CString) {
String[] split = colors.val().split("\\|");
if (split.length == 0) {
builder.addColor(MCColor.WHITE);
} else {
for (String s : split) {
builder.addColor(StaticLayer.GetConvertor().GetColor(s, t));
}
}
} else {
throw new CREFormatException("Expecting an array or string for colors parameter, but found " + colors.typeof(), t);
}
} else {
builder.addColor(MCColor.WHITE);
}
if (fe.containsKey("fade")) {
Construct colors = fe.get("fade", t);
if (colors instanceof CArray) {
CArray ccolors = (CArray) colors;
for (Construct color : ccolors.asList()) {
MCColor mccolor;
if (color instanceof CArray) {
mccolor = color((CArray) color, t);
} else if (color instanceof CString) {
mccolor = StaticLayer.GetConvertor().GetColor(color.val(), t);
} else if (color instanceof CInt && ccolors.size() == 3) {
// Appears to be a single color
builder.addFadeColor(color(ccolors, t));
break;
} else {
throw new CREFormatException("Expecting individual color to be an array or string, but found " + color.typeof(), t);
}
builder.addFadeColor(mccolor);
}
} else if (colors instanceof CString) {
String[] split = colors.val().split("\\|");
for (String s : split) {
builder.addFadeColor(StaticLayer.GetConvertor().GetColor(s, t));
}
} else {
throw new CREFormatException("Expecting an array or string for fade parameter, but found " + colors.typeof(), t);
}
}
if (fe.containsKey("type")) {
try {
builder.setType(MCFireworkType.valueOf(fe.get("type", t).val().toUpperCase()));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(ex.getMessage(), t, ex);
}
}
return builder.build();
}
Aggregations