We have colours.

This commit is contained in:
sergiotarxz 2024-08-04 04:35:26 +02:00
parent e7eea26aaa
commit 87a052f5fd
1 changed files with 26 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import org.bukkit.NamespacedKey;
import org.bukkit.metadata.MetadataValue;
import de.tr7zw.changeme.nbtapi.*;
import de.tr7zw.changeme.nbtapi.iface.*;
import org.bukkit.ChatColor;
public class BetterVillager extends JavaPlugin implements Listener {
@Override
@ -34,6 +35,31 @@ public class BetterVillager extends JavaPlugin implements Listener {
}
@EventHandler
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
String message = event.getMessage();
char[] messageArrayChars = message.toCharArray();
String finalMessage = "";
boolean isEscape = false;
for (char c : messageArrayChars) {
if (c == '&') {
isEscape = true;
continue;
}
if (isEscape) {
if (c >= '0' && c <= '9') {
finalMessage += "§"+c;
isEscape = false;
continue;
}
isEscape = false;
}
finalMessage += c;
}
event.setMessage(finalMessage);
}
/** Event handler for when a player right-clicks on an entity. */
@EventHandler
public void onEntityInteraction(PlayerInteractEntityEvent event) {