diff --git a/src/main/java/net/lewmc/essence/utils/MessageUtil.java b/src/main/java/net/lewmc/essence/utils/MessageUtil.java index deff7fc3..f6727fc5 100644 --- a/src/main/java/net/lewmc/essence/utils/MessageUtil.java +++ b/src/main/java/net/lewmc/essence/utils/MessageUtil.java @@ -1,9 +1,8 @@ package net.lewmc.essence.utils; import net.lewmc.essence.Essence; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; /** @@ -34,12 +33,16 @@ public MessageUtil(CommandSender cs, Essence plugin) { public void send(String group, String message, String[] replace) { message = this.getMessage(message, group); if (message != null) { - for (int i = 0; i < replace.length; i++) { - message = message.replace("{{" + (i + 1) + "}}", replace[i]); + int i = 1; + for (String item : replace) { + message = message.replace("{{"+i+"}}", item); + i++; } - this.cs.sendMessage(Component.text(message)); // Send the formatted message + this.cs.sendMessage(message); } else { - sendErrorMessage(cs); + this.cs.sendMessage(ChatColor.DARK_RED + "[Essence] " + ChatColor.RED + "Unable to send message to player, see console for more information."); + LogUtil log = new LogUtil(this.plugin); + log.warn("Unable to send message '"+group+".null' to player, could not find key in en-GB.yml"); } } @@ -52,9 +55,11 @@ public void send(String group, String message, String[] replace) { public void send(String group, String message) { message = this.getMessage(message, group); if (message != null) { - this.cs.sendMessage(Component.text(message)); // Send the formatted message + this.cs.sendMessage(message); } else { - sendErrorMessage(cs); + this.cs.sendMessage(ChatColor.DARK_RED + "[Essence] " + ChatColor.RED + "Unable to send message to player, see console for more information."); + LogUtil log = new LogUtil(this.plugin); + log.warn("Unable to send message '"+group+".null' to player, could not find key in en-GB.yml"); } } @@ -68,14 +73,17 @@ public void send(String group, String message) { public void sendTo(CommandSender cs, String group, String message) { message = this.getMessage(message, group); if (message != null) { - cs.sendMessage(Component.text(message)); // Send the formatted message + cs.sendMessage(message); } else { - sendErrorMessage(cs); + cs.sendMessage(ChatColor.DARK_RED + "[Essence] " + ChatColor.RED + "Unable to send message to player, see console for more information."); + this.cs.sendMessage(ChatColor.DARK_RED + "[Essence] " + ChatColor.RED + "Unable to send message to player, see console for more information."); + LogUtil log = new LogUtil(this.plugin); + log.warn("Unable to send message '"+group+".null' to player, could not find key in en-GB.yml"); } } /** - * Send a message to a user with additional data. + * Send a message to a user. * @param cs CommandSender - The player to send the message to. * @param group String - The group the message belongs to in the language file. * @param message String - The message taken from the language file. @@ -85,12 +93,17 @@ public void sendTo(CommandSender cs, String group, String message) { public void sendTo(CommandSender cs, String group, String message, String[] replace) { message = this.getMessage(message, group); if (message != null) { - for (int i = 0; i < replace.length; i++) { - message = message.replace("{{" + (i + 1) + "}}", replace[i]); + int i = 1; + for (String item : replace) { + message = message.replace("{{"+i+"}}", item); + i++; } - cs.sendMessage(Component.text(message)); // Send the formatted message + cs.sendMessage(message); } else { - sendErrorMessage(cs); + cs.sendMessage(ChatColor.DARK_RED + "[Essence] " + ChatColor.RED + "Unable to send message to player, see console for more information."); + this.cs.sendMessage(ChatColor.DARK_RED + "[Essence] " + ChatColor.RED + "Unable to send message to player, see console for more information."); + LogUtil log = new LogUtil(this.plugin); + log.warn("Unable to send message '"+group+".null' to player, could not find key in en-GB.yml"); } } @@ -99,8 +112,7 @@ public void sendTo(CommandSender cs, String group, String message, String[] repl * @param message String - The message to be sent. */ public void broadcast(String message) { - Bukkit.broadcast(Component.text("Broadcast > ").color(NamedTextColor.GOLD) - .append(Component.text(message).color(NamedTextColor.YELLOW))); + Bukkit.broadcastMessage(ChatColor.GOLD + "Broadcast > " + ChatColor.YELLOW + message); } /** @@ -112,10 +124,10 @@ public void broadcast(String message) { private String getMessage(String code, String group) { String language = this.plugin.getConfig().getString("language"); FileUtil data = new FileUtil(this.plugin); - data.load("language/" + language + ".yml"); + data.load("language/"+language+".yml"); if (data.get(group) != null) { - String toSend = data.getString(group + "." + code); + String toSend = data.getString(group+"."+code); data.close(); return toSend; } else { @@ -123,14 +135,4 @@ private String getMessage(String code, String group) { return null; } } - - /** - * Send an error message to a specific CommandSender. - * @param cs CommandSender - The recipient of the error message. - */ - private void sendErrorMessage(CommandSender cs) { - Component errorMessage = Component.text("[Essence] Unable to send message to player, see console for more information.") - .color(NamedTextColor.DARK_RED); - cs.sendMessage(errorMessage); - } -} +} \ No newline at end of file