Search in sources :

Example 1 with Color

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

the class MapDot method render.

@Override
public void render(MapView mapView, MapCanvas mapCanvas, dPlayer player, UUID uuid) {
    int baseX = getX(player, uuid);
    int baseY = getY(player, uuid);
    int radius = (int) aH.getDoubleFrom(tag(radiusTag, player));
    Color color = dColor.valueOf(tag(colorTag, player)).getColor();
    for (int x = -radius; x < radius; x++) {
        int finalX = baseX + x;
        if (finalX >= 128) {
            continue;
        }
        for (int y = -radius; y < radius; y++) {
            int finalY = baseY + y;
            if (finalY >= 128) {
                continue;
            }
            if (((x + 0.5) * (x + 0.5)) + ((y + 0.5) * (y + 0.5)) <= (radius * radius)) {
                mapCanvas.setPixel(finalX, finalY, MapPalette.matchColor(color.getRed(), color.getGreen(), color.getBlue()));
            }
        }
    }
}
Also used : Color(org.bukkit.Color) net.aufdemrand.denizen.objects.dColor(net.aufdemrand.denizen.objects.dColor)

Example 2 with Color

use of org.bukkit.Color in project Glowstone by GlowstoneMC.

the class GlowChargeFadeMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    ItemStack charge = null;
    List<Color> colors = new ArrayList<>();
    for (ItemStack item : matrix) {
        if (item == null)
            continue;
        switch(item.getType()) {
            case INK_SACK:
                Dye dye = (Dye) item.getData();
                colors.add(dye.getColor().getFireworkColor());
                break;
            case FIREWORK_CHARGE:
                charge = item;
                break;
            default:
                // Wrong item on matrix
                return null;
        }
    }
    // No charge, or no colors
    if (charge == null || colors.isEmpty())
        return null;
    FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
    FireworkEffect old = meta.getEffect();
    FireworkEffect newEffect = FireworkEffect.builder().with(old.getType()).withColor(old.getColors()).flicker(old.hasFlicker()).trail(old.hasTrail()).withFade(colors).build();
    meta.setEffect(newEffect);
    ItemStack ret = charge.clone();
    ret.setItemMeta(meta);
    return ret;
}
Also used : Dye(org.bukkit.material.Dye) Color(org.bukkit.Color) ArrayList(java.util.ArrayList) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) FireworkEffect(org.bukkit.FireworkEffect)

Example 3 with Color

use of org.bukkit.Color in project Glowstone by GlowstoneMC.

the class GlowChargeMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    boolean hasGunpowder = false;
    boolean trail = false;
    boolean twinkle = false;
    List<Color> colors = new ArrayList<>();
    Type type = Type.BALL;
    for (ItemStack item : matrix) {
        if (item == null)
            continue;
        switch(item.getType()) {
            case SULPHUR:
                // Only 1 gunpowder allowed
                if (hasGunpowder)
                    return null;
                hasGunpowder = true;
                break;
            case INK_SACK:
                Dye dye = (Dye) item.getData();
                colors.add(dye.getColor().getFireworkColor());
                break;
            case DIAMOND:
                // Only 1 diamond allowed
                if (trail)
                    return null;
                trail = true;
                break;
            case GLOWSTONE_DUST:
                // Only 1 dust allowed
                if (twinkle)
                    return null;
                twinkle = true;
                break;
            case FIREBALL:
                if (type != Type.BALL)
                    return null;
                type = Type.BALL_LARGE;
                break;
            case GOLD_NUGGET:
                if (type != Type.BALL)
                    return null;
                type = Type.STAR;
                break;
            case FEATHER:
                if (type != Type.BALL)
                    return null;
                type = Type.BURST;
                break;
            case SKULL_ITEM:
                if (type != Type.BALL)
                    return null;
                type = Type.CREEPER;
                break;
            default:
                // Non firework item on matrix
                return null;
        }
    }
    // Not enough ingredients
    if (!hasGunpowder || colors.isEmpty())
        return null;
    FireworkEffect effect = FireworkEffect.builder().withColor(colors).trail(trail).flicker(twinkle).with(type).build();
    ItemStack charge = new ItemStack(Material.FIREWORK_CHARGE, 1);
    FireworkEffectMeta meta = (FireworkEffectMeta) charge.getItemMeta();
    meta.setEffect(effect);
    charge.setItemMeta(meta);
    return charge;
}
Also used : Dye(org.bukkit.material.Dye) Type(org.bukkit.FireworkEffect.Type) Color(org.bukkit.Color) ArrayList(java.util.ArrayList) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) FireworkEffect(org.bukkit.FireworkEffect)

Example 4 with Color

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

the class ItemStackAction method setItem.

/**
     * 
     * @param action_type
     * @param block
     * @param player
     */
public void setItem(ItemStack item, int quantity, int slot, Map<Enchantment, Integer> enchantments) {
    actionData = new ItemStackActionData();
    if (enchantments != null) {
        this.enchantments = enchantments;
    }
    if (item == null || item.getAmount() <= 0) {
        this.setCanceled(true);
        return;
    }
    this.item = item;
    if (enchantments == null) {
        this.enchantments = item.getEnchantments();
    }
    // Set basics
    this.block_id = item.getTypeId();
    this.block_subid = item.getDurability();
    actionData.amt = quantity;
    if (slot >= 0) {
        actionData.slot = slot;
    }
    // Set additional data all items may have
    final ItemMeta meta = item.getItemMeta();
    if (meta != null && meta.getDisplayName() != null) {
        actionData.name = meta.getDisplayName();
    }
    // Leather Coloring
    if (meta != null && item.getType().name().contains("LEATHER_")) {
        final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
        if (lam.getColor() != null) {
            actionData.color = lam.getColor().asRGB();
        }
    } else // Skull Owner
    if (meta != null && item.getType().equals(Material.SKULL_ITEM)) {
        final SkullMeta skull = (SkullMeta) meta;
        if (skull.hasOwner()) {
            actionData.owner = skull.getOwner();
        }
    }
    // Written books
    if (meta != null && meta instanceof BookMeta) {
        final BookMeta bookMeta = (BookMeta) meta;
        actionData.by = bookMeta.getAuthor();
        actionData.title = bookMeta.getTitle();
        actionData.content = bookMeta.getPages().toArray(new String[0]);
    }
    // Lore
    if (meta != null && meta.getLore() != null) {
        actionData.lore = meta.getLore().toArray(new String[0]);
    }
    // Enchantments
    if (!this.enchantments.isEmpty()) {
        final String[] enchs = new String[this.enchantments.size()];
        int i = 0;
        for (final Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
            enchs[i] = ench.getKey().getId() + ":" + ench.getValue();
            i++;
        }
        actionData.enchs = enchs;
    } else // Book enchantments
    if (meta != null && item.getType().equals(Material.ENCHANTED_BOOK)) {
        final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
        if (bookEnchantments.hasStoredEnchants()) {
            if (bookEnchantments.getStoredEnchants().size() > 0) {
                final String[] enchs = new String[bookEnchantments.getStoredEnchants().size()];
                int i = 0;
                for (final Entry<Enchantment, Integer> ench : bookEnchantments.getStoredEnchants().entrySet()) {
                    enchs[i] = ench.getKey().getId() + ":" + ench.getValue();
                    i++;
                }
                actionData.enchs = enchs;
            }
        }
    }
    // Fireworks
    if (meta != null && block_id == 402) {
        final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
        if (fireworkMeta.hasEffect()) {
            final FireworkEffect effect = fireworkMeta.getEffect();
            if (!effect.getColors().isEmpty()) {
                final int[] effectColors = new int[effect.getColors().size()];
                int i = 0;
                for (final Color effectColor : effect.getColors()) {
                    effectColors[i] = effectColor.asRGB();
                    i++;
                }
                actionData.effectColors = effectColors;
            }
            if (!effect.getFadeColors().isEmpty()) {
                final int[] fadeColors = new int[effect.getColors().size()];
                final int i = 0;
                for (final Color fadeColor : effect.getFadeColors()) {
                    fadeColors[i] = fadeColor.asRGB();
                }
                actionData.fadeColors = fadeColors;
            }
            if (effect.hasFlicker()) {
                actionData.hasFlicker = true;
            }
            if (effect.hasTrail()) {
                actionData.hasTrail = true;
            }
        }
    }
}
Also used : Color(org.bukkit.Color) SkullMeta(org.bukkit.inventory.meta.SkullMeta) FireworkEffect(org.bukkit.FireworkEffect) Entry(java.util.Map.Entry) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 5 with Color

use of org.bukkit.Color 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;
}
Also used : net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Color(org.bukkit.Color) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) FireworkEffect(org.bukkit.FireworkEffect)

Aggregations

Color (org.bukkit.Color)13 FireworkEffect (org.bukkit.FireworkEffect)7 ArrayList (java.util.ArrayList)4 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)4 DyeColor (org.bukkit.DyeColor)3 Type (org.bukkit.FireworkEffect.Type)3 ItemStack (org.bukkit.inventory.ItemStack)3 Banner (org.bukkit.block.Banner)2 PatternType (org.bukkit.block.banner.PatternType)2 Enchantment (org.bukkit.enchantments.Enchantment)2 FireworkMeta (org.bukkit.inventory.meta.FireworkMeta)2 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)2 Dye (org.bukkit.material.Dye)2 MinigameType (au.com.mineauz.minigames.gametypes.MinigameType)1 Field (java.lang.reflect.Field)1 Entry (java.util.Map.Entry)1 Random (java.util.Random)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 net.aufdemrand.denizen.objects.dColor (net.aufdemrand.denizen.objects.dColor)1