Search in sources :

Example 1 with Firework

use of org.bukkit.entity.Firework 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 Firework

use of org.bukkit.entity.Firework in project Minigames by AddstarMC.

the class PlayerData method partyMode.

public void partyMode(MinigamePlayer player) {
    if (onPartyMode()) {
        Location loc = player.getPlayer().getLocation();
        Firework firework = (Firework) player.getPlayer().getWorld().spawnEntity(loc, EntityType.FIREWORK);
        FireworkMeta fwm = firework.getFireworkMeta();
        Random chance = new Random();
        Type type = Type.BALL_LARGE;
        if (chance.nextInt(100) < 50) {
            type = Type.BALL;
        }
        Color col = Color.fromRGB(chance.nextInt(255), chance.nextInt(255), chance.nextInt(255));
        FireworkEffect effect = FireworkEffect.builder().with(type).withColor(col).flicker(chance.nextBoolean()).trail(chance.nextBoolean()).build();
        fwm.addEffect(effect);
        fwm.setPower(1);
        firework.setFireworkMeta(fwm);
    }
}
Also used : Type(org.bukkit.FireworkEffect.Type) EntityType(org.bukkit.entity.EntityType) MinigameType(au.com.mineauz.minigames.gametypes.MinigameType) Random(java.util.Random) Firework(org.bukkit.entity.Firework) Color(org.bukkit.Color) ChatColor(org.bukkit.ChatColor) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffect(org.bukkit.FireworkEffect) Location(org.bukkit.Location)

Example 3 with Firework

use of org.bukkit.entity.Firework in project Essentials by drtshock.

the class Commandfirework method run.

@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    final ItemStack stack = user.getBase().getItemInHand();
    if (stack.getType() == Material.FIREWORK) {
        if (args.length > 0) {
            if (args[0].equalsIgnoreCase("clear")) {
                FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
                fmeta.clearEffects();
                stack.setItemMeta(fmeta);
                user.sendMessage(tl("fireworkEffectsCleared"));
            } else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p")))) {
                FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
                try {
                    int power = Integer.parseInt(args[1]);
                    fmeta.setPower(power > 3 ? 4 : power);
                } catch (NumberFormatException e) {
                    throw new Exception(tl("invalidFireworkFormat", args[1], args[0]));
                }
                stack.setItemMeta(fmeta);
            } else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("f"))) && user.isAuthorized("essentials.firework.fire")) {
                int amount = 1;
                boolean direction = false;
                if (args.length > 1) {
                    if (NumberUtil.isInt(args[1])) {
                        final int serverLimit = ess.getSettings().getSpawnMobLimit();
                        amount = Integer.parseInt(args[1]);
                        if (amount > serverLimit) {
                            amount = serverLimit;
                            user.sendMessage(tl("mobSpawnLimit"));
                        }
                    } else {
                        direction = true;
                    }
                }
                for (int i = 0; i < amount; i++) {
                    Firework firework = (Firework) user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
                    FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
                    if (direction) {
                        final Vector vector = user.getBase().getEyeLocation().getDirection().multiply(0.070);
                        if (fmeta.getPower() > 1) {
                            fmeta.setPower(1);
                        }
                        firework.setVelocity(vector);
                    }
                    firework.setFireworkMeta(fmeta);
                }
            } else {
                final MetaItemStack mStack = new MetaItemStack(stack);
                for (String arg : args) {
                    try {
                        mStack.addFireworkMeta(user.getSource(), true, arg, ess);
                    } catch (Exception e) {
                        user.sendMessage(tl("fireworkSyntax"));
                        throw e;
                    }
                }
                if (mStack.isValidFirework()) {
                    FireworkMeta fmeta = (FireworkMeta) mStack.getItemStack().getItemMeta();
                    FireworkEffect effect = mStack.getFireworkBuilder().build();
                    if (fmeta.getEffects().size() > 0 && !user.isAuthorized("essentials.firework.multiple")) {
                        throw new Exception(tl("multipleCharges"));
                    }
                    fmeta.addEffect(effect);
                    stack.setItemMeta(fmeta);
                } else {
                    user.sendMessage(tl("fireworkSyntax"));
                    throw new Exception(tl("fireworkColor"));
                }
            }
        } else {
            throw new NotEnoughArgumentsException();
        }
    } else {
        throw new Exception(tl("holdFirework"));
    }
}
Also used : Firework(org.bukkit.entity.Firework) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) MetaItemStack(com.earth2me.essentials.MetaItemStack) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) MetaItemStack(com.earth2me.essentials.MetaItemStack) FireworkEffect(org.bukkit.FireworkEffect)

Aggregations

Firework (org.bukkit.entity.Firework)3 FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)3 FireworkEffect (org.bukkit.FireworkEffect)2 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)1 MetaItemStack (com.earth2me.essentials.MetaItemStack)1 List (java.util.List)1 Random (java.util.Random)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 ChatColor (org.bukkit.ChatColor)1 Color (org.bukkit.Color)1 Builder (org.bukkit.FireworkEffect.Builder)1 Type (org.bukkit.FireworkEffect.Type)1 Location (org.bukkit.Location)1 EntityType (org.bukkit.entity.EntityType)1 ItemStack (org.bukkit.inventory.ItemStack)1 Vector (org.bukkit.util.Vector)1