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.meta; 019 020import net.tridentsdk.Console; 021import net.tridentsdk.plugin.cmd.PlatformColor; 022 023import javax.annotation.Nullable; 024 025/** 026 * A color able to be used in the chat text 027 * 028 * <p>These should be self-explanatory, if you need more help, take a look at 029 * <a href="http://minecraft.gamepedia.com/Formatting_codes">Minecraft Wiki</a>.</p> 030 * 031 * @author The TridentSDK Team 032 * @since 0.3-alpha-DP 033 */ 034public enum ChatColor { 035 BLACK { 036 @Override 037 public String toString() { 038 return "§0"; 039 } 040 }, 041 DARK_BLUE { 042 @Override 043 public String toString() { 044 return "§1"; 045 } 046 }, 047 DARK_GREEN { 048 @Override 049 public String toString() { 050 return "§2"; 051 } 052 }, 053 DARK_AQUA { 054 @Override 055 public String toString() { 056 return "§3"; 057 } 058 }, 059 DARK_RED { 060 @Override 061 public String toString() { 062 return "§4"; 063 } 064 }, 065 DARK_PURPLE { 066 @Override 067 public String toString() { 068 return "§5"; 069 } 070 }, 071 GOLD { 072 @Override 073 public String toString() { 074 return "§6"; 075 } 076 }, 077 GRAY { 078 @Override 079 public String toString() { 080 return "§7"; 081 } 082 }, 083 DARK_GRAY { 084 @Override 085 public String toString() { 086 return "§8"; 087 } 088 }, 089 BLUE { 090 @Override 091 public String toString() { 092 return "§9"; 093 } 094 }, 095 GREEN { 096 @Override 097 public String toString() { 098 return "§a"; 099 } 100 }, 101 AQUA { 102 @Override 103 public String toString() { 104 return "§b"; 105 } 106 }, 107 RED { 108 @Override 109 public String toString() { 110 return "§c"; 111 } 112 }, 113 LIGHT_PURPLE { 114 @Override 115 public String toString() { 116 return "§d"; 117 } 118 }, 119 YELLOW { 120 @Override 121 public String toString() { 122 return "§e"; 123 } 124 }, 125 WHITE { 126 @Override 127 public String toString() { 128 return "§f"; 129 } 130 }, 131 OBFUSCATED { 132 @Override 133 public String toString() { 134 return "§k"; 135 } 136 }, 137 BOLD { 138 @Override 139 public String toString() { 140 return "§l"; 141 } 142 }, 143 STRIKETHROUGH { 144 @Override 145 public String toString() { 146 return "§m"; 147 } 148 }, 149 UNDERLINE { 150 @Override 151 public String toString() { 152 return "§n"; 153 } 154 }, 155 ITALIC { 156 @Override 157 public String toString() { 158 return "§o"; 159 } 160 }, 161 RESET { 162 @Override 163 public String toString() { 164 return "§r"; 165 } 166 }; 167 168 /** 169 * Finds the color based on the character after a the section symbol (§) 170 * 171 * @param color the character after the section 172 * @return the chat color with that character 173 */ 174 @Nullable 175 public static ChatColor of(char color) { 176 String find = String.valueOf(color); 177 for (ChatColor chatColor : values()) { 178 if (chatColor.toString().contains(find)) 179 return chatColor; 180 } 181 182 return null; 183 } 184 185 /** 186 * Obtains the section symbol preceeding chat colors 187 * 188 * @return the precceding section symbol 189 */ 190 public static char magicCharacter() { 191 return '§'; 192 } 193 194 /** 195 * Returns the console color representation of the chat color 196 * 197 * <p>Supported colors: 198 * <ul> 199 * <li>{@link net.tridentsdk.meta.ChatColor#BLACK}</li> 200 * <li>{@link net.tridentsdk.meta.ChatColor#DARK_PURPLE} - 201 * {@link Console#PURPLE}</li> 202 * <li>{@link net.tridentsdk.meta.ChatColor#BLUE}</li> 203 * <li>{@link net.tridentsdk.meta.ChatColor#GREEN}</li> 204 * <li>{@link net.tridentsdk.meta.ChatColor#AQUA} - {@link Console#CYAN}</li> 205 * <li>{@link net.tridentsdk.meta.ChatColor#RED}</li> 206 * <li>{@link net.tridentsdk.meta.ChatColor#YELLOW}</li> 207 * <li>{@link net.tridentsdk.meta.ChatColor#WHITE}</li> 208 * <li>{@link net.tridentsdk.meta.ChatColor#RESET}</li> 209 * </ul></p> 210 * 211 * @param color the color to parse 212 * @return the server console color code for that chatcolor 213 */ 214 public static String consoleFormat(ChatColor color) { 215 switch (color) { 216 case BLACK: 217 return Console.BLACK; 218 case DARK_PURPLE: 219 return Console.PURPLE; 220 case BLUE: 221 return Console.BLUE; 222 case GREEN: 223 return Console.GREEN; 224 case AQUA: 225 return Console.CYAN; 226 case RED: 227 return Console.RED; 228 case YELLOW: 229 return Console.YELLOW; 230 case WHITE: 231 return Console.WHITE; 232 case RESET: 233 return Console.RESET; 234 default: 235 return PlatformColor.EMPTY; 236 } 237 } 238}