Remove old redundant chat cache command

Fix broken code in SnapshotPlugin
This commit is contained in:
Keir Nellyer 2016-06-23 01:13:18 +01:00
parent 8bbeb3292f
commit 4fc5e036fa
2 changed files with 14 additions and 67 deletions

View File

@ -1,7 +1,6 @@
package mineplex.core.chatsnap; package mineplex.core.chatsnap;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -11,7 +10,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.chatsnap.commands.ChatCacheCommand; import mineplex.core.account.CoreClientManager;
import mineplex.core.message.PrivateMessageEvent; import mineplex.core.message.PrivateMessageEvent;
/** /**
@ -20,11 +19,13 @@ import mineplex.core.message.PrivateMessageEvent;
public class SnapshotPlugin extends MiniPlugin public class SnapshotPlugin extends MiniPlugin
{ {
private final SnapshotManager _snapshotManager; 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); super("ChatSnap", plugin);
_snapshotManager = snapshotManager; _snapshotManager = snapshotManager;
_clientManager = clientManager;
} }
public SnapshotManager getSnapshotManager() public SnapshotManager getSnapshotManager()
@ -35,7 +36,7 @@ public class SnapshotPlugin extends MiniPlugin
@Override @Override
public void addCommands() public void addCommands()
{ {
addCommand(new ChatCacheCommand(this));
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@ -50,24 +51,24 @@ public class SnapshotPlugin extends MiniPlugin
_snapshotManager.cacheSnapshot(createSnapshot(e)); _snapshotManager.cacheSnapshot(createSnapshot(e));
} }
public Set<UUID> getUUIDSet(Set<Player> playerSet) public Set<Integer> getAccountIds(Set<Player> players)
{ {
return playerSet.stream().map(Player::getUniqueId).collect(Collectors.toSet()); return players.stream().map(_clientManager::getAccountId).collect(Collectors.toSet());
} }
public Snapshot createSnapshot(AsyncPlayerChatEvent e) public Snapshot createSnapshot(AsyncPlayerChatEvent e)
{ {
UUID senderUUID = e.getPlayer().getUniqueId(); int senderId = _clientManager.getAccountId(e.getPlayer());
Set<UUID> uuidSet = getUUIDSet(e.getRecipients()); Set<Integer> recipientIds = getAccountIds(e.getRecipients());
uuidSet.remove(senderUUID); recipientIds.remove(senderId);
return new Snapshot(senderUUID, uuidSet, e.getMessage()); return new Snapshot(senderId, recipientIds, e.getMessage());
} }
public Snapshot createSnapshot(PrivateMessageEvent e) public Snapshot createSnapshot(PrivateMessageEvent e)
{ {
Player sender = e.getSender(); int senderId = _clientManager.getAccountId(e.getSender());
Player recipient = e.getRecipient(); int recipientId = _clientManager.getAccountId(e.getRecipient());
String message = e.getMessage(); String message = e.getMessage();
return new Snapshot(sender.getUniqueId(), recipient.getUniqueId(), message); return new Snapshot(senderId, recipientId, message);
} }
} }

View File

@ -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<SnapshotPlugin>
{
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 <player>", _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<Snapshot> snaps = Plugin.getSnapshotManager().getSnapshots(offlinePlayer.getUniqueId());
for (Snapshot snapshot : snaps)
{
// TODO: show sender name
caller.sendMessage(snapshot.getMessage());
}
}
});
}
}