Skip to content

Commit

Permalink
Remove adventure components - breaks bukkit servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewmilburn committed Oct 4, 2024
1 parent bda7d75 commit 40efb78
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions src/main/java/net/lewmc/essence/utils/MessageUtil.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -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");
}
}

Expand All @@ -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");
}
}

Expand All @@ -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.
Expand All @@ -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");
}
}

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

/**
Expand All @@ -112,25 +124,15 @@ 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 {
data.close();
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);
}
}
}

0 comments on commit 40efb78

Please sign in to comment.