diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/ChatSnapManager.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/ChatSnapManager.java new file mode 100644 index 000000000..c58bf87d1 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/ChatSnapManager.java @@ -0,0 +1,52 @@ +package mineplex.core.chatsnap; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + +/** + * @author iKeirNez + */ +public class ChatSnapManager +{ + private Cache _snapshots = CacheBuilder.newBuilder() + .concurrencyLevel(4) + .expireAfterWrite(30, TimeUnit.MINUTES) + .build(); + + public ChatSnapManager() + { + + } + + public void cacheMessageSnap(MessageSnap messageSnap) + { + _snapshots.put(messageSnap.getSender(), messageSnap); + } + + /** + * Gets all instances of {@link MessageSnap} which involve a particular user. + * The user may be the sender or recipient of a message. + * + * @param search the user to search for snaps involved in + * @return the snaps that the user is involved in + */ + public Set getMessageSnapsInvolving(UUID search) + { + Set matches = new HashSet<>(); + + for (MessageSnap messageSnap : _snapshots.asMap().values()) + { + if (messageSnap.getSender().equals(search) || messageSnap.getRecipients().contains(search)) + { + matches.add(messageSnap); + } + } + + return matches; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/ChatSnapPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/ChatSnapPlugin.java new file mode 100644 index 000000000..808a300a4 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/ChatSnapPlugin.java @@ -0,0 +1,41 @@ +package mineplex.core.chatsnap; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; + +/** + * @author iKeirNez + */ +public class ChatSnapPlugin extends MiniPlugin +{ + private final ChatSnapManager _chatSnapManager; + + public ChatSnapPlugin(JavaPlugin plugin, ChatSnapManager chatSnapManager) + { + super("ChatSnap", plugin); + _chatSnapManager = chatSnapManager; + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void cacheChatMessage(AsyncPlayerChatEvent e) + { + // TODO replace with Java 8 functions? + Set recipients = new HashSet<>(); + for (Player recipient : e.getRecipients()) + { + recipients.add(recipient.getUniqueId()); + } + + MessageSnap messageSnap = new MessageSnap(e.getPlayer().getUniqueId(), recipients, e.getMessage()); + _chatSnapManager.cacheMessageSnap(messageSnap); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/MessageSnap.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/MessageSnap.java new file mode 100644 index 000000000..f58ebc3ae --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/MessageSnap.java @@ -0,0 +1,51 @@ +package mineplex.core.chatsnap; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * Represents a message sent by a player. + * @author iKeirNez + */ +public class MessageSnap +{ + private UUID sender; + private Collection recipients; + private String message; + private long time; + + public MessageSnap(UUID sender, Collection recipients, String message) + { + this(sender, recipients, message, System.currentTimeMillis()); + } + + public MessageSnap(UUID sender, Collection recipients, String message, long time) + { + this.sender = sender; + this.recipients = recipients; + this.message = message; + this.time = time; + } + + public UUID getSender() + { + return sender; + } + + public String getMessage() + { + return message; + } + + public Set getRecipients() + { + return new HashSet<>(recipients); + } + + public long getTime() + { + return time; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 0a7985a38..c79262891 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -1,11 +1,11 @@ package mineplex.core.report; -import java.sql.SQLException; import java.util.Collection; import java.util.HashMap; import java.util.Map; import mineplex.core.account.CoreClient; +import mineplex.core.chatsnap.ChatSnapManager; import mineplex.core.command.CommandCenter; import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.ClickEvent; @@ -51,6 +51,7 @@ public class ReportManager { private JavaPlugin _javaPlugin; private PreferencesManager _preferencesManager; private StatsManager _statsManager; + private ChatSnapManager _chatSnapManager; private String _serverName; // Holds active/open reports in a synchronized database. @@ -62,11 +63,12 @@ public class ReportManager { // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. private Map _activeReports; - public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, StatsManager statsManager, String serverName) + public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, StatsManager statsManager, ChatSnapManager chatSnapManager, String serverName) { _javaPlugin = javaPlugin; _preferencesManager = preferencesManager; _statsManager = statsManager; + _chatSnapManager = chatSnapManager; _serverName = serverName; _reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); _activeReports = new HashMap(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 68d4a38e0..e9c619b4d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -8,6 +8,8 @@ import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; +import mineplex.core.chatsnap.ChatSnapManager; +import mineplex.core.chatsnap.ChatSnapPlugin; import mineplex.core.command.CommandCenter; import mineplex.core.donation.DonationManager; import mineplex.core.explosion.Explosion; @@ -91,7 +93,9 @@ public class Clans extends JavaPlugin new Explosion(this, blockRestore); new FriendManager(this, _clientManager, preferenceManager, portal); new InventoryManager(this, _clientManager); - new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, serverStatusManager.getCurrentServerName())); + ChatSnapManager chatSnapManager = new ChatSnapManager(); + new ChatSnapPlugin(this, chatSnapManager); + new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, chatSnapManager, serverStatusManager.getCurrentServerName())); ClansManager clans = new ClansManager(this, serverStatusManager.getCurrentServerName(), _clientManager, _donationManager, blockRestore, teleport, webServerAddress); new Recipes(this); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 8074e90f8..743391960 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -12,6 +12,8 @@ import mineplex.core.antihack.AntiHack; import mineplex.core.aprilfools.AprilFoolsManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; +import mineplex.core.chatsnap.ChatSnapManager; +import mineplex.core.chatsnap.ChatSnapPlugin; import mineplex.core.command.CommandCenter; import mineplex.core.creature.Creature; import mineplex.core.disguise.DisguiseManager; @@ -152,7 +154,9 @@ public class Hub extends JavaPlugin implements IRelation } }); new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager, giveawayManager); - new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, serverStatusManager.getCurrentServerName())); + ChatSnapManager chatSnapManager = new ChatSnapManager(); + new ChatSnapPlugin(this, chatSnapManager); + new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, chatSnapManager, serverStatusManager.getCurrentServerName())); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 3edb66383..aca2e2f80 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -9,6 +9,8 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.FoodDupeFix; import mineplex.core.PacketsInteractionFix; import mineplex.core.account.CoreClient; +import mineplex.core.chatsnap.ChatSnapManager; +import mineplex.core.chatsnap.ChatSnapPlugin; import mineplex.core.giveaway.GiveawayManager; import mineplex.core.globalpacket.GlobalPacketManager; import net.minecraft.server.v1_8_R3.BiomeBase; @@ -134,7 +136,9 @@ public class Arcade extends JavaPlugin FriendManager friendManager = new FriendManager(this, _clientManager, preferenceManager, portal); Chat chat = new Chat(this, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); - new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, serverStatusManager.getCurrentServerName())); + ChatSnapManager chatSnapManager = new ChatSnapManager(); + new ChatSnapPlugin(this, chatSnapManager); + new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, chatSnapManager, serverStatusManager.getCurrentServerName())); BlockRestore blockRestore = new BlockRestore(this);