use of org.bukkit.inventory.meta.FireworkEffectMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method adjust.
@Override
public void adjust(Mechanism mechanism) {
if (mechanism.matches("firework")) {
dList fireworks = mechanism.getValue().asType(dList.class);
ItemMeta meta = item.getItemStack().getItemMeta();
for (String effect : fireworks) {
String[] data = effect.split(",");
if (data.length == 9) {
FireworkEffect.Builder builder = FireworkEffect.builder();
builder.trail(new Element(data[0]).asBoolean());
builder.flicker(new Element(data[1]).asBoolean());
if (new Element(data[2]).matchesEnum(FireworkEffect.Type.values())) {
builder.with(FireworkEffect.Type.valueOf(data[2].toUpperCase()));
} else {
dB.echoError("Invalid firework type '" + data[2] + "'");
}
builder.withColor(Color.fromRGB(new Element(data[3]).asInt(), new Element(data[4]).asInt(), new Element(data[5]).asInt()));
builder.withFade(Color.fromRGB(new Element(data[6]).asInt(), new Element(data[7]).asInt(), new Element(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 Element(data[0]).asInt());
} else {
dB.echoError("Cannot set the power of a firework effect!");
}
} else {
dB.echoError("Invalid firework data '" + effect + "'");
}
}
item.getItemStack().setItemMeta(meta);
}
}
use of org.bukkit.inventory.meta.FireworkEffectMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method getFireworkData.
public dList getFireworkData() {
List<FireworkEffect> effects;
dList list = new dList();
if (item.getItemStack().getItemMeta() instanceof FireworkMeta) {
effects = ((FireworkMeta) item.getItemStack().getItemMeta()).getEffects();
int power = ((FireworkMeta) item.getItemStack().getItemMeta()).getPower();
if (power != 0) {
list.add(String.valueOf(power));
}
} else {
effects = Arrays.asList(((FireworkEffectMeta) item.getItemStack().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;
}
Aggregations