diff --git a/src/main/java/eu/m724/tweaks/Language.java b/src/main/java/eu/m724/tweaks/Language.java index c232f1d..5cefae6 100644 --- a/src/main/java/eu/m724/tweaks/Language.java +++ b/src/main/java/eu/m724/tweaks/Language.java @@ -6,6 +6,10 @@ package eu.m724.tweaks; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; + import java.util.Locale; import java.util.ResourceBundle; @@ -23,4 +27,12 @@ public class Language { public static String getString(String key) { return INSTANCE.resourceBundle.getString(key); } + + public static BaseComponent getComponent(String key, ChatColor color) { + return new ComponentBuilder(getString(key)).color(color).build(); + } + + public static BaseComponent getComponent(String key, ChatColor color, Object... format) { + return new ComponentBuilder(getString(key).formatted(format)).color(color).build(); + } } diff --git a/src/main/java/eu/m724/tweaks/chat/ChatCommands.java b/src/main/java/eu/m724/tweaks/chat/ChatCommands.java index 2372ff3..f2ecad1 100644 --- a/src/main/java/eu/m724/tweaks/chat/ChatCommands.java +++ b/src/main/java/eu/m724/tweaks/chat/ChatCommands.java @@ -6,6 +6,7 @@ package eu.m724.tweaks.chat; +import eu.m724.tweaks.Language; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -45,36 +46,31 @@ public class ChatCommands implements CommandExecutor { } boolean authenticated = false; - BaseComponent[] component = null; + BaseComponent component = null; ChatRoom newRoom = manager.getById(id); if (newRoom != null) { if (newRoom.password != null) { if (newRoom.password.equals(password)) { authenticated = true; } else if (password == null) { - component = new ComponentBuilder("This room is password protected").color(ChatColor.RED) - .create(); + component = Language.getComponent("chatPasswordProtected", ChatColor.RED); } else { - component = new ComponentBuilder("Invalid password").color(ChatColor.RED) - .create(); + component = Language.getComponent("chatWrongPassword", ChatColor.RED); } } else { authenticated = true; } } else { - component = new ComponentBuilder("No room named ").color(ChatColor.RED) - .append(id).color(ChatColor.AQUA) - .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent()))) - .create(); + component = Language.getComponent("chatNoSuchRoom", ChatColor.RED, id); } if (authenticated) { manager.setPlayerChatRoom(newRoom, player); - component = new ComponentBuilder("Joined chat room: ").color(ChatColor.GOLD) + component = new ComponentBuilder(Language.getComponent("chatJoined", ChatColor.GOLD)) .append(newRoom.id).color(newRoom.color) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(newRoom.getInfoComponent()))) - .append("\nThere are %d other players".formatted(newRoom.players.size())).color(ChatColor.GOLD) - .create(); + .append(Language.getComponent("chatPlayers", ChatColor.GOLD, newRoom.players.size())) + .build(); } player.spigot().sendMessage(component); diff --git a/src/main/resources/strings.properties b/src/main/resources/strings.properties index 2d26c1c..f7a4b90 100644 --- a/src/main/resources/strings.properties +++ b/src/main/resources/strings.properties @@ -12,4 +12,12 @@ updatesNotChecked = Not checked yet # %s is time as HH:mm updatesNoUpdates = No available updates. Last checked: %s # %s is update title -updatesClickToOpen = Click to open on SpigotMC "%s" \ No newline at end of file +updatesClickToOpen = Click to open on SpigotMC "%s" + +# Used in /chat +chatPasswordProtected = This room is password protected +chatWrongPassword = Wrong password +chatNoSuchRoom = No room named %s +# Room name is added at end +chatJoined = Joined chat room: +chatPlayers = %d other players are here \ No newline at end of file