Search in sources :

Example 6 with Color

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

the class dColor method valueOf.

/**
     * Gets a Color Object from a string form.
     *
     * @param string the string
     * @return a Color, or null if incorrectly formatted
     */
@Fetchable("co")
public static dColor valueOf(String string, TagContext context) {
    string = string.toUpperCase().replace("CO@", "");
    if (string.matches("RANDOM")) {
        // Get a color using random RGB values
        return new dColor(CoreUtilities.getRandom().nextInt(256), CoreUtilities.getRandom().nextInt(256), CoreUtilities.getRandom().nextInt(256));
    }
    Matcher m = rgbPattern.matcher(string);
    if (m.matches()) {
        return new dColor(aH.getIntegerFrom(m.group(1)), aH.getIntegerFrom(m.group(2)), aH.getIntegerFrom(m.group(3)));
    }
    Field colorField = null;
    try {
        colorField = Color.class.getField(string.toUpperCase());
    } catch (SecurityException e1) {
        dB.echoError("Security exception getting color field!");
    } catch (NoSuchFieldException e1) {
        dB.echoError("No such color field!");
    }
    if (colorField != null) {
        return new dColor(colorField);
    }
    // No match
    return null;
}
Also used : Field(java.lang.reflect.Field) Matcher(java.util.regex.Matcher) DyeColor(org.bukkit.DyeColor) Color(org.bukkit.Color)

Example 7 with Color

use of org.bukkit.Color 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 8 with Color

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

the class GlowMetaFireworkEffect method toEffect.

static FireworkEffect toEffect(CompoundTag explosion) {
    boolean flicker = false;
    boolean trail = false;
    Type type;
    List<Color> colors = new ArrayList<>();
    List<Color> fadeColors = new ArrayList<>();
    int[] colorInts = explosion.getIntArray("Colors");
    for (int color : colorInts) {
        colors.add(Color.fromRGB(color));
    }
    type = Type.values()[explosion.getByte("Type")];
    if (explosion.isByte("Flicker"))
        flicker = explosion.getBool("Flicker");
    if (explosion.isByte("Trail"))
        trail = explosion.getBool("Trail");
    if (explosion.isIntArray("FadeColors")) {
        int[] fadeInts = explosion.getIntArray("FadeColors");
        for (int fade : fadeInts) {
            fadeColors.add(Color.fromRGB(fade));
        }
    }
    return FireworkEffect.builder().flicker(flicker).trail(trail).with(type).withColor(colors).withFade(fadeColors).build();
}
Also used : Type(org.bukkit.FireworkEffect.Type) Color(org.bukkit.Color) ArrayList(java.util.ArrayList)

Example 9 with Color

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

the class GlowMetaFireworkEffect method toExplosion.

static CompoundTag toExplosion(FireworkEffect effect) {
    CompoundTag explosion = new CompoundTag();
    if (effect.hasFlicker())
        explosion.putBool("Flicker", true);
    if (effect.hasTrail())
        explosion.putBool("Trail", true);
    explosion.putByte("Type", effect.getType().ordinal());
    List<Color> colors = effect.getColors();
    List<Integer> colorInts = colors.stream().map(Color::asRGB).collect(Collectors.toList());
    explosion.putIntArray("Colors", Ints.toArray(colorInts));
    List<Color> fade = effect.getFadeColors();
    if (!fade.isEmpty()) {
        List<Integer> fadeInts = fade.stream().map(Color::asRGB).collect(Collectors.toList());
        explosion.putIntArray("FadeColors", Ints.toArray(fadeInts));
    }
    return explosion;
}
Also used : Color(org.bukkit.Color) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 10 with Color

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

the class GlowArmorDyeMatcher method getResult.

@Override
public ItemStack getResult(ItemStack[] matrix) {
    ItemStack armor = null;
    List<Color> colors = new ArrayList<>();
    for (ItemStack item : matrix) {
        if (item == null)
            continue;
        if (item.getType() == Material.INK_SACK) {
            Color color = ((Dye) item.getData()).getColor().getColor();
            colors.add(color);
            continue;
        }
        if (LEATHERS.matches(item.getType())) {
            // Can't dye more than one item
            if (armor != null)
                return null;
            armor = item;
            continue;
        }
        // Non-armor item
        return null;
    }
    // No armor
    if (armor == null)
        return null;
    // No colors
    if (colors.isEmpty())
        return null;
    LeatherArmorMeta meta = (LeatherArmorMeta) armor.getItemMeta();
    Color base = meta.getColor();
    if (meta.getColor() == GlowItemFactory.instance().getDefaultLeatherColor()) {
        base = colors.remove(0);
    }
    Color newColor = base.mixColors(colors.toArray(new Color[colors.size()]));
    ItemStack ret = armor.clone();
    LeatherArmorMeta retMeta = (LeatherArmorMeta) ret.getItemMeta();
    retMeta.setColor(newColor);
    ret.setItemMeta(retMeta);
    return ret;
}
Also used : Color(org.bukkit.Color) ArrayList(java.util.ArrayList) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ItemStack(org.bukkit.inventory.ItemStack)

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