From 6d3d24ecbf837901783d4616e08963edcd94276a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 16 May 2018 22:56:59 +0200 Subject: [PATCH] Added support for ch IDs field --- .../buttondevteam/chat/listener/PlayerListener.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index cc0f46f..423c7d4 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -30,10 +30,8 @@ import org.bukkit.help.HelpTopic; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.ArrayList; -import java.util.Random; -import java.util.Timer; -import java.util.TimerTask; +import java.util.*; +import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.function.Supplier; @@ -75,13 +73,14 @@ public class PlayerListener implements Listener { else mp = null; String cmd = ""; + final BiPredicate checkchid = (chan, cmd1) -> cmd1.equalsIgnoreCase(chan.ID) || (chan.IDs != null && Arrays.stream(chan.IDs).anyMatch(cmd1::equalsIgnoreCase)); if (index == -1) { // Only the command is run if (!(sender instanceof Player || sender instanceof ConsoleCommandSender)) return false; // ^^ We can only store player or console channels - Directly sending to channels would still work if they had an event cmd = sender instanceof ConsoleCommandSender ? message : message.substring(1); for (Channel channel : Channel.getChannels()) { - if (cmd.equalsIgnoreCase(channel.ID)) { + if (checkchid.test(channel, cmd)) { Supplier getch = () -> sender instanceof Player ? mp.CurrentChannel : ConsoleChannel; Consumer setch = ch -> { if (sender instanceof Player) @@ -130,7 +129,7 @@ public class PlayerListener implements Listener { } } else for (Channel channel : Channel.getChannels()) { - if (cmd.equalsIgnoreCase(channel.ID)) { + if (checkchid.test(channel, cmd)) { //Apparently method references don't require final variables TBMCChatAPI.SendChatMessage(channel, sender, message.substring(index + 1)); return true; }