use of org.bukkit.inventory.meta.FireworkMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <ItemTag.firework>
// @returns ListTag
// @group properties
// @mechanism ItemTag.firework
// @description
// Returns the firework's property value as a list, matching the non-MapTag format of the mechanism.
// Consider instead using <@link tag ItemTag.firework_data>
// -->
PropertyParser.<ItemFirework, ListTag>registerTag(ListTag.class, "firework", (attribute, object) -> {
return object.getFireworkData();
});
// <--[tag]
// @attribute <ItemTag.firework_data>
// @returns ListTag
// @group properties
// @mechanism ItemTag.firework
// @description
// Returns the firework's property value as a ListTag of MapTags, matching the MapTag format of the mechanism.
// -->
PropertyParser.<ItemFirework, ListTag>registerTag(ListTag.class, "firework_data", (attribute, object) -> {
return object.getFireworkDataMap();
});
// <--[tag]
// @attribute <ItemTag.firework_power>
// @returns ElementTag(Number)
// @group properties
// @mechanism ItemTag.firework_power
// @description
// Returns the firework's power.
// Power primarily affects how high the firework flies, with each level of power corresponding to approximately half a second of additional flight them.
// -->
PropertyParser.<ItemFirework, ElementTag>registerTag(ElementTag.class, "firework_power", (attribute, object) -> {
ItemMeta meta = object.item.getItemMeta();
return meta instanceof FireworkMeta ? new ElementTag(((FireworkMeta) meta).getPower()) : null;
});
}
use of org.bukkit.inventory.meta.FireworkMeta 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 org.bukkit.inventory.meta.FireworkMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method getFireworkData.
public ListTag getFireworkData() {
List<FireworkEffect> effects;
ListTag list = new ListTag();
if (item.getItemMeta() instanceof FireworkMeta) {
effects = ((FireworkMeta) item.getItemMeta()).getEffects();
int power = ((FireworkMeta) item.getItemMeta()).getPower();
if (power != 0) {
list.add(String.valueOf(power));
}
} 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;
list.add(effect.hasTrail() + "," + effect.hasFlicker() + "," + effect.getType().name() + "," + ColOne.getRed() + "," + ColOne.getGreen() + "," + ColOne.getBlue() + "," + ColTwo.getRed() + "," + ColTwo.getGreen() + "," + ColTwo.getBlue());
}
}
return list;
}
use of org.bukkit.inventory.meta.FireworkMeta 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);
}
}
Aggregations