001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.base;
019
020/**
021 * Represents a color in minecraft
022 *
023 * @author The TridentSDK Team
024 * @since 0.3-alpha-DP
025 */
026public enum SubstanceColor {
027    WHITE(0), ORANGE(1), MAGENTA(2), LIGHT_BLUE(3),
028    YELLOW(4), LIME(5), PINK(6),
029    GRAY(7), SILVER(8), CYAN(9),
030    PURPLE(10), BLUE(11), BROWN(12),
031    GREEN(13), RED(14), BLACK(15);
032
033    int value;
034
035    SubstanceColor(int i) {
036        value = i;
037    }
038
039    /**
040     * Gets a substance color from the byte value
041     *
042     * @param v the byte value
043     * @return the substance color with that value, or {@code null} if it is out of bounds (bound: 0 <= x <= 15)
044     */
045    public static SubstanceColor of(byte v) {
046        for (SubstanceColor color : values()) {
047            if (color.asInt() == v) {
048                return color;
049            }
050        }
051
052        return null;
053    }
054
055    /**
056     * Gets the color value as an int
057     *
058     * @return the value given to the color by the protocol
059     */
060    public int asInt() {
061        return value;
062    }
063}