use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemPotion method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("potion_effects")) {
List<ObjectTag> data = new ArrayList<>(CoreUtilities.objectToList(mechanism.value, mechanism.context));
ObjectTag firstObj = data.remove(0);
PotionMeta meta = getMeta();
PotionType type;
boolean upgraded = false;
boolean extended = false;
ColorTag color = null;
if (firstObj.canBeType(MapTag.class)) {
MapTag baseEffect = firstObj.asType(MapTag.class, mechanism.context);
if (baseEffect.getObject("type") != null) {
ElementTag typeElement = baseEffect.getObject("type").asElement();
if (!typeElement.matchesEnum(PotionType.class)) {
mechanism.echoError("Invalid base potion type '" + typeElement + "': type is required");
return;
}
type = PotionType.valueOf(typeElement.asString().toUpperCase());
} else {
mechanism.echoError("No base potion type specified: type is required");
return;
}
if (baseEffect.getObject("upgraded") != null) {
ElementTag upgradedElement = baseEffect.getObject("upgraded").asElement();
if (upgradedElement.isBoolean()) {
upgraded = upgradedElement.asBoolean();
} else {
mechanism.echoError("Invalid upgraded state '" + upgradedElement + "': must be a boolean");
}
}
if (baseEffect.getObject("extended") != null) {
ElementTag extendedElement = baseEffect.getObject("extended").asElement();
if (extendedElement.isBoolean()) {
extended = extendedElement.asBoolean();
} else {
mechanism.echoError("Invalid extended state '" + extendedElement + "': must be a boolean");
}
}
if (baseEffect.getObject("color") != null) {
ObjectTag colorObj = baseEffect.getObject("color");
if (colorObj.canBeType(ColorTag.class)) {
color = colorObj.asType(ColorTag.class, mechanism.context);
} else {
mechanism.echoError("Invalid color '" + colorObj + "': must be a valid ColorTag");
}
}
} else {
String[] d1 = firstObj.toString().split(",");
try {
type = PotionType.valueOf(d1[0].toUpperCase());
} catch (IllegalArgumentException ex) {
mechanism.echoError("Invalid base potion type '" + d1[0] + "': type is required");
return;
}
upgraded = CoreUtilities.equalsIgnoreCase(d1[1], "true");
extended = CoreUtilities.equalsIgnoreCase(d1[2], "true");
if (d1.length > 3) {
ColorTag temp = ColorTag.valueOf(d1[3].replace("&comma", ","), mechanism.context);
if (temp == null) {
mechanism.echoError("Invalid color '" + d1[3] + "': must be a valid ColorTag");
} else {
color = temp;
}
}
}
if (upgraded && !type.isUpgradeable()) {
mechanism.echoError("Cannot upgrade potion of type '" + type.name() + "'");
upgraded = false;
}
if (extended && !type.isExtendable()) {
mechanism.echoError("Cannot extend potion of type '" + type.name() + "'");
extended = false;
}
if (upgraded && extended) {
mechanism.echoError("Cannot both upgrade and extend a potion");
extended = false;
}
if (color != null) {
meta.setColor(color.getColor());
}
meta.setBasePotionData(new PotionData(type, extended, upgraded));
meta.clearCustomEffects();
for (ObjectTag effectObj : data) {
PotionEffect effect;
if (effectObj.canBeType(MapTag.class)) {
effect = parseEffect(effectObj.asType(MapTag.class, mechanism.context), mechanism.context);
} else {
effect = parseEffect(effectObj.toString(), mechanism.context);
}
if (effect != null) {
meta.addCustomEffect(effect, false);
} else {
mechanism.echoError("Invalid potion effect '" + effectObj + "'");
}
}
item.setItemMeta(meta);
}
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class FireworkCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
final LocationTag location = (LocationTag) scriptEntry.getObject("location");
ElementTag type = scriptEntry.getElement("type");
List<ColorTag> primary = scriptEntry.argForPrefixList("primary", ColorTag.class, true);
if (primary == null) {
primary = Collections.singletonList(new ColorTag(Color.YELLOW));
}
List<ColorTag> fade = scriptEntry.argForPrefixList("fade", ColorTag.class, true);
boolean flicker = scriptEntry.argAsBoolean("flicker");
boolean trail = scriptEntry.argAsBoolean("trail");
ElementTag power = scriptEntry.argForPrefixAsElement("power", "1");
DurationTag life = scriptEntry.argForPrefix("life", DurationTag.class, true);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), location, type, power, life, db("flicker", flicker), db("trail", trail), db("primary colors", primary), db("fade colors", fade));
}
Firework firework = location.getWorld().spawn(location, Firework.class);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
fireworkMeta.setPower(power.asInt());
Builder fireworkBuilder = FireworkEffect.builder();
fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
fireworkBuilder.withColor(Conversion.convertColors(primary));
if (fade != null) {
fireworkBuilder.withFade(Conversion.convertColors(fade));
}
if (flicker) {
fireworkBuilder.withFlicker();
}
if (trail) {
fireworkBuilder.withTrail();
}
fireworkMeta.addEffects(fireworkBuilder.build());
firework.setFireworkMeta(fireworkMeta);
if (life != null) {
NMSHandler.getEntityHelper().setFireworkLifetime(firework, life.getTicksAsInt());
}
scriptEntry.addObject("launched_firework", new EntityTag(firework));
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method getFireworkDataMap.
public ListTag getFireworkDataMap() {
List<FireworkEffect> effects;
ListTag list = new ListTag();
if (item.getItemMeta() instanceof FireworkMeta) {
effects = ((FireworkMeta) item.getItemMeta()).getEffects();
} else {
effects = Collections.singletonList(((FireworkEffectMeta) item.getItemMeta()).getEffect());
}
if (effects != null) {
for (FireworkEffect effect : effects) {
if (effect == null) {
continue;
}
Color ColOne = effect.getColors() != null && effect.getColors().size() > 0 ? effect.getColors().get(0) : Color.BLUE;
Color ColTwo = effect.getFadeColors() != null && effect.getFadeColors().size() > 0 ? effect.getFadeColors().get(0) : ColOne;
MapTag effectMap = new MapTag();
effectMap.putObject("trail", new ElementTag(effect.hasTrail()));
effectMap.putObject("flicker", new ElementTag(effect.hasFlicker()));
effectMap.putObject("type", new ElementTag(effect.getType().name()));
effectMap.putObject("color", new ColorTag(ColOne));
effectMap.putObject("fade_color", new ColorTag(ColTwo));
list.addObject(effectMap);
}
}
return list;
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("firework_power") && mechanism.requireInteger()) {
if (item.getItemMeta() instanceof FireworkMeta) {
ItemMeta meta = item.getItemMeta();
((FireworkMeta) meta).setPower(mechanism.getValue().asInt());
item.setItemMeta(meta);
} else {
mechanism.echoError("Cannot set the power of a firework effect!");
}
}
// -->
if (mechanism.matches("firework")) {
ItemMeta meta = item.getItemMeta();
if (!mechanism.hasValue()) {
if (meta instanceof FireworkMeta) {
((FireworkMeta) meta).clearEffects();
} else {
((FireworkEffectMeta) meta).setEffect(null);
}
} else {
Collection<ObjectTag> list = CoreUtilities.objectToList(mechanism.getValue(), mechanism.context);
for (ObjectTag object : list) {
if (object.canBeType(MapTag.class)) {
MapTag effectMap = object.asType(MapTag.class, mechanism.context);
FireworkEffect.Builder builder = FireworkEffect.builder();
ObjectTag type = effectMap.getObject("type");
ObjectTag color = effectMap.getObject("color");
ObjectTag fadeColor = effectMap.getObject("fade_color");
ObjectTag trail = effectMap.getObject("trail");
ObjectTag flicker = effectMap.getObject("flicker");
builder.trail(trail != null && trail.asElement().asBoolean());
builder.flicker(flicker != null && flicker.asElement().asBoolean());
if (type != null) {
ElementTag effectType = type.asElement();
if (effectType.matchesEnum(FireworkEffect.Type.class)) {
builder.with(FireworkEffect.Type.valueOf(effectType.asString().toUpperCase()));
} else {
mechanism.echoError("Invalid firework type '" + effectType.asString() + "'");
}
}
ColorTag co = new ColorTag(Color.BLACK);
if (color != null && ColorTag.matches(color.toString())) {
co = ColorTag.valueOf(color.toString(), mechanism.context);
} else if (color != null) {
mechanism.echoError("Invalid color '" + color + "'");
}
builder.withColor(co.getColor());
if (fadeColor != null) {
ColorTag fadeCo = ColorTag.valueOf(fadeColor.toString(), mechanism.context);
if (fadeCo != null) {
builder.withFade(fadeCo.getColor());
} else {
mechanism.echoError("Invalid fade color '" + fadeColor + "'");
}
}
FireworkEffect built = builder.build();
if (meta instanceof FireworkMeta) {
((FireworkMeta) meta).addEffect(built);
} else {
((FireworkEffectMeta) meta).setEffect(built);
}
} else {
String effect = object.toString();
String[] data = effect.split(",");
if (data.length == 9) {
FireworkEffect.Builder builder = FireworkEffect.builder();
builder.trail(new ElementTag(data[0]).asBoolean());
builder.flicker(new ElementTag(data[1]).asBoolean());
if (new ElementTag(data[2]).matchesEnum(FireworkEffect.Type.class)) {
builder.with(FireworkEffect.Type.valueOf(data[2].toUpperCase()));
} else {
mechanism.echoError("Invalid firework type '" + data[2] + "'");
}
builder.withColor(Color.fromRGB(new ElementTag(data[3]).asInt(), new ElementTag(data[4]).asInt(), new ElementTag(data[5]).asInt()));
builder.withFade(Color.fromRGB(new ElementTag(data[6]).asInt(), new ElementTag(data[7]).asInt(), new ElementTag(data[8]).asInt()));
FireworkEffect built = builder.build();
if (meta instanceof FireworkMeta) {
((FireworkMeta) meta).addEffect(built);
} else {
((FireworkEffectMeta) meta).setEffect(built);
}
} else if (data.length == 1) {
if (meta instanceof FireworkMeta) {
((FireworkMeta) meta).setPower(new ElementTag(data[0]).asInt());
} else {
mechanism.echoError("Cannot set the power of a firework effect!");
}
} else {
mechanism.echoError("Invalid firework data '" + effect + "'");
}
}
}
}
item.setItemMeta(meta);
}
}
use of com.denizenscript.denizen.objects.ColorTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemColor method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if ((mechanism.matches("dye") || mechanism.matches("dye_color") || mechanism.matches("color")) && (mechanism.requireObject(ColorTag.class))) {
ColorTag color = mechanism.valueAsType(ColorTag.class);
Material mat = item.getBukkitMaterial();
if (mat == Material.POTION || mat == Material.LINGERING_POTION || mat == Material.SPLASH_POTION) {
PotionMeta meta = (PotionMeta) item.getItemMeta();
meta.setColor(color.getColor());
item.setItemMeta(meta);
return;
}
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
meta.setColor(color.getColor());
item.setItemMeta(meta);
}
}
Aggregations