PC-958 Don't allow chat abuse reports of players who haven't spoken
in chat
This commit is contained in:
parent
640a8d3516
commit
e2840f36b5
@ -23,7 +23,7 @@ public class SnapshotManager
|
|||||||
// For an easy work around, we store values as the Key
|
// For an easy work around, we store values as the Key
|
||||||
// For the value we just use some dummy object
|
// For the value we just use some dummy object
|
||||||
// I went with Boolean as it's the smallest data type
|
// I went with Boolean as it's the smallest data type
|
||||||
private final Cache<SnapshotMessage, Boolean> _snapshots = CacheBuilder.newBuilder()
|
private final Cache<SnapshotMessage, Boolean> _messages = CacheBuilder.newBuilder()
|
||||||
.concurrencyLevel(4)
|
.concurrencyLevel(4)
|
||||||
.expireAfterWrite(30, TimeUnit.MINUTES)
|
.expireAfterWrite(30, TimeUnit.MINUTES)
|
||||||
.build();
|
.build();
|
||||||
@ -48,9 +48,9 @@ public class SnapshotManager
|
|||||||
*
|
*
|
||||||
* @param message the message to temporarily store
|
* @param message the message to temporarily store
|
||||||
*/
|
*/
|
||||||
public void cacheSnapshot(SnapshotMessage message)
|
public void cacheMessage(SnapshotMessage message)
|
||||||
{
|
{
|
||||||
_snapshots.put(message, true);
|
_messages.put(message, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,25 +59,52 @@ public class SnapshotManager
|
|||||||
*
|
*
|
||||||
* @return a set containing all snapshots
|
* @return a set containing all snapshots
|
||||||
*/
|
*/
|
||||||
public Set<SnapshotMessage> getSnapshots()
|
public Set<SnapshotMessage> getMessages()
|
||||||
{
|
{
|
||||||
// The compareTo method in SnapshotMessage will ensure this in chronological order
|
// The compareTo method in SnapshotMessage will ensure this in chronological order
|
||||||
Set<SnapshotMessage> messages = new TreeSet<>();
|
Set<SnapshotMessage> messages = new TreeSet<>();
|
||||||
messages.addAll(_snapshots.asMap().keySet());
|
messages.addAll(_messages.asMap().keySet());
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all instances of {@link SnapshotMessage} which involve a particular user.
|
* Gets all messages an account is involved in.
|
||||||
* The user may be the sender or recipient of a message.
|
* The user may be the sender or recipient of a message.
|
||||||
*
|
*
|
||||||
* @param accountId the user to search for snaps involved in
|
* @param accountId the account to search for messages involved in
|
||||||
* @return the snaps that the user is involved in
|
* @return the messages that the account is involved in
|
||||||
*/
|
*/
|
||||||
public Set<SnapshotMessage> getSnapshots(int accountId)
|
public Set<SnapshotMessage> getMessagesInvolving(int accountId)
|
||||||
{
|
{
|
||||||
return _snapshots.asMap().keySet().stream()
|
Set<SnapshotMessage> messagesInvolved = new TreeSet<>();
|
||||||
.filter(snapshot -> snapshot.getSenderId() == accountId || snapshot.getRecipientIds().contains(accountId))
|
messagesInvolved.addAll(getMessagesFrom(accountId));
|
||||||
|
messagesInvolved.addAll(getMessagesReceived(accountId));
|
||||||
|
return messagesInvolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all messages sent by an account.
|
||||||
|
*
|
||||||
|
* @param senderId the account to search for messages involved in
|
||||||
|
* @return the messages that the account is involved in
|
||||||
|
*/
|
||||||
|
public Set<SnapshotMessage> getMessagesFrom(int senderId)
|
||||||
|
{
|
||||||
|
return _messages.asMap().keySet().stream()
|
||||||
|
.filter(message -> message.getSenderId() == senderId)
|
||||||
|
.collect(Collectors.toCollection(TreeSet::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all messages received by an account.
|
||||||
|
*
|
||||||
|
* @param recipientId the account to search for messages received
|
||||||
|
* @return the messages that the account is involved in
|
||||||
|
*/
|
||||||
|
public Set<SnapshotMessage> getMessagesReceived(int recipientId)
|
||||||
|
{
|
||||||
|
return _messages.asMap().keySet().stream()
|
||||||
|
.filter(message -> message.getRecipientIds().contains(recipientId))
|
||||||
.collect(Collectors.toCollection(TreeSet::new));
|
.collect(Collectors.toCollection(TreeSet::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,13 +42,13 @@ public class SnapshotPlugin extends MiniPlugin
|
|||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent e)
|
public void onPlayerChat(AsyncPlayerChatEvent e)
|
||||||
{
|
{
|
||||||
_snapshotManager.cacheSnapshot(createSnapshot(e));
|
_snapshotManager.cacheMessage(createSnapshot(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onPrivateMessage(PrivateMessageEvent e)
|
public void onPrivateMessage(PrivateMessageEvent e)
|
||||||
{
|
{
|
||||||
_snapshotManager.cacheSnapshot(createSnapshot(e));
|
_snapshotManager.cacheMessage(createSnapshot(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Integer> getAccountIds(Set<Player> players)
|
public Set<Integer> getAccountIds(Set<Player> players)
|
||||||
|
@ -29,7 +29,7 @@ public class PushSnapshotsHandler implements CommandCallback
|
|||||||
PushSnapshotsCommand pushCommand = (PushSnapshotsCommand) command;
|
PushSnapshotsCommand pushCommand = (PushSnapshotsCommand) command;
|
||||||
int accountId = pushCommand.getAccountId();
|
int accountId = pushCommand.getAccountId();
|
||||||
long reportId = pushCommand.getReportId();
|
long reportId = pushCommand.getReportId();
|
||||||
Set<SnapshotMessage> messages = _snapshotManager.getSnapshots(accountId);
|
Set<SnapshotMessage> messages = _snapshotManager.getMessagesInvolving(accountId);
|
||||||
|
|
||||||
if (messages.size() > 0)
|
if (messages.size() > 0)
|
||||||
{
|
{
|
||||||
|
@ -80,6 +80,11 @@ public class ReportManager
|
|||||||
commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler);
|
commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SnapshotManager getSnapshotManager()
|
||||||
|
{
|
||||||
|
return _snapshotManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link ReportRepository} we are using.
|
* Gets the {@link ReportRepository} we are using.
|
||||||
*
|
*
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.event.HandlerList;
|
|||||||
import mineplex.core.account.CoreClient;
|
import mineplex.core.account.CoreClient;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.gui.SimpleGui;
|
import mineplex.core.gui.SimpleGui;
|
||||||
import mineplex.core.report.ReportCategory;
|
import mineplex.core.report.ReportCategory;
|
||||||
import mineplex.core.report.ReportManager;
|
import mineplex.core.report.ReportManager;
|
||||||
@ -18,17 +19,17 @@ import mineplex.core.report.ReportPlugin;
|
|||||||
*/
|
*/
|
||||||
public class ReportCategoryPage extends SimpleGui
|
public class ReportCategoryPage extends SimpleGui
|
||||||
{
|
{
|
||||||
private final ReportPlugin _reportPlugin;
|
private final ReportPlugin _plugin;
|
||||||
private final Player _reporter;
|
private final Player _reporter;
|
||||||
private final int _reporterId;
|
private final int _reporterId;
|
||||||
private final CoreClient _suspect;
|
private final CoreClient _suspect;
|
||||||
private final String _reason;
|
private final String _reason;
|
||||||
|
|
||||||
public ReportCategoryPage(ReportPlugin reportPlugin, Player reporter, int reporterId, CoreClient suspect, String reason)
|
public ReportCategoryPage(ReportPlugin plugin, Player reporter, int reporterId, CoreClient suspect, String reason)
|
||||||
{
|
{
|
||||||
super(reportPlugin.getPlugin(), reporter, "Report " + suspect.getName(), 9 * 3);
|
super(plugin.getPlugin(), reporter, "Report " + suspect.getName(), 9 * 3);
|
||||||
|
|
||||||
_reportPlugin = reportPlugin;
|
_plugin = plugin;
|
||||||
_reporter = reporter;
|
_reporter = reporter;
|
||||||
_reporterId = reporterId;
|
_reporterId = reporterId;
|
||||||
_suspect = suspect;
|
_suspect = suspect;
|
||||||
@ -49,7 +50,31 @@ public class ReportCategoryPage extends SimpleGui
|
|||||||
_reporter.closeInventory();
|
_reporter.closeInventory();
|
||||||
unregisterListener();
|
unregisterListener();
|
||||||
|
|
||||||
_reportPlugin.getReportManager().createReport(_reporterId, _suspect.getAccountId(), category, _reason)
|
if (category == ReportCategory.CHAT_ABUSE)
|
||||||
|
{
|
||||||
|
if (hasSentMessage(_suspect.getAccountId()))
|
||||||
|
{
|
||||||
|
createReport(category);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UtilPlayer.message(_reporter, F.main(_plugin.getName(), C.cRed + "You have not received a message from that player"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
createReport(category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasSentMessage(int accountId)
|
||||||
|
{
|
||||||
|
return _plugin.getReportManager().getSnapshotManager().getMessagesFrom(accountId).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createReport(ReportCategory category)
|
||||||
|
{
|
||||||
|
_plugin.getReportManager().createReport(_reporterId, _suspect.getAccountId(), category, _reason)
|
||||||
.thenAccept(report -> {
|
.thenAccept(report -> {
|
||||||
boolean error = true;
|
boolean error = true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user