This commit is contained in:
parent
e55bd1c676
commit
b267985be1
3 changed files with 29 additions and 13 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
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
|
Loading…
Reference in a new issue