Java Code Examples for org.bukkit.Color#fromRGB()

The following examples show how to use org.bukkit.Color#fromRGB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftMetaMap.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
CraftMetaMap(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(MAP_SCALING.NBT)) {
        this.scaling = tag.getBoolean(MAP_SCALING.NBT) ? SCALING_TRUE : SCALING_FALSE;
    }

    if (tag.hasKey(DISPLAY.NBT)) {
        NBTTagCompound display = tag.getCompoundTag(DISPLAY.NBT);

        if (display.hasKey(MAP_LOC_NAME.NBT)) {
            locName = display.getString(MAP_LOC_NAME.NBT);
        }

        if (display.hasKey(MAP_COLOR.NBT)) {
            color = Color.fromRGB(display.getInteger(MAP_COLOR.NBT));
        }
    }
}
 
Example 2
Source File: ItemUtils.java    From ChestCommands with GNU General Public License v3.0 6 votes vote down vote up
public static Color parseColor(String input) throws FormatException {
	String[] split = StringUtils.stripChars(input, " ").split(",");

	if (split.length != 3) {
		throw new FormatException("it must be in the format \"red, green, blue\".");
	}

	int red, green, blue;

	try {
		red = Integer.parseInt(split[0]);
		green = Integer.parseInt(split[1]);
		blue = Integer.parseInt(split[2]);
	} catch (NumberFormatException ex) {
		throw new FormatException("it contains invalid numbers.");
	}

	if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) {
		throw new FormatException("it should only contain numbers between 0 and 255.");
	}

	return Color.fromRGB(red, green, blue);
}
 
Example 3
Source File: XParticle.java    From XSeries with MIT License 5 votes vote down vote up
/**
 * Generate a random RGB color for particles.
 *
 * @return a random color.
 * @since 1.0.0
 */
public static Color randomColor() {
    ThreadLocalRandom gen = ThreadLocalRandom.current();
    int randR = gen.nextInt(0, 256);
    int randG = gen.nextInt(0, 256);
    int randB = gen.nextInt(0, 256);

    return Color.fromRGB(randR, randG, randB);
}
 
Example 4
Source File: CraftMetaLeatherArmor.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
CraftMetaLeatherArmor(NBTTagCompound tag) {
    super(tag);
    if (tag.hasKey(DISPLAY.NBT)) {
        NBTTagCompound display = tag.getCompoundTag(DISPLAY.NBT);
        if (display.hasKey(COLOR.NBT)) {
            color = Color.fromRGB(display.getInteger(COLOR.NBT));
        }
    }
}
 
Example 5
Source File: Items.java    From TabooLib with MIT License 5 votes vote down vote up
public static Color asColor(String color) {
    try {
        String[] v = color.split("-");
        return Color.fromRGB(NumberConversions.toInt(v[0]), NumberConversions.toInt(v[1]), NumberConversions.toInt(v[2]));
    } catch (Throwable e) {
        return Color.fromRGB(0, 0, 0);
    }
}
 
Example 6
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get a Color from a JSONObject. If any one of the red, green, or blue keys are not found,
 * they are given a value of 0 by default. Therefore, if the red and green values found were both 0,
 * and the blue key is not found, the resulting color is black (0, 0, 0).
 *
 * @param color The JSONObject to construct a Color from.
 * @return The decoded Color
 */
private static Color getColor(JsonObject color) {
    int r = 0, g = 0, b = 0;
    if (color.has("red"))
        r = color.get("red").getAsInt();
    if (color.has("green"))
        g = color.get("green").getAsInt();
    if (color.has("blue"))
        b = color.get("blue").getAsInt();
    return Color.fromRGB(r, g, b);
}
 
Example 7
Source File: CraftMetaLeatherArmor.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
CraftMetaLeatherArmor(net.minecraft.nbt.NBTTagCompound tag) {
    super(tag);
    if (tag.hasKey(DISPLAY.NBT)) {
        net.minecraft.nbt.NBTTagCompound display = tag.getCompoundTag(DISPLAY.NBT);
        if (display.hasKey(COLOR.NBT)) {
            color = Color.fromRGB(display.getInteger(COLOR.NBT));
        }
    }
}
 
Example 8
Source File: Utils.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parses the string as RGB or as DyeColor and returns it as Color.
 *
 * @param string string to parse as a Color
 * @return the Color (never null)
 * @throws InstructionParseException when something goes wrong
 */
public static Color getColor(String string) throws InstructionParseException {
    if (string == null || string.isEmpty()) {
        throw new InstructionParseException("Color is not specified");
    }
    try {
        return Color.fromRGB(Integer.parseInt(string));
    } catch (NumberFormatException e1) {
        LogUtils.logThrowableIgnore(e1);
        // string is not a decimal number
        try {
            return Color.fromRGB(Integer.parseInt(string.replace("#", ""), 16));
        } catch (NumberFormatException e2) {
            LogUtils.logThrowableIgnore(e2);
            // string is not a hexadecimal number, try dye color
            try {
                return DyeColor.valueOf(string.trim().toUpperCase().replace(' ', '_')).getColor();
            } catch (IllegalArgumentException e3) {
                // this was not a dye color name
                throw new InstructionParseException("Dye color does not exist: " + string, e3);
            }
        }
    } catch (IllegalArgumentException e) {
        // string was a number, but incorrect
        throw new InstructionParseException("Incorrect RGB code: " + string, e);
    }
}
 
Example 9
Source File: DeprecatedMethodUtil.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get a Color from a JSONObject. If any one of the red, green, or blue keys are not found,
 * they are given a value of 0 by default. Therefore, if the red and green values found were both 0,
 * and the blue key is not found, the resulting color is black (0, 0, 0).
 *
 * @param color The JSONObject to construct a Color from.
 * @return The decoded Color
 */
private static Color getColor(JsonObject color) {
    int r = 0, g = 0, b = 0;
    if (color.has("red"))
        r = color.get("red").getAsInt();
    if (color.has("green"))
        g = color.get("green").getAsInt();
    if (color.has("blue"))
        b = color.get("blue").getAsInt();
    return Color.fromRGB(r, g, b);
}
 
Example 10
Source File: ColorVariable.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String get() {
	NBTTagCompound data = data();
	Color color = Color.fromRGB(data.getInt(_key));
	String r = Integer.toHexString(color.getRed());
	String g = Integer.toHexString(color.getGreen());
	String b = Integer.toHexString(color.getBlue());
	return "#" + (r.length() == 1 ? "0" + r : r) + (g.length() == 1 ? "0" + g : g) + (b.length() == 1 ? "0" + b : b);
}
 
Example 11
Source File: CraftTippedArrow.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Color getColor() {
    return Color.fromRGB(getHandle().getColor());
}
 
Example 12
Source File: CraftAreaEffectCloud.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Color getColor() {
    return Color.fromRGB(getHandle().getColor());
}
 
Example 13
Source File: CraftPotionEffectType.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Color getColor() {
    return Color.fromRGB(handle.getLiquidColor());
}
 
Example 14
Source File: ItemBuilder.java    From Crazy-Crates with MIT License 4 votes vote down vote up
private static Color getColor(String color) {
    if (color != null) {
        switch (color.toUpperCase()) {
            case "AQUA":
                return Color.AQUA;
            case "BLACK":
                return Color.BLACK;
            case "BLUE":
                return Color.BLUE;
            case "FUCHSIA":
                return Color.FUCHSIA;
            case "GRAY":
                return Color.GRAY;
            case "GREEN":
                return Color.GREEN;
            case "LIME":
                return Color.LIME;
            case "MAROON":
                return Color.MAROON;
            case "NAVY":
                return Color.NAVY;
            case "OLIVE":
                return Color.OLIVE;
            case "ORANGE":
                return Color.ORANGE;
            case "PURPLE":
                return Color.PURPLE;
            case "RED":
                return Color.RED;
            case "SILVER":
                return Color.SILVER;
            case "TEAL":
                return Color.TEAL;
            case "WHITE":
                return Color.WHITE;
            case "YELLOW":
                return Color.YELLOW;
        }
        try {
            String[] rgb = color.split(",");
            return Color.fromRGB(Integer.parseInt(rgb[0]), Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]));
        } catch (Exception ignore) {
        }
    }
    return null;
}
 
Example 15
Source File: MiscUtil.java    From CardinalPGM with MIT License 4 votes vote down vote up
public static Color convertHexToRGB(String color) {
    return Color.fromRGB(Integer.valueOf(color.substring(0, 2), 16), Integer.valueOf(color.substring(2, 4), 16), Integer.valueOf(color.substring(4, 6), 16));
}