Initial ChatSnap implementation.

This commit is contained in:
Keir 2015-11-26 16:55:27 +00:00
parent f0e24468d5
commit edf93ec43f
7 changed files with 163 additions and 5 deletions

View File

@ -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<UUID, MessageSnap> _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<MessageSnap> getMessageSnapsInvolving(UUID search)
{
Set<MessageSnap> matches = new HashSet<>();
for (MessageSnap messageSnap : _snapshots.asMap().values())
{
if (messageSnap.getSender().equals(search) || messageSnap.getRecipients().contains(search))
{
matches.add(messageSnap);
}
}
return matches;
}
}

View File

@ -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<UUID> 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);
}
}

View File

@ -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<UUID> recipients;
private String message;
private long time;
public MessageSnap(UUID sender, Collection<UUID> recipients, String message)
{
this(sender, recipients, message, System.currentTimeMillis());
}
public MessageSnap(UUID sender, Collection<UUID> 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<UUID> getRecipients()
{
return new HashSet<>(recipients);
}
public long getTime()
{
return time;
}
}

View File

@ -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<String, Integer> _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<Report>(Region.ALL, Report.class, "reports");
_activeReports = new HashMap<String, Integer>();

View File

@ -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);

View File

@ -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);

View File

@ -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);