From 4fc5e036fae903702e6d6790242b2ea0a3a1b990 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Thu, 23 Jun 2016 01:13:18 +0100 Subject: [PATCH] Remove old redundant chat cache command Fix broken code in SnapshotPlugin --- .../core/chatsnap/SnapshotPlugin.java | 27 +++++----- .../chatsnap/commands/ChatCacheCommand.java | 54 ------------------- 2 files changed, 14 insertions(+), 67 deletions(-) delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/chatsnap/commands/ChatCacheCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotPlugin.java index 366cdff25..3cffae021 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotPlugin.java @@ -1,7 +1,6 @@ package mineplex.core.chatsnap; import java.util.Set; -import java.util.UUID; import java.util.stream.Collectors; import org.bukkit.entity.Player; @@ -11,7 +10,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; -import mineplex.core.chatsnap.commands.ChatCacheCommand; +import mineplex.core.account.CoreClientManager; import mineplex.core.message.PrivateMessageEvent; /** @@ -20,11 +19,13 @@ import mineplex.core.message.PrivateMessageEvent; public class SnapshotPlugin extends MiniPlugin { private final SnapshotManager _snapshotManager; + private final CoreClientManager _clientManager; - public SnapshotPlugin(JavaPlugin plugin, SnapshotManager snapshotManager) + public SnapshotPlugin(JavaPlugin plugin, SnapshotManager snapshotManager, CoreClientManager clientManager) { super("ChatSnap", plugin); _snapshotManager = snapshotManager; + _clientManager = clientManager; } public SnapshotManager getSnapshotManager() @@ -35,7 +36,7 @@ public class SnapshotPlugin extends MiniPlugin @Override public void addCommands() { - addCommand(new ChatCacheCommand(this)); + } @EventHandler(priority = EventPriority.MONITOR) @@ -50,24 +51,24 @@ public class SnapshotPlugin extends MiniPlugin _snapshotManager.cacheSnapshot(createSnapshot(e)); } - public Set getUUIDSet(Set playerSet) + public Set getAccountIds(Set players) { - return playerSet.stream().map(Player::getUniqueId).collect(Collectors.toSet()); + return players.stream().map(_clientManager::getAccountId).collect(Collectors.toSet()); } public Snapshot createSnapshot(AsyncPlayerChatEvent e) { - UUID senderUUID = e.getPlayer().getUniqueId(); - Set uuidSet = getUUIDSet(e.getRecipients()); - uuidSet.remove(senderUUID); - return new Snapshot(senderUUID, uuidSet, e.getMessage()); + int senderId = _clientManager.getAccountId(e.getPlayer()); + Set recipientIds = getAccountIds(e.getRecipients()); + recipientIds.remove(senderId); + return new Snapshot(senderId, recipientIds, e.getMessage()); } public Snapshot createSnapshot(PrivateMessageEvent e) { - Player sender = e.getSender(); - Player recipient = e.getRecipient(); + int senderId = _clientManager.getAccountId(e.getSender()); + int recipientId = _clientManager.getAccountId(e.getRecipient()); String message = e.getMessage(); - return new Snapshot(sender.getUniqueId(), recipient.getUniqueId(), message); + return new Snapshot(senderId, recipientId, message); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/commands/ChatCacheCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/commands/ChatCacheCommand.java deleted file mode 100644 index bb1dcb1a3..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/commands/ChatCacheCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package mineplex.core.chatsnap.commands; - -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; - -import mineplex.core.chatsnap.SnapshotPlugin; -import mineplex.core.chatsnap.Snapshot; -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; - -/** - * Displays what chat messages we have cached for a player. - */ -public class ChatCacheCommand extends CommandBase -{ - public ChatCacheCommand(SnapshotPlugin plugin) - { - super(plugin, Rank.MODERATOR, "chatcache"); - } - - @Override - public void Execute(final Player caller, String[] args) - { - if (args.length != 1) - { - UtilPlayer.message(caller, F.main(Plugin.getName(), String.format("Invalid arguments, usage: /%s ", _aliasUsed))); - return; - } - - final String playerName = args[0]; - - // getOfflinePlayer sometimes blocks, see this needs to be async - Plugin.getScheduler().runTaskAsynchronously(Plugin.getPlugin(), new Runnable() - { - @Override - public void run() - { - OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName); - Set snaps = Plugin.getSnapshotManager().getSnapshots(offlinePlayer.getUniqueId()); - - for (Snapshot snapshot : snaps) - { - // TODO: show sender name - caller.sendMessage(snapshot.getMessage()); - } - } - }); - } -}