Skip to content

Commit 39e8295

Browse files
authored
feat: add & color code support in Chat and Language (#907)
1 parent bdfd6b1 commit 39e8295

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/main/java/net/coreprotect/language/Language.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.concurrent.ConcurrentHashMap;
44

5+
import org.bukkit.ChatColor;
6+
57
public class Language {
68

79
private static ConcurrentHashMap<Phrase, String> phrases = new ConcurrentHashMap<>();
@@ -21,10 +23,16 @@ protected static String getTranslatedPhrase(Phrase phrase) {
2123
}
2224

2325
protected static void setUserPhrase(Phrase phrase, String value) {
26+
if (value != null) {
27+
value = ChatColor.translateAlternateColorCodes('&', value);
28+
}
2429
userPhrases.put(phrase, value);
2530
}
2631

2732
protected static void setTranslatedPhrase(Phrase phrase, String value) {
33+
if (value != null) {
34+
value = ChatColor.translateAlternateColorCodes('&', value);
35+
}
2836
translatedPhrases.put(phrase, value);
2937
}
3038

src/main/java/net/coreprotect/utility/Chat.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ private Chat() {
2323
throw new IllegalStateException("Utility class");
2424
}
2525

26+
public static String translateColorCodes(String text) {
27+
if (text == null) {
28+
return null;
29+
}
30+
return ChatColor.translateAlternateColorCodes('&', text);
31+
}
32+
2633
public static void sendComponent(CommandSender sender, String string, String bypass) {
34+
string = translateColorCodes(string);
2735
SpigotAdapter.ADAPTER.sendComponent(sender, string, bypass);
2836
}
2937

@@ -32,6 +40,7 @@ public static void sendComponent(CommandSender sender, String string) {
3240
}
3341

3442
public static void sendMessage(CommandSender sender, String message) {
43+
message = translateColorCodes(message);
3544
if (sender instanceof ConsoleCommandSender) {
3645
message = message.replace(Color.DARK_AQUA, ChatColor.DARK_AQUA.toString());
3746
}
@@ -40,10 +49,12 @@ public static void sendMessage(CommandSender sender, String message) {
4049
}
4150

4251
public static void sendConsoleMessage(String string) {
52+
string = translateColorCodes(string);
4353
Bukkit.getServer().getConsoleSender().sendMessage(string);
4454
}
4555

4656
public static void console(String string) {
57+
string = translateColorCodes(string);
4758
if (string.startsWith("-") || string.startsWith("[")) {
4859
Bukkit.getLogger().log(Level.INFO, string);
4960
}
@@ -53,6 +64,7 @@ public static void console(String string) {
5364
}
5465

5566
public static void sendGlobalMessage(CommandSender user, String string) {
67+
string = translateColorCodes(string);
5668
if (user instanceof ConsoleCommandSender) {
5769
sendMessage(user, Color.DARK_AQUA + "[CoreProtect] " + Color.WHITE + string);
5870
return;

0 commit comments

Comments
 (0)