Translate /chat
All checks were successful
/ deploy (push) Successful in 1m48s

This commit is contained in:
Minecon724 2024-12-03 12:59:34 +01:00
parent e55bd1c676
commit b267985be1
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
3 changed files with 29 additions and 13 deletions

View file

@ -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();
}
}

View file

@ -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);

View file

@ -13,3 +13,11 @@ updatesNotChecked = Not checked yet
updatesNoUpdates = No available updates. Last checked: %s
# %s is update title
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