From bd656015bfa24a562eca23c60b05c5901a565a02 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 21 Sep 2019 02:21:53 +0200 Subject: [PATCH] Fixes, improved color mode command Renaming Fixed TownyAnnouncer once again - but it still doesn't work Improved color mode (separated "unknown color" and "reset") Fixed ping sound hiding for nicknames (#90) --- .idea/ButtonChat.iml | 6 ++-- pom.xml | 10 +++--- .../buttondevteam/chat/ChatProcessing.java | 1 + .../chat/commands/ucmds/HelpCommand.java | 2 +- .../chat/commands/ucmds/ReloadCommand.java | 2 +- .../chat/components/fun/CCommand.java | 28 +++++++++------- .../chat/components/fun/FunComponent.java | 2 +- .../chat/components/towny/TownyAnnouncer.java | 33 +++++++++---------- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index 8f59b6f..966c902 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -11,9 +11,6 @@ - - - @@ -50,6 +47,7 @@ - + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 21eb434..9fca21e 100644 --- a/pom.xml +++ b/pom.xml @@ -249,13 +249,13 @@ 4.12 test - + - log4j - log4j - 1.2.17 + org.apache.logging.log4j + log4j-core + 2.8.1 + provided - ButtonChat diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index dc02c3a..e472147 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -269,6 +269,7 @@ public class ChatProcessing { StringBuilder nicksb = new StringBuilder("(?i)("); boolean addNickFormatter = false; for (Player p : Bukkit.getOnlinePlayers()) { + if (!canSee.test(p)) continue; final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId()); if (nick != null) { nicksb.append(nick).append("|"); diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java index 67d88c5..b7c10fa 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java @@ -19,7 +19,7 @@ public final class HelpCommand extends UCommandBase { public boolean def(CommandSender sender, @Command2.TextArg @Command2.OptionalArg String topicOrCommand) { if (topicOrCommand == null) { sender.sendMessage(new String[]{ - "§6---- Thorpe Help ----", + "§6---- Chroma Help ----", "Do /u help for more info", "Do /u help [subcommands] for more info about a command", "Topics:", diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/ReloadCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/ReloadCommand.java index e5b5ef4..2a49259 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/ReloadCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/ReloadCommand.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; @CommandClass(helpText = { "Reload", - "Reloads Thorpe-Chat" + "Reloads the config" }, modOnly = true) public class ReloadCommand extends UCommandBase { @Command2.Subcommand diff --git a/src/main/java/buttondevteam/chat/components/fun/CCommand.java b/src/main/java/buttondevteam/chat/components/fun/CCommand.java index 252f028..42acb07 100644 --- a/src/main/java/buttondevteam/chat/components/fun/CCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/CCommand.java @@ -7,6 +7,7 @@ import buttondevteam.lib.player.TBMCPlayer; import org.bukkit.entity.Player; import java.util.Arrays; +import java.util.Optional; @CommandClass(path = "u c", helpText = { "Rainbow mode", @@ -18,7 +19,7 @@ public class CCommand extends ICommand2MC { public boolean def(Player player, @Command2.OptionalArg String color) { ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); if (color == null) { - if (PluginMain.permission.has(player, "thorpe.color.rainbow")) { + if (PluginMain.permission.has(player, "chroma.color.rainbow")) { p.RainbowPresserColorMode = !p.RainbowPresserColorMode; p.OtherColorMode = null; if (p.RainbowPresserColorMode) @@ -30,20 +31,23 @@ public class CCommand extends ICommand2MC { return true; } } else { - if (PluginMain.permission.has(player, "thorpe.color.custom")) { - p.RainbowPresserColorMode = false; - p.OtherColorMode = null; - try { - String x = color.toLowerCase(); - p.OtherColorMode = Arrays.stream(Color.values()).filter(c -> c.getName().equals(x)).findAny().orElse(null); - } catch (Exception e) { + if (PluginMain.permission.has(player, "chroma.color.custom")) { + String x = color.toLowerCase(); + if ("off".equals(x)) { + p.OtherColorMode = null; + player.sendMessage("§eMessage color reset."); + return true; + } + Optional oc = Arrays.stream(Color.values()).filter(c -> c.getName().equals(x)).findAny(); + if (!oc.isPresent()) { player.sendMessage("§cUnknown message color: " + color); player.sendMessage("§cUse color names, like blue, or dark_aqua"); + player.sendMessage("§cOr use 'off' to disable"); + return true; } - if (p.OtherColorMode != null) - player.sendMessage(String.format("§eMessage color set to %s", p.OtherColorMode)); - else - player.sendMessage("§eMessage color reset."); + p.RainbowPresserColorMode = false; + p.OtherColorMode = oc.get(); + player.sendMessage(String.format("§eMessage color set to %s", p.OtherColorMode)); } else { player.sendMessage("§cYou don't have permission for this command."); return true; diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index 3f47ea8..6acf3e5 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -139,7 +139,7 @@ public class FunComponent extends Component implements Listener { if (ht.getName().equalsIgnoreCase(cmd)) return; } - if (PluginMain.permission.has(event.getSender(), "thorpe.unanything")) { + if (PluginMain.permission.has(event.getSender(), "chroma.unanything")) { event.setCancelled(true); int index = cmd.lastIndexOf(' '); if (index == -1) { diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java index 020993b..e8cf4d6 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java @@ -5,18 +5,25 @@ import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.chat.TBMCChatAPI; 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 org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.filter.LevelRangeFilter; +import org.apache.logging.log4j.core.layout.PatternLayout; import java.util.regex.Pattern; public class TownyAnnouncer { private static final Pattern LOG_TYPE_PATTERN = Pattern.compile("\\[(\\w+) (?:Msg|Message)](?: (\\w+):)?"); - private static final Appender HANDLER = new AppenderSkeleton() { + private static final Appender HANDLER = new AbstractAppender(TownyAnnouncer.class.getSimpleName(), + LevelRangeFilter.createFilter(Level.INFO, Level.INFO, Filter.Result.ACCEPT, Filter.Result.DENY), + PatternLayout.createDefaultLayout()) { @Override - public void append(LoggingEvent logRecord) { + public void append(LogEvent logRecord) { if (logRecord.getMessage() == null) return; String message = logRecord.getMessage().toString(); val m = LOG_TYPE_PATTERN.matcher(message); @@ -42,16 +49,6 @@ public class TownyAnnouncer { break; } } - - @Override - public void close() throws SecurityException { - - } - - @Override - public boolean requiresLayout() { - return false; - } }; private static TBMCSystemChatEvent.BroadcastTarget target; @@ -62,7 +59,7 @@ public class TownyAnnouncer { target = TBMCSystemChatEvent.BroadcastTarget.add("towny"); TownyAnnouncer.townChannel = townChannel; TownyAnnouncer.nationChannel = nationChannel; - LogManager.getLogger("com.palmergames.bukkit.towny").addAppender(HANDLER); + ((Logger) LogManager.getLogger("com.palmergames.bukkit.towny")).getContext().getConfiguration().addAppender(HANDLER); } public static void setdown() { @@ -70,6 +67,6 @@ public class TownyAnnouncer { target = null; TownyAnnouncer.townChannel = null; TownyAnnouncer.nationChannel = null; - LogManager.getLogger("com.palmergames.bukkit.towny").removeAppender(HANDLER); + ((Logger) LogManager.getLogger("com.palmergames.bukkit.towny")).getContext().getConfiguration().getAppenders().remove(TownyAnnouncer.class.getSimpleName()); } }