From ef2328e126693e01d77a1b6c673e27774da6ce73 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 18 May 2018 01:32:05 +0200 Subject: [PATCH] Re-added nickname map... Fixes --- .../java/buttondevteam/chat/ChatPlayer.java | 2 +- .../buttondevteam/chat/ChatProcessing.java | 8 +- .../listener/PlayerJoinLeaveListener.java | 2 +- .../chat/listener/PlayerListener.java | 74 ++++++++++--------- 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatPlayer.java b/src/main/java/buttondevteam/chat/ChatPlayer.java index 4001407..d4b3db5 100644 --- a/src/main/java/buttondevteam/chat/ChatPlayer.java +++ b/src/main/java/buttondevteam/chat/ChatPlayer.java @@ -128,7 +128,7 @@ public class ChatPlayer extends TBMCPlayerBase { return 0x6; else if (flairTime <= 11 && flairTime >= 0) return 0xc; - return 0xf; + return 0x00; //Return 0 if none or too high, so names will get aqua default color, not white } public double getF() { diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 1f4d096..61fd6e0 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -276,11 +276,11 @@ public class ChatProcessing { if (addNickFormatter) formatters.add(ChatFormatter.builder().regex((Pattern.compile(nicksb.toString()))).color(Color.Aqua) .onmatch((match, builder) -> { - if (PlayerListener.nicknames.containsKey(match)) { - Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match)); + if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased + Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase())); if (p == null) { PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed " - + match + " but was reported as online."); + + match.toLowerCase() + " but was reported as online."); return "§c" + match + "§r"; } if (PlayerListener.NotificationSound == null) @@ -290,7 +290,7 @@ public class ChatProcessing { (float) PlayerListener.NotificationPitch); return PluginMain.essentials.getUser(p).getNickname(); } - Bukkit.getServer().getLogger().warning("Player nicknamed " + match + Bukkit.getServer().getLogger().warning("Player nicknamed " + match.toLowerCase() + " not found in nickname map but was reported as online."); return "§c" + match + "§r"; }).priority(Priority.High).build()); diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index 64e2cc5..e2a5196 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -87,7 +87,7 @@ public class PlayerJoinLeaveListener implements Listener { nwithoutformatting = nwithoutformatting.replace("§" + nwithoutformatting.charAt(index + 1), ""); } else nwithoutformatting = p.getName(); - PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId()); + PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> { updatePlayerColors(p, cp); //TODO: Doesn't have effect diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 48801ac..db2c10f 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -12,6 +12,8 @@ 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; @@ -31,11 +33,17 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import java.util.*; +import java.util.Map.Entry; import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.function.Supplier; public class PlayerListener implements Listener { + /** + * Does not contain format codes, lowercased + */ + public static BiMap nicknames = HashBiMap.create(); + public static boolean Enable = false; public static int LoginWarningCountTotal = 5; @@ -109,31 +117,31 @@ public class PlayerListener implements Listener { if (player != null && sender instanceof Player) player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: " + ((Player) sender).getWorld().getName()); - } else if (cmd.equalsIgnoreCase("minecraft:me")) { - if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) { - String msg = message.substring(index + 1); - Bukkit.broadcastMessage(String.format("* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg)); - return true; - } else { - sender.sendMessage("§cCan't use /minecraft:me while muted."); - return true; - } - } else if (cmd.equalsIgnoreCase("me")) { //Take over for Discord broadcast - if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) { - String msg = message.substring(index + 1); - Bukkit.broadcastMessage(String.format("§5* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg)); - return true; - } else { - sender.sendMessage("§cCan't use /me while muted."); - return true; - } - } else - for (Channel channel : Channel.getChannels()) { + } else if (cmd.equalsIgnoreCase("minecraft:me")) { + if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) { + String msg = message.substring(index + 1); + Bukkit.broadcastMessage(String.format("* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg)); + return true; + } else { + sender.sendMessage("§cCan't use /minecraft:me while muted."); + return true; + } + } else if (cmd.equalsIgnoreCase("me")) { //Take over for Discord broadcast + if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) { + String msg = message.substring(index + 1); + Bukkit.broadcastMessage(String.format("§5* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg)); + return true; + } else { + sender.sendMessage("§cCan't use /me while muted."); + return true; + } + } else + for (Channel channel : Channel.getChannels()) { if (checkchid.test(channel, cmd)) { //Apparently method references don't require final variables - TBMCChatAPI.SendChatMessage(channel, sender, message.substring(index + 1)); - return true; - } - } + TBMCChatAPI.SendChatMessage(channel, sender, message.substring(index + 1)); + return true; + } + } // TODO: Target selectors } // We don't care if we have arguments @@ -162,10 +170,9 @@ public class PlayerListener implements Listener { @EventHandler public void onTabComplete(PlayerChatTabCompleteEvent e) { String name = e.getLastToken(); - for (Player p : Bukkit.getOnlinePlayers()) { - String displayName = ChatColor.stripColor(p.getDisplayName()); - if (displayName.startsWith(name)) - e.getTabCompletions().add(displayName); + for (Entry nicknamekv : nicknames.entrySet()) { + if (nicknamekv.getKey().startsWith(name.toLowerCase())) + e.getTabCompletions().add(Bukkit.getPlayer(nicknamekv.getValue()).getName()); //Tabcomplete with the correct case } } @@ -272,7 +279,7 @@ public class PlayerListener implements Listener { if (e.shouldSendTo(p)) p.sendMessage("§c!§r[" + e.getChannel().DisplayName + "] <" + (e.getSender() instanceof Player - ? ((Player) e.getSender()).getDisplayName() : e.getSender().getName()) + ? ((Player) e.getSender()).getDisplayName() : e.getSender().getName()) + "> " + e.getMessage()); TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex); } @@ -286,10 +293,11 @@ public class PlayerListener implements Listener { @EventHandler public void onNickChange(NickChangeEvent e) { - //PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again + nicknames.inverse().forcePut(e.getAffected().getBase().getUniqueId(), ChatColor.stripColor(e.getValue()).toLowerCase()); + //PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //Won't fire this event again - Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> { - PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //TODO: Doesn't have effect - }, 1); + Bukkit.getScheduler().runTaskLater(PluginMain.Instance, () -> { + PlayerJoinLeaveListener.updatePlayerColors(e.getAffected().getBase()); //TODO: Doesn't have effect + }, 1); } }