New /reporthandle command

This commit is contained in:
Keir Nellyer 2016-06-24 12:14:58 +01:00
parent d67082bca2
commit fd64753ba0
2 changed files with 93 additions and 50 deletions

View File

@ -6,13 +6,13 @@ import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import com.google.common.base.Preconditions;
import mineplex.core.account.CoreClientManager;
import mineplex.core.chatsnap.Snapshot;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.command.CommandCenter;
import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.portal.Portal;
@ -116,53 +116,53 @@ public class ReportManager
);
}
public void handleReport(long reportId, Player reportHandler)
public void handleReport(Report report, Player reportHandler)
{
_reportRepository.getReport(reportId).thenCompose(BukkitFuture.accept(report ->
{
if (report != null)
{
Optional<Integer> handlerIdOptional = report.getHandlerId();
Preconditions.checkNotNull(report);
Preconditions.checkNotNull(reportHandler);
if (handlerIdOptional.isPresent())
{
_reportRepository.getAccountName(handlerIdOptional.get())
.thenAccept(name ->
reportHandler.sendMessage(
F.main(
getReportPrefix(reportId),
String.format("%s is already handling this report.", name)
)
)
);
}
else
{
String handlerName = reportHandler.getName();
int handlerId = _clientManager.Get(reportHandler).getAccountId();
report.setHandlerId(handlerId);
Optional<Long> reportIdOptional = report.getReportId();
Preconditions.checkArgument(reportIdOptional.isPresent(), "Report id is not present.");
long reportId = reportIdOptional.get();
if (report.getCategory() == ReportCategory.CHAT_ABUSE)
{
Set<Snapshot> relatedSnapshots = _snapshotManager.getSnapshots(report.getSuspectId());
_snapshotManager.getSnapshotRepository().insertSnapshots(reportId, relatedSnapshots)
.exceptionally(throwable -> {
_javaPlugin.getLogger().log(Level.SEVERE, "Error whilst inserting snapshots into database.", throwable);
return null;
});
}
Optional<Integer> handlerIdOptional = report.getHandlerId();
_reportRepository.updateReport(report);
if (handlerIdOptional.isPresent())
{
_reportRepository.getAccountName(handlerIdOptional.get())
.thenAccept(name ->
reportHandler.sendMessage(
F.main(
getReportPrefix(reportId),
String.format("%s is already handling this report.", name)
)
)
);
}
else
{
String handlerName = reportHandler.getName();
int handlerId = _clientManager.Get(reportHandler).getAccountId();
report.setHandlerId(handlerId);
sendStaffNotification(F.main(getReportPrefix(reportId), String.format("%s is handling this report.", handlerName)));
Portal.transferPlayer(reportHandler.getName(), report.getLatestMessage().getServer());
if (report.getCategory() == ReportCategory.CHAT_ABUSE)
{
Set<Snapshot> relatedSnapshots = _snapshotManager.getSnapshots(report.getSuspectId());
_snapshotManager.getSnapshotRepository().insertSnapshots(reportId, relatedSnapshots)
.exceptionally(throwable -> {
_javaPlugin.getLogger().log(Level.SEVERE, "Error whilst inserting snapshots into database.", throwable);
return null;
});
}
// Show user details of the report every x seconds
new ReportHandlerMessageTask(this, report).runTaskTimer(_javaPlugin, 20L * 10, 20L * 10);
}
}
})
);
_reportRepository.updateReport(report);
sendStaffNotification(F.main(getReportPrefix(reportId), String.format("%s is handling this report.", handlerName)));
Portal.transferPlayer(reportHandler.getName(), report.getLatestMessage().getServer());
// Show user details of the report every x seconds
new ReportHandlerMessageTask(this, report).runTaskTimer(_javaPlugin, 20L * 10, 20L * 10);
}
}
public CompletableFuture<Boolean> canReport(Player player)
@ -233,7 +233,7 @@ public class ReportManager
ReportMessage message = entry.getValue();
int serverWeight = message.getServerWeight();
double ageImpact = Math.pow(1 - 0.066666666666667, message.getDurationSinceCreation().toMinutes());
double ageImpact = 15 * Math.pow(1 - 0.066666666666667, message.getDurationSinceCreation().toMinutes());
// TODO do something with all these values
}

View File

@ -1,33 +1,76 @@
package mineplex.core.report.command;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.BukkitFuture;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.report.Report;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ReportRepository;
import org.bukkit.entity.Player;
public class ReportHandleCommand extends CommandBase<ReportPlugin>
{
public ReportHandleCommand(ReportPlugin plugin)
{
super(plugin, Rank.MODERATOR, "reporthandle", "rh");
}
@Override
public void Execute(final Player player, final String[] args)
{
if(args == null || args.length < 1)
{
if (args == null || args.length == 0)
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!"));
ReportManager reportManager = Plugin.getReportManager();
ReportRepository reportRepository = reportManager.getReportRepository();
Map<Report, Double> reportPriorities = new ConcurrentHashMap<>();
// the below fetches the ids of all unhandled reports and gets a Report object for each of these ids
// the priority of the report is then calculated and the results placed in a map
CompletableFuture.allOf(
reportRepository.getUnhandledReports().thenCompose(reportRepository::getReports).thenAccept(reports ->
reports.stream().map(report ->
reportManager.calculatePriority(report).thenAccept(priority ->
reportPriorities.put(report, priority)
)
).toArray(CompletableFuture[]::new))
).thenApply(aVoid ->
{
Map.Entry<Report, Double> mostImportant = null;
for (Map.Entry<Report, Double> entry : reportPriorities.entrySet())
{
if (mostImportant == null || entry.getValue() > mostImportant.getValue())
{
mostImportant = entry;
}
}
return mostImportant == null ? null : mostImportant.getKey();
}).thenCompose(BukkitFuture.accept(report ->
{
if (report != null)
{
reportManager.handleReport(report, player);
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "No report found, report queue is empty."));
}
}));
}
else
{
long reportId = Long.parseLong(args[0]);
Plugin.getReportManager().handleReport(reportId, player);
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "Your arguments are inappropriate for this command!"));
}
}
}