From 0c768b95e8ac00dbf295398b4c7a159863e39be3 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 13 May 2018 21:38:56 +0200 Subject: [PATCH 1/2] Removed nickname map Huh Squashed with a test commit --- .../chat/commands/ucmds/TownColorCommand.java | 2 +- .../chat/listener/PlayerListener.java | 22 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/TownColorCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/TownColorCommand.java index 63c7623..7d0d9d8 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/TownColorCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/TownColorCommand.java @@ -41,7 +41,7 @@ public class TownColorCommand extends UCommandBase { return true; } if (args.length > ColorCount) { - player.sendMessage("You can only use " + ColorCount + " color" + (ColorCount > 1 ? "(s)" : "") + "."); + player.sendMessage("You can only use " + ColorCount + " color" + (ColorCount > 1 ? "s" : "") + "."); return true; } String[] a = new String[args.length + 1]; diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 923e9e8..cc0f46f 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -12,12 +12,11 @@ import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import com.vexsoftware.votifier.model.Vote; import com.vexsoftware.votifier.model.VotifierEvent; import net.ess3.api.events.NickChangeEvent; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -31,17 +30,14 @@ import org.bukkit.help.HelpTopic; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.*; -import java.util.Map.Entry; +import java.util.ArrayList; +import java.util.Random; +import java.util.Timer; +import java.util.TimerTask; import java.util.function.Consumer; import java.util.function.Supplier; public class PlayerListener implements Listener { - /** - * Does not contain format codes - */ - public static BiMap nicknames = HashBiMap.create(); - public static boolean Enable = false; public static int LoginWarningCountTotal = 5; @@ -168,9 +164,10 @@ public class PlayerListener implements Listener { @EventHandler public void onTabComplete(PlayerChatTabCompleteEvent e) { String name = e.getLastToken(); - for (Entry nicknamekv : nicknames.entrySet()) { - if (nicknamekv.getKey().startsWith(name)) - e.getTabCompletions().add(nicknamekv.getKey()); + for (Player p : Bukkit.getOnlinePlayers()) { + String displayName = ChatColor.stripColor(p.getDisplayName()); + if (displayName.startsWith(name)) + e.getTabCompletions().add(displayName); } } @@ -291,7 +288,6 @@ public class PlayerListener implements Listener { @EventHandler public void onNickChange(NickChangeEvent e) { - nicknames.inverse().put(e.getAffected().getBase().getUniqueId(), e.getValue()); //PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> { From 6d3d24ecbf837901783d4616e08963edcd94276a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 16 May 2018 22:56:59 +0200 Subject: [PATCH 2/2] 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; }