mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
outsource color into own enum class
This commit is contained in:
parent
7e6b170e1c
commit
91f325b37a
50
src/main/java/de/bixilon/minosoft/game/datatypes/Color.java
Normal file
50
src/main/java/de/bixilon/minosoft/game/datatypes/Color.java
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
public enum Color {
|
||||
BLACK(0x00),
|
||||
DARK_BLUE(0x01),
|
||||
DARK_GREEN(0x02),
|
||||
DARK_AQUA(0x03),
|
||||
DARK_RED(0x04),
|
||||
DARK_PURPLE(0x05),
|
||||
GOLD(0x06),
|
||||
GRAY(0x07),
|
||||
DARK_GRAY(0x08),
|
||||
BLUE(0x09),
|
||||
GREEN(0x0A),
|
||||
AQUA(0x0B),
|
||||
RED(0x0C),
|
||||
PURPLE(0x0D),
|
||||
YELLOW(0x0E),
|
||||
WHITE(0x0F);
|
||||
|
||||
|
||||
final int color;
|
||||
final String prefix;
|
||||
|
||||
Color(int color) {
|
||||
this.color = color;
|
||||
this.prefix = String.format("%x", color);
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
}
|
@ -107,22 +107,22 @@ public class TextComponent {
|
||||
}
|
||||
|
||||
public enum ChatAttributes {
|
||||
BLACK("\033[38;2;0;0;0m", "0"),
|
||||
DARK_BLUE("\033[38;2;0;0;170m", "1"),
|
||||
DARK_GREEN("\033[38;2;0;170;0m", "2"),
|
||||
DARK_AQUA("\033[38;2;0;170;170m", "3"),
|
||||
DARK_RED("\033[38;2;170;0;0m", "4"),
|
||||
DARK_PURPLE("\033[38;2;170;0;170m", "5"),
|
||||
GOLD("\033[38;2;255;170;0m", "6"),
|
||||
GRAY("\033[38;2;170;170;170m", "7"),
|
||||
DARK_GRAY("\033[38;2;85;85;85m", "8"),
|
||||
BLUE("\033[38;2;85;85;255m", "9"),
|
||||
GREEN("\033[38;2;85;255;85m", "a"),
|
||||
AQUA("\033[38;2;85;255;255m", "b"),
|
||||
RED("\033[38;2;255;85;85m", "c"),
|
||||
PURPLE("\033[38;2;255;85;255m", "d", "light_purple"),
|
||||
YELLOW("\033[38;2;255;255;85m", "e"),
|
||||
WHITE("\033[38;2;255;255;255m", "f"),
|
||||
BLACK("\033[38;2;0;0;0m", Color.BLACK),
|
||||
DARK_BLUE("\033[38;2;0;0;170m", Color.DARK_BLUE),
|
||||
DARK_GREEN("\033[38;2;0;170;0m", Color.DARK_GREEN),
|
||||
DARK_AQUA("\033[38;2;0;170;170m", Color.DARK_AQUA),
|
||||
DARK_RED("\033[38;2;170;0;0m", Color.DARK_RED),
|
||||
DARK_PURPLE("\033[38;2;170;0;170m", Color.DARK_PURPLE),
|
||||
GOLD("\033[38;2;255;170;0m", Color.GOLD),
|
||||
GRAY("\033[38;2;170;170;170m", Color.GRAY),
|
||||
DARK_GRAY("\033[38;2;85;85;85m", Color.DARK_GRAY),
|
||||
BLUE("\033[38;2;85;85;255m", Color.DARK_BLUE),
|
||||
GREEN("\033[38;2;85;255;85m", Color.GREEN),
|
||||
AQUA("\033[38;2;85;255;255m", Color.AQUA),
|
||||
RED("\033[38;2;255;85;85m", Color.RED),
|
||||
PURPLE("\033[38;2;255;85;255m", Color.PURPLE, "light_purple"),
|
||||
YELLOW("\033[38;2;255;255;85m", Color.YELLOW),
|
||||
WHITE("\033[38;2;255;255;255m", Color.WHITE),
|
||||
|
||||
RESET("\u001b[0m", "r"),
|
||||
BOLD("\u001b[1m", "l"),
|
||||
@ -132,27 +132,70 @@ public class TextComponent {
|
||||
OBFUSCATED("\u001b[47;1m", "k"); //ToDo
|
||||
|
||||
final String consolePrefix;
|
||||
final String minecraftPrefix;
|
||||
final Color color;
|
||||
final String prefix;
|
||||
final String name;
|
||||
|
||||
ChatAttributes(String consolePrefix, String minecraftPrefix, String name) {
|
||||
ChatAttributes(String consolePrefix, Color color, String name) {
|
||||
this.consolePrefix = consolePrefix;
|
||||
this.minecraftPrefix = minecraftPrefix;
|
||||
this.color = color;
|
||||
this.name = name;
|
||||
this.prefix = null;
|
||||
}
|
||||
|
||||
ChatAttributes(String consolePrefix, Color color) {
|
||||
this.consolePrefix = consolePrefix;
|
||||
this.color = color;
|
||||
this.name = null;
|
||||
this.prefix = null;
|
||||
}
|
||||
|
||||
ChatAttributes(String consolePrefix, String prefix, String name) {
|
||||
this.consolePrefix = consolePrefix;
|
||||
this.prefix = prefix;
|
||||
this.color = null;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
ChatAttributes(String consolePrefix, String minecraftPrefix) {
|
||||
ChatAttributes(String consolePrefix, String prefix) {
|
||||
this.consolePrefix = consolePrefix;
|
||||
this.minecraftPrefix = minecraftPrefix;
|
||||
this.prefix = prefix;
|
||||
this.color = null;
|
||||
this.name = null;
|
||||
}
|
||||
|
||||
|
||||
public static ChatAttributes byName(String name) {
|
||||
for (ChatAttributes c : values()) {
|
||||
if ((c.getName() != null && c.getName().toLowerCase().equals(name.toLowerCase())) || c.name().toLowerCase().equals(name.toLowerCase())) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ChatAttributes byColor(Color color) {
|
||||
for (ChatAttributes c : values()) {
|
||||
if (c.getColor() == color) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getConsolePrefix() {
|
||||
return consolePrefix;
|
||||
}
|
||||
|
||||
public String getMinecraftPrefix() {
|
||||
return minecraftPrefix;
|
||||
public String getPrefix() {
|
||||
if (prefix == null) {
|
||||
return color.getPrefix();
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -166,23 +209,5 @@ public class TextComponent {
|
||||
public String toString() {
|
||||
return getConsolePrefix();
|
||||
}
|
||||
|
||||
public static ChatAttributes byName(String name) {
|
||||
for (ChatAttributes c : values()) {
|
||||
if ((c.getName() != null && c.getName().toLowerCase().equals(name.toLowerCase())) || c.name().toLowerCase().equals(name.toLowerCase())) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ChatAttributes byMinecraftPrefix(String prefix) {
|
||||
for (ChatAttributes c : values()) {
|
||||
if (c.getMinecraftPrefix().equals(prefix)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user