From 2ab6a5f4eb41c4a86442ffa754437e8e0f112209 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 27 Aug 2017 23:35:46 +0200 Subject: [PATCH] Nickname impr., Towny spy, RP channel - Added nickname cache update on nick change for mentions - Added support for Towny spy (again) - Removed RPMode and added RP channel --- .../java/buttondevteam/chat/ChatPlayer.java | 1 - .../buttondevteam/chat/ChatProcessing.java | 17 ++++++--- .../java/buttondevteam/chat/PluginMain.java | 19 ++++++++-- .../chat/commands/OOCCommand.java | 36 ------------------- .../listener/PlayerJoinLeaveListener.java | 2 -- .../chat/listener/PlayerListener.java | 6 ++++ .../java/buttondevteam/chat/ChatFormatIT.java | 2 +- 7 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 src/main/java/buttondevteam/chat/commands/OOCCommand.java diff --git a/src/main/java/buttondevteam/chat/ChatPlayer.java b/src/main/java/buttondevteam/chat/ChatPlayer.java index 3eb9338..25bc99d 100644 --- a/src/main/java/buttondevteam/chat/ChatPlayer.java +++ b/src/main/java/buttondevteam/chat/ChatPlayer.java @@ -42,7 +42,6 @@ public class ChatPlayer extends TBMCPlayerBase { return data(false); } - public boolean RPMode = true; public Location SavedLocation; public boolean Working; // public int Tables = 10; diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 6001f54..7c5e262 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -2,6 +2,7 @@ package buttondevteam.chat; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; @@ -115,7 +116,7 @@ public class ChatProcessing { }).build()); } pingedconsole = false; // Will set it to true onmatch (static constructor) - final String channelidentifier = getChannelID(channel, sender, mp); + final String channelidentifier = getChannelID(channel, sender); TellrawPart json = createTellraw(sender, message, player, mp, channelidentifier); long combinetime = System.nanoTime(); @@ -148,10 +149,18 @@ public class ChatProcessing { score = e.getMCScore(sender); if (score < 0) // Never send messages to score below 0 sender.sendMessage("§cYou don't have permission to send this message or something went wrong"); - else + else { PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, score, jsonstr)); + if (e.getChannel().ID.equals(PluginMain.TownChat.ID) + || e.getChannel().ID.equals(PluginMain.NationChat.ID)) { + ((List) json.getExtra()).add(0, new TellrawPart("[SPY]")); + jsonstr = toJson(json); + Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format( + "tellraw @a[score_%s=1000,score_%s_min=1000 %s", channel.ID, channel.ID, jsonstr)); + } + } } else PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, String.format("tellraw @a %s", jsonstr)); @@ -235,9 +244,9 @@ public class ChatProcessing { return json; } - static String getChannelID(Channel channel, CommandSender sender, ChatPlayer mp) { + static String getChannelID(Channel channel, CommandSender sender) { final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + channel.DisplayName) - + "]" + (mp != null && !mp.RPMode ? "[OOC]" : ""); + + "]"; return channelidentifier; } diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index f54690c..3149890 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -23,7 +23,6 @@ import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.Channel.RecipientTestResult; import buttondevteam.lib.player.TBMCPlayerBase; - import com.earth2me.essentials.Essentials; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -63,6 +62,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. public static Channel TownChat; public static Channel NationChat; + public static Channel RPChannel; /** *

@@ -93,6 +93,11 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); TBMCChatAPI.RegisterChatChannel( NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); + TBMCChatAPI.RegisterChatChannel(RPChannel = new Channel("§7RP§f", Color.Gray, "rp", Channel.noScoreResult(s -> { + if (s instanceof ConsoleCommandSender) + return true; + return true; // TODO: Allow hiding it + }, "You need to show the RP chat in order to speak in it."))); setupChat(); setupEconomy(); @@ -324,10 +329,18 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. private static RecipientTestResult checkTownNationChat(CommandSender sender, boolean nationchat) { if (!(sender instanceof Player)) return new RecipientTestResult("§cYou are not a player!"); + Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase()); + RecipientTestResult result = checkTownNationChatInternal(sender, nationchat, resident); + if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it + result = new RecipientTestResult(1000); // There won't be more than a thousand towns/nations probably + return result; + } + + private static RecipientTestResult checkTownNationChatInternal(CommandSender sender, boolean nationchat, + Resident resident) { try { - Resident resident = PluginMain.TU.getResidentMap().get(sender.getName().toLowerCase()); if (resident != null && resident.getModes().contains("spy")) - return null; + return new RecipientTestResult(1000); // There won't be more than a thousand towns/nations probably /* * p.sendMessage(String.format("[SPY-%s] - %s: %s", channel.DisplayName, ((Player) sender).getDisplayName(), message)); */ diff --git a/src/main/java/buttondevteam/chat/commands/OOCCommand.java b/src/main/java/buttondevteam/chat/commands/OOCCommand.java deleted file mode 100644 index c85151f..0000000 --- a/src/main/java/buttondevteam/chat/commands/OOCCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package buttondevteam.chat.commands; - -import org.bukkit.entity.Player; - -import buttondevteam.chat.ChatPlayer; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.PlayerCommandBase; -import buttondevteam.lib.player.TBMCPlayer; - -@CommandClass(modOnly = false) -public final class OOCCommand extends PlayerCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Out-of-character message ----", - "This command will put a [OCC] tag before your message indicating that you are talking out of character", - "Usage: /" + alias + " " }; - } - - @Override - public boolean OnCommand(Player player, String alias, String[] args) { - if (args.length == 0) { - return false; - } else { - final ChatPlayer cp = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); - cp.RPMode = false; - String message = ""; - for (String arg : args) - message += arg + " "; - player.chat(message.substring(0, message.length() - 1)); - cp.RPMode = true; - } - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index 5e05bee..aa96a2b 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -86,8 +86,6 @@ public class PlayerJoinLeaveListener implements Listener { nwithoutformatting = p.getName(); PlayerListener.nicknames.put(nwithoutformatting, p.getUniqueId()); - cp.RPMode = true; - cp.FlairUpdate(); if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 521eb54..e218c34 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -21,6 +21,7 @@ import buttondevteam.lib.chat.ChatChannelRegisterEvent; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; +import net.ess3.api.events.NickChangeEvent; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import com.google.common.collect.BiMap; @@ -292,4 +293,9 @@ public class PlayerListener implements Listener { if (e.getChannel().filteranderrormsg != null && PluginMain.SB.getObjective(e.getChannel().ID) == null) // Not global chat and doesn't exist yet PluginMain.SB.registerNewObjective(e.getChannel().ID, "dummy"); } + + @EventHandler + public void onNickChange(NickChangeEvent e) { + nicknames.inverse().put(e.getAffected().getBase().getUniqueId(), e.getValue()); + } } diff --git a/src/test/java/buttondevteam/chat/ChatFormatIT.java b/src/test/java/buttondevteam/chat/ChatFormatIT.java index 19c8f59..fc8124b 100644 --- a/src/test/java/buttondevteam/chat/ChatFormatIT.java +++ b/src/test/java/buttondevteam/chat/ChatFormatIT.java @@ -63,7 +63,7 @@ public class ChatFormatIT extends TestCase { @Test public void testMessage() { ArrayList cfs = ChatProcessing.addFormatters(Color.White); - final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, null); + final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender); final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, chid); ChatFormatter.Combine(cfs, message, tp); System.out.println("Testing: " + message);