Search in sources :

Example 1 with Builder

use of org.bukkit.FireworkEffect.Builder in project Denizen-For-Bukkit by DenizenScript.

the class FireworkCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    final dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation();
    Element type = (Element) scriptEntry.getObject("type");
    Element power = (Element) scriptEntry.getObject("power");
    boolean flicker = scriptEntry.hasObject("flicker");
    boolean trail = scriptEntry.hasObject("trail");
    List<dColor> primary = (List<dColor>) scriptEntry.getObject("primary");
    List<dColor> fade = (List<dColor>) scriptEntry.getObject("fade");
    // Report to dB
    dB.report(scriptEntry, getName(), location.debug() + type.debug() + power.debug() + (flicker ? aH.debugObj("flicker", flicker) : "") + (trail ? aH.debugObj("trail", trail) : "") + aH.debugObj("primary colors", primary.toString()) + (fade != null ? aH.debugObj("fade colors", fade.toString()) : ""));
    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);
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dColor(net.aufdemrand.denizen.objects.dColor) Firework(org.bukkit.entity.Firework) Builder(org.bukkit.FireworkEffect.Builder) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 2 with Builder

use of org.bukkit.FireworkEffect.Builder in project EffectLib by Slikey.

the class BigBangEffect method onRun.

@Override
public void onRun() {
    if (firework == null) {
        Builder b = FireworkEffect.builder().with(fireworkType);
        b.withColor(color).withColor(color2).withColor(color3);
        b.withFade(fadeColor);
        b.trail(true);
        firework = b.build();
    }
    Location location = getLocation();
    for (int i = 0; i < explosions; i++) {
        Vector v = RandomUtils.getRandomVector().multiply(radius);
        detonate(location, v);
        if (soundInterval != 0 && step % soundInterval == 0) {
            location.getWorld().playSound(location, sound, soundVolume, soundPitch);
        }
    }
    step++;
}
Also used : Builder(org.bukkit.FireworkEffect.Builder) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 3 with Builder

use of org.bukkit.FireworkEffect.Builder in project Prism-Bukkit by prism.

the class ItemStackAction method setItemStackFromNewDataFormat.

/**
	 * 
	 */
protected void setItemStackFromNewDataFormat() {
    if (data == null || !data.startsWith("{"))
        return;
    actionData = gson.fromJson(data, ItemStackActionData.class);
    item = new ItemStack(this.block_id, actionData.amt, (short) this.block_subid);
    // Restore enchantment
    if (actionData.enchs != null && actionData.enchs.length > 0) {
        for (final String ench : actionData.enchs) {
            final String[] enchArgs = ench.split(":");
            final Enchantment enchantment = Enchantment.getById(Integer.parseInt(enchArgs[0]));
            // Restore book enchantment
            if (item.getType().equals(Material.ENCHANTED_BOOK)) {
                final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
                bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
                item.setItemMeta(bookEnchantments);
            } else // Restore item enchantment
            {
                item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
            }
        }
    }
    // Leather color
    if (item.getType().name().contains("LEATHER_") && actionData.color > 0) {
        final LeatherArmorMeta lam = (LeatherArmorMeta) item.getItemMeta();
        lam.setColor(Color.fromRGB(actionData.color));
        item.setItemMeta(lam);
    } else // Skulls
    if (item.getType().equals(Material.SKULL_ITEM) && actionData.owner != null) {
        final SkullMeta meta = (SkullMeta) item.getItemMeta();
        meta.setOwner(actionData.owner);
        item.setItemMeta(meta);
    } else // Written books
    if (item.getItemMeta() instanceof BookMeta) {
        final BookMeta bookMeta = (BookMeta) item.getItemMeta();
        bookMeta.setAuthor(actionData.by);
        bookMeta.setTitle(actionData.title);
        bookMeta.setPages(actionData.content);
        item.setItemMeta(bookMeta);
    }
    // Fireworks
    if (block_id == 402 && actionData.effectColors != null && actionData.effectColors.length > 0) {
        final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) item.getItemMeta();
        final Builder effect = FireworkEffect.builder();
        if (actionData.effectColors != null) {
            for (int i = 0; i < actionData.effectColors.length; i++) {
                effect.withColor(Color.fromRGB(actionData.effectColors[i]));
            }
            fireworkMeta.setEffect(effect.build());
        }
        if (actionData.fadeColors != null) {
            for (int i = 0; i < actionData.fadeColors.length; i++) {
                effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
            }
            fireworkMeta.setEffect(effect.build());
        }
        if (actionData.hasFlicker) {
            effect.flicker(true);
        }
        if (actionData.hasTrail) {
            effect.trail(true);
        }
        fireworkMeta.setEffect(effect.build());
        item.setItemMeta(fireworkMeta);
    }
    // Item display names
    final ItemMeta meta = item.getItemMeta();
    if (actionData.name != null) {
        meta.setDisplayName(actionData.name);
    }
    if (actionData.lore != null) {
        meta.setLore(Arrays.asList(actionData.lore));
    }
    item.setItemMeta(meta);
}
Also used : Builder(org.bukkit.FireworkEffect.Builder) SkullMeta(org.bukkit.inventory.meta.SkullMeta) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 4 with Builder

use of org.bukkit.FireworkEffect.Builder in project Prism-Bukkit by prism.

the class ItemStackAction method deserializeFireWorksMeta.

private static ItemStack deserializeFireWorksMeta(ItemStack item, ItemMeta meta, ItemStackActionData actionData) {
    final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
    final Builder effect = FireworkEffect.builder();
    for (int i = 0; i < actionData.effectColors.length; i++) {
        effect.withColor(Color.fromRGB(actionData.effectColors[i]));
    }
    fireworkMeta.setEffect(effect.build());
    if (actionData.fadeColors != null) {
        for (int i = 0; i < actionData.fadeColors.length; i++) {
            effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
        }
        fireworkMeta.setEffect(effect.build());
    }
    if (actionData.hasFlicker) {
        effect.flicker(true);
    }
    if (actionData.hasTrail) {
        effect.trail(true);
    }
    fireworkMeta.setEffect(effect.build());
    item.setItemMeta(fireworkMeta);
    return item;
}
Also used : Builder(org.bukkit.FireworkEffect.Builder) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta)

Example 5 with Builder

use of org.bukkit.FireworkEffect.Builder 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));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Firework(org.bukkit.entity.Firework) Builder(org.bukkit.FireworkEffect.Builder) ColorTag(com.denizenscript.denizen.objects.ColorTag) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Aggregations

Builder (org.bukkit.FireworkEffect.Builder)5 Firework (org.bukkit.entity.Firework)2 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)2 FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)2 ColorTag (com.denizenscript.denizen.objects.ColorTag)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 List (java.util.List)1 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 net.aufdemrand.denizen.objects.dColor (net.aufdemrand.denizen.objects.dColor)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 Element (net.aufdemrand.denizencore.objects.Element)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 Location (org.bukkit.Location)1 Enchantment (org.bukkit.enchantments.Enchantment)1 ItemStack (org.bukkit.inventory.ItemStack)1 BookMeta (org.bukkit.inventory.meta.BookMeta)1 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)1