ServerAPI/src/main/java/xyz/etztech/serverapi/Color.java

56 lines
1.4 KiB
Java

package xyz.etztech.serverapi;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
public class Color {
public static Color DEFAULT = new Color("#AAAAAA");
public static Color ERROR = new Color("#F14668");
public static Color INFO = new Color("#3298DC");
public static Color PRIMARY = new Color("#3273DC");
private final String hex;
private final ChatColor chatColor;
public Color(String hex) {
this.hex = hex;
this.chatColor = ChatColor.of(hex);
}
public String getHex() {
return hex;
}
public int getInt() {
return hexToInt(hex);
}
public ChatColor getChatColor() {
return chatColor;
}
public void sms(CommandSender commandSender, String message) {
if (commandSender instanceof ConsoleCommandSender) {
ServerAPI.getInstance().log(message);
return;
}
TextComponent text = new TextComponent(message);
text.setColor(this.chatColor);
commandSender.spigot().sendMessage(text);
}
public static int hexToInt(String hex) {
if (hex.startsWith("#")) {
hex = hex.substring(1);
}
if (hex.length() != 6) {
return 0;
}
return Integer.parseInt(hex, 16);
}
}