From fa375c49125605d8da2c17a41adac3120b433946 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 16 Sep 2019 15:35:28 +0200 Subject: [PATCH] Updated code relying on Towny & updated Lombok version Towny now uses log4j Newer Lombok supports Java 11 --- .idea/ButtonChat.iml | 3 +- pom.xml | 23 +++++++++----- .../chat/components/towny/TownyAnnouncer.java | 30 ++++++++++--------- .../chat/components/towny/TownyComponent.java | 6 ++-- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index 19d6c49..8f59b6f 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -39,7 +39,7 @@ - + @@ -50,5 +50,6 @@ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index ac73cc8..21eb434 100644 --- a/pom.xml +++ b/pom.xml @@ -212,12 +212,14 @@ master-SNAPSHOT provided - - org.projectlombok - lombok - 1.16.16 - provided - + + + org.projectlombok + lombok + 1.18.10 + provided + + org.spigotmc spigot @@ -247,7 +249,14 @@ 4.12 test - + + + log4j + log4j + 1.2.17 + + + ButtonChat TBMCPlugins diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java index 55702c7..020993b 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java @@ -4,20 +4,22 @@ import buttondevteam.chat.ChatProcessing; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.chat.TBMCChatAPI; -import com.palmergames.bukkit.towny.TownyLogger; import lombok.val; +import org.apache.log4j.Appender; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.LogManager; +import org.apache.log4j.spi.LoggingEvent; -import java.util.logging.Handler; -import java.util.logging.LogRecord; import java.util.regex.Pattern; public class TownyAnnouncer { private static final Pattern LOG_TYPE_PATTERN = Pattern.compile("\\[(\\w+) (?:Msg|Message)](?: (\\w+):)?"); - private static final Handler HANDLER = new Handler() { + private static final Appender HANDLER = new AppenderSkeleton() { @Override - public void publish(LogRecord logRecord) { + public void append(LoggingEvent logRecord) { if (logRecord.getMessage() == null) return; - val m = LOG_TYPE_PATTERN.matcher(logRecord.getMessage()); + String message = logRecord.getMessage().toString(); + val m = LOG_TYPE_PATTERN.matcher(message); if (!m.find()) return; String groupID = m.group(2); //The group ID is correctly cased switch (String.valueOf(m.group(1))) { //valueOf: Handles null @@ -25,30 +27,30 @@ public class TownyAnnouncer { if (townChannel == null) return; TBMCChatAPI.SendSystemMessage(townChannel, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID), - logRecord.getMessage(), target, ChatProcessing.MCORIGIN); + message, target, ChatProcessing.MCORIGIN); break; case "Nation": if (nationChannel == null) return; TBMCChatAPI.SendSystemMessage(nationChannel, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID), - logRecord.getMessage(), target, ChatProcessing.MCORIGIN); + message, target, ChatProcessing.MCORIGIN); break; case "Global": TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, - logRecord.getMessage(), target, ChatProcessing.MCORIGIN); + message, target, ChatProcessing.MCORIGIN); break; } } @Override - public void flush() { + public void close() throws SecurityException { } @Override - public void close() throws SecurityException { - + public boolean requiresLayout() { + return false; } }; @@ -60,7 +62,7 @@ public class TownyAnnouncer { target = TBMCSystemChatEvent.BroadcastTarget.add("towny"); TownyAnnouncer.townChannel = townChannel; TownyAnnouncer.nationChannel = nationChannel; - TownyLogger.log.addHandler(HANDLER); + LogManager.getLogger("com.palmergames.bukkit.towny").addAppender(HANDLER); } public static void setdown() { @@ -68,6 +70,6 @@ public class TownyAnnouncer { target = null; TownyAnnouncer.townChannel = null; TownyAnnouncer.nationChannel = null; - TownyLogger.log.removeHandler(HANDLER); + LogManager.getLogger("com.palmergames.bukkit.towny").removeAppender(HANDLER); } } diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java index 0ddd52c..dfdec58 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java @@ -7,14 +7,12 @@ import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.TBMCChatAPI; -import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.towny.TownyUniverse; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyUniverse; import lombok.val; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -34,7 +32,7 @@ public class TownyComponent extends Component { @Override protected void enable() { - TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse(); + TU = TownyUniverse.getInstance(); Towns = TU.getTownsMap().values().stream().map(Town::getName).collect(Collectors.toCollection(ArrayList::new)); // Creates a snapshot of towns, new towns will be added when needed Nations = TU.getNationsMap().values().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations TBMCChatAPI.RegisterChatChannel(