From df7f8bca5ee0bd5860fe51c3e7ee49096f960d36 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 12 Feb 2019 22:28:42 +0100 Subject: [PATCH] Town color error fix, applying changes --- src/main/java/buttondevteam/chat/ChatProcessing.java | 5 +++-- .../chat/components/fun/PressCommand.java | 7 ++++--- .../components/towncolors/TownColorComponent.java | 6 ++++-- .../chat/components/towny/TownyAnnouncer.java | 12 +++++++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index cb593df..86a9526 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -52,7 +52,8 @@ public class ChatProcessing { private static final Pattern SPOILER_PATTERN = Pattern.compile("\\|\\|"); private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green, Color.Blue, Color.DarkPurple}; - private static boolean pingedconsole = false; + private static final Pattern WORD_PATTERN = Pattern.compile("\\S+"); + private static boolean pingedconsole = false; public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build(); @@ -134,7 +135,7 @@ public class ChatProcessing { ArrayList formatters = addFormatters(colormode); if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color final AtomicInteger rpc = new AtomicInteger(0); - formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf, s) -> { + formatters.add(ChatFormatter.builder().regex(WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> { cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]); return match; }).build()); diff --git a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java index 7923d21..b9ddc7d 100644 --- a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java @@ -3,8 +3,9 @@ package buttondevteam.chat.components.fun; import buttondevteam.core.component.restart.ScheduledRestartCommand; import buttondevteam.lib.ScheduledServerRestartEvent; import buttondevteam.lib.ThorpeUtils; -import buttondevteam.lib.chat.Command2MC; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.event.EventHandler; @@ -13,12 +14,12 @@ import org.bukkit.event.Listener; import java.util.HashSet; @CommandClass -public class PressCommand extends Command2MC implements Listener { +public class PressCommand extends ICommand2MC implements Listener { private HashSet pressers; //Will be cleared with this class on shutdown/disable private ScheduledRestartCommand command; private int startTicks; - @Subcommand + @Command2.Subcommand public void def(CommandSender sender) { if (command == null) { sender.sendMessage("§cThe timer isn't ticking... yet."); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index 02c8b42..b94d993 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -12,6 +12,7 @@ import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.chat.Color; import com.earth2me.essentials.User; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.Nation; import lombok.experimental.var; import lombok.val; import org.bukkit.Bukkit; @@ -79,9 +80,10 @@ public class TownColorComponent extends Component { return; for (val entry : TownColors.entrySet()) { try { - val nation = TownyComponent.TU.getTownsMap().get(entry.getKey()).getNation(); + val town = TownyComponent.TU.getTownsMap().get(entry.getKey()); + Nation nation; Color nc; - if (nation == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) + if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) nc = Color.White; setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc); } catch (Exception e) { diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java index f6788e8..dc69adf 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java @@ -3,6 +3,7 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; import buttondevteam.core.component.channel.Channel; +import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.chat.TBMCChatAPI; import com.palmergames.bukkit.towny.TownyLogger; import lombok.val; @@ -24,17 +25,17 @@ public class TownyAnnouncer { case "Town": TBMCChatAPI.SendSystemMessage(PluginMain.TownChat, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID), - logRecord.getMessage(), ChatProcessing.MCORIGIN); + logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; case "Nation": TBMCChatAPI.SendSystemMessage(PluginMain.NationChat, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID), - logRecord.getMessage(), ChatProcessing.MCORIGIN); + logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; case "Global": TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, - logRecord.getMessage(), ChatProcessing.MCORIGIN); + logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; } } @@ -50,11 +51,16 @@ public class TownyAnnouncer { } }; + private static TBMCSystemChatEvent.BroadcastTarget target; + public static void setup() { + target = TBMCSystemChatEvent.BroadcastTarget.add("towny"); TownyLogger.log.addHandler(HANDLER); } public static void setdown() { + TBMCSystemChatEvent.BroadcastTarget.remove(target); + target = null; TownyLogger.log.removeHandler(HANDLER); } }