From 87a052f5fd0fc48957b82f9356252eaddfb0886d Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Sun, 4 Aug 2024 04:35:26 +0200 Subject: [PATCH] We have colours. --- .../me/sergiotarxz/bv/BetterVillager.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/me/sergiotarxz/bv/BetterVillager.java b/src/main/java/me/sergiotarxz/bv/BetterVillager.java index deb6751..fcf652d 100644 --- a/src/main/java/me/sergiotarxz/bv/BetterVillager.java +++ b/src/main/java/me/sergiotarxz/bv/BetterVillager.java @@ -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) {