Merge pull request #226 from Mineplex-LLC/bugfix/report-hotfix

Report feature hotfixes
This commit is contained in:
Shaun Bennett 2016-10-05 17:13:08 -04:00 committed by GitHub
commit 25000f7367
8 changed files with 198 additions and 174 deletions

View File

@ -12,7 +12,6 @@ import java.util.logging.Level;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
@ -248,11 +247,8 @@ public class ReportManager
checkNotNull(report);
checkNotNull(reportResult);
return _reportRepository.getAccountUUID(report.getSuspectId()).thenAccept(suspectUUID ->
return _reportRepository.getAccountName(report.getSuspectId()).thenAccept(suspectName ->
{
OfflinePlayer suspect = Bukkit.getOfflinePlayer(suspectUUID);
String suspectName = suspect.getName();
if (reportCloser != null)
{
int closerId = _clientManager.Get(reportCloser).getAccountId();
@ -266,64 +262,68 @@ public class ReportManager
saveCompletableFuture.thenAccept(reportId ->
{
if (reportResult.getType() == ReportResultType.ABUSIVE)
try
{
// if report was marked abusive, check if each of the reporters
// should be banned from using the report system
report.getReporterIds().forEach(reporterId ->
_reportRepository.getAccountUUID(reporterId).thenAccept(reporterUUID ->
{
CoreClient reporterClient = _clientManager.Get(reporterUUID);
checkAbuseBan(reporterClient, reportCloser, reportId);
}));
}
Bukkit.getScheduler().runTask(_plugin, () ->
{
String prefix = getReportPrefix(reportId);
String reason = reportResult.getReason().orElse("No reason specified.");
if (reportCloser != null)
if (reportResult.getType() == ReportResultType.ABUSIVE)
{
if (reportResult.getType() == ReportResultType.ACCEPTED)
{
// TODO: force moderator to choose a punishment (requires new punish gui)
CommandCenter.Instance.onPlayerCommandPreprocess(
new PlayerCommandPreprocessEvent(reportCloser,
String.format("/punish %s Report #%s - %s", suspectName, reportId, reason)));
}
// TODO: send these after punishment has been decided (requires new punish gui)
reportCloser.sendMessage(
F.main(prefix, "Report marked as: "
+ C.cGold + reportResult.getType().getName()));
reportCloser.sendMessage(F.main(prefix, "Reason: " + F.elem(reason)));
// if report was marked abusive, check if each of the reporters
// should be banned from using the report system
report.getReporterIds().forEach(reporterId ->
_reportRepository.getAccountUUID(reporterId).thenAccept(reporterUUID ->
{
CoreClient reporterClient = _clientManager.Get(reporterUUID);
checkAbuseBan(reporterClient, reportCloser, reportId);
}));
}
getUUIDs(report.getReporterIds()).thenAccept(ids ->
Bukkit.getScheduler().runTask(_plugin, () ->
{
ReportResultType resultType = reportResult.getType();
ChildJsonMessage jsonMessage = new JsonMessage(F.main(
prefix,
"Your report against " + F.elem(suspectName) + " was marked as " + F.elem(resultType.getName()) + "."))
.extra("\n");
String prefix = getReportPrefix(reportId);
String reason = reportResult.getReason().orElse("No reason specified.");
if (resultType == ReportResultType.ABUSIVE)
if (reportCloser != null)
{
jsonMessage = jsonMessage.add(F.main(prefix, C.cRed + "Submitting false reports may result in punishment."))
.add("\n");
if (reportResult.getType() == ReportResultType.ACCEPTED)
{
// TODO: force moderator to choose a punishment (requires new punish gui)
CommandCenter.Instance.onPlayerCommandPreprocess(
new PlayerCommandPreprocessEvent(reportCloser,
String.format("/punish %s Report #%d - %s", suspectName, reportId, reason)));
}
// TODO: send these after punishment has been decided (requires new punish gui)
reportCloser.sendMessage(
F.main(prefix, "Report marked as: "
+ C.cGold + reportResult.getType().getName()));
reportCloser.sendMessage(F.main(prefix, "Reason: " + F.elem(reason)));
}
jsonMessage = jsonMessage.add(F.main(prefix, "Reason: " + F.elem(reason)));
getUUIDs(report.getReporterIds()).thenAccept(ids ->
{
ReportResultType resultType = reportResult.getType();
ChildJsonMessage jsonMessage = new JsonMessage(F.main(
prefix,
"Your report against " + F.elem(suspectName) + " was marked as " + F.elem(resultType.getName()) + "."))
.extra("\n");
new ReportersNotification(ids, jsonMessage).publish();
if (resultType == ReportResultType.ABUSIVE)
{
jsonMessage = jsonMessage.add(F.main(prefix, C.cRed + "Submitting false reports may result in punishment."))
.add("\n");
}
jsonMessage = jsonMessage.add(F.main(prefix, "Reason: " + F.elem(reason)));
new ReportersNotification(ids, jsonMessage).publish();
});
});
});
_reportRepository.clearCache(reportId);
}).exceptionally(throwable -> {
_plugin.getLogger().log(Level.SEVERE, "Post-report save failed.", throwable);
return null;
_reportRepository.clearCache(reportId);
}
catch (Throwable throwable)
{
_plugin.getLogger().log(Level.SEVERE, "Post-report save failed.", throwable);
}
});
});
}
@ -512,27 +512,12 @@ public class ReportManager
*/
public CompletableFuture<Boolean> isHandlingReport(int accountId)
{
CompletableFuture<List<Long>> future = _reportRepository.getReportsHandling(accountId);
return future.thenApply(reportIds -> {
// if for some reason we cannot fetch the report a user is handling
// assume the worst and return true
// this means we do not end up allowing a user to handle multiple reports simultaneously
if (reportIds == null)
{
return true;
}
for (long reportId : reportIds)
{
if (isActiveReport(reportId).join())
{
return true;
}
}
return false;
});
return _reportRepository.getReportsHandling(accountId)
.thenApply(reportIds -> reportIds.size() > 0)
.exceptionally(throwable -> true);
// ^ if for some reason we cannot fetch the report a user is handling
// assume the worst and return true
// this means we do not end up allowing a user to handle multiple reports simultaneously
}
/**
@ -558,28 +543,24 @@ public class ReportManager
reportIds.stream().map(_reportRepository::getReport).collect(Collectors.toList())
).thenCompose(UtilFuture::sequence)
.thenApply(UtilCollections::unboxPresent)
.thenCompose(reports -> UtilFuture.filter(reports, this::isActiveReport)).thenApply(reports ->
{
Report report = null;
int size = reports.size();
.thenApply(reports ->
{
Report report = null;
int size = reports.size();
if (size == 1)
{
report = reports.get(0);
}
else if (size > 1)
{
throw new IllegalStateException("Account is handling multiple reports.");
}
if (size == 1)
{
report = reports.get(0);
}
else if (size > 1)
{
throw new IllegalStateException("Account is handling multiple reports.");
}
return Optional.ofNullable(report);
});
return Optional.ofNullable(report);
});
future.exceptionally(throwable ->
{
_plugin.getLogger().log(Level.SEVERE, "Error getting the report account is handling.", throwable);
return Optional.empty();
});
future.exceptionally(throwable -> Optional.empty());
return future;
}
@ -632,31 +613,43 @@ public class ReportManager
{
int playerId = _clientManager.Get(player).getAccountId();
getReportHandling(playerId).thenAccept(reportOptional ->
getReportHandling(playerId).whenComplete((reportOptional, throwable) ->
{
if (reportOptional.isPresent())
if (throwable == null)
{
Report report = reportOptional.get();
if (!report.getHandlerTask().isPresent())
if (reportOptional.isPresent())
{
long reportId = report.getId().orElseThrow(() -> new IllegalStateException("Report id is not present."));
new ReportHandlerTask(this, reportId).start(_plugin);
Report report = reportOptional.get();
if (!report.getHandlerTask().isPresent())
{
long reportId = report.getId().orElseThrow(() -> new IllegalStateException("Report id is not present."));
new ReportHandlerTask(this, reportId).start(_plugin);
}
}
}
else
{
_plugin.getLogger().log(Level.SEVERE, "Error whilst checking for report being handled by " + player.getName(), throwable);
}
});
_reportRepository.getOngoingReports(playerId)
.thenAccept(reports ->
{
for (Report report : reports)
{
sendHandlerNotification(report,
F.main(getReportPrefix(report),
String.format("%s has joined %s.", player.getName(), F.elem(_serverName))));
}
}
);
_reportRepository.getOngoingReports(playerId).whenComplete((reports, throwable) ->
{
if (throwable == null)
{
for (Report report : reports)
{
sendHandlerNotification(report,
F.main(getReportPrefix(report),
String.format("%s has joined %s.", player.getName(), F.elem(_serverName))));
}
}
else
{
_plugin.getLogger().log(Level.SEVERE, "Error whilst checking for on-going reports against " + player.getName(), throwable);
}
});
}
protected void onPlayerQuit(Player player)

View File

@ -1,5 +1,7 @@
package mineplex.core.report.command;
import java.util.logging.Level;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
@ -30,19 +32,27 @@ public class ReportAbortCommand extends CommandBase<ReportPlugin>
{
ReportManager reportManager = Plugin.getReportManager();
reportManager.getReportHandling(player).thenApply(BukkitFuture.accept(reportOptional ->
reportManager.getReportHandling(player).whenComplete(BukkitFuture.complete((reportOptional, throwable) ->
{
if (reportOptional.isPresent())
if (throwable == null)
{
Report report = reportOptional.get();
if (reportOptional.isPresent())
{
Report report = reportOptional.get();
reportManager.abortReport(report).thenApply(BukkitFuture.accept(voidValue ->
UtilPlayer.message(player, F.main(ReportManager.getReportPrefix(report),
"Report has been aborted and may be handled by another staff member."))));
reportManager.abortReport(report).thenApply(BukkitFuture.accept(voidValue ->
UtilPlayer.message(player, F.main(ReportManager.getReportPrefix(report),
"Report has been aborted and may be handled by another staff member."))));
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), "You aren't currently handling a report."));
}
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), "You aren't currently handling a report."));
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "An error occurred, please try again later."));
Plugin.getPlugin().getLogger().log(Level.SEVERE, "Error whilst aborting report for player " + player.getName(), throwable);
}
}));
}

View File

@ -1,5 +1,7 @@
package mineplex.core.report.command;
import java.util.logging.Level;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
@ -57,6 +59,7 @@ public class ReportCloseCommand extends CommandBase<ReportPlugin>
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "An error occurred, please try again later."));
Plugin.getPlugin().getLogger().log(Level.SEVERE, "An error occurred whilst fetching the report being handled by " + player.getName(), throwable);
}
});
}

View File

@ -4,6 +4,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -39,62 +40,70 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
ReportRepository reportRepository = reportManager.getReportRepository();
int accountId = _commandCenter.GetClientManager().getAccountId(player);
reportManager.isHandlingReport(player).thenAccept(isHandlingReport ->
reportManager.isHandlingReport(player).whenComplete((handlingReport, throwable) ->
{
if (!isHandlingReport)
if (throwable == null)
{
Map<Report, Double> reportPriorities = Collections.synchronizedMap(new HashMap<>());
boolean devMode = reportManager.isDevMode(player.getUniqueId());
// 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
reportRepository.getUnhandledReports(accountId, devMode).thenCompose(reportRepository::getReports).thenAccept(reports ->
CompletableFuture.allOf(reports.stream().map(report ->
reportManager.calculatePriority(report).thenAccept(priority ->
{
if (priority > 0)
{
reportPriorities.put(report, priority);
}
else
{
// mark the report as expired to keep the database clean
// and reduce future query time
reportManager.expireReport(report);
}
}
)
).toArray(CompletableFuture[]::new)).join()
).thenApply(aVoid ->
if (!handlingReport)
{
Map.Entry<Report, Double> mostImportant = null;
Map<Report, Double> reportPriorities = Collections.synchronizedMap(new HashMap<>());
boolean devMode = reportManager.isDevMode(player.getUniqueId());
for (Map.Entry<Report, Double> entry : reportPriorities.entrySet())
// 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
reportRepository.getUnhandledReports(accountId, devMode).thenCompose(reportRepository::getReports).thenAccept(reports ->
CompletableFuture.allOf(reports.stream().map(report ->
reportManager.calculatePriority(report).thenAccept(priority ->
{
if (priority > 0)
{
reportPriorities.put(report, priority);
}
else
{
// mark the report as expired to keep the database clean
// and reduce future query time
reportManager.expireReport(report);
}
}
)
).toArray(CompletableFuture[]::new)).join()
).thenApply(aVoid ->
{
if (mostImportant == null || (double) entry.getValue() > mostImportant.getValue())
Map.Entry<Report, Double> mostImportant = null;
for (Map.Entry<Report, Double> entry : reportPriorities.entrySet())
{
mostImportant = entry;
if (mostImportant == null || (double) entry.getValue() > mostImportant.getValue())
{
mostImportant = entry;
}
}
}
return mostImportant == null ? null : mostImportant.getKey();
}).thenCompose(BukkitFuture.accept(report ->
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
{
if (report != null)
{
reportManager.handleReport(report, player);
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "No report found, report queue is empty."));
}
}));
Bukkit.getScheduler().runTask(Plugin.getPlugin(), () ->
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "You are already handling a report.")));
}
}
else
{
Bukkit.getScheduler().runTask(Plugin.getPlugin(), () ->
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "You are already handling a report.")));
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "An error occurred, please try again later."));
Plugin.getPlugin().getLogger().log(Level.SEVERE, "Error whilst checking for reports being handled by " + player.getName(), throwable);
}
});
}

View File

@ -227,11 +227,7 @@ public class ReportRepository
return reportsHandling;
});
future.exceptionally(throwable ->
{
_logger.log(Level.SEVERE, "Error fetching reports being handled by specified account.", throwable);
return new ArrayList<>();
});
future.exceptionally(throwable -> null);
return future;
}

View File

@ -0,0 +1 @@
ALTER TABLE Account.reportResults MODIFY reason VARCHAR(256);

View File

@ -161,4 +161,6 @@ INSERT INTO Account.reportResultTypes (id, globalStat, name) VALUES (3, 1, 'EXPI
INSERT INTO Account.snapshotTypes (id, name) VALUES (0, 'CHAT');
INSERT INTO Account.snapshotTypes (id, name) VALUES (1, 'PM');
INSERT INTO Account.snapshotTypes (id, name) VALUES (2, 'PARTY');
INSERT INTO Account.snapshotTypes (id, name) VALUES (2, 'PARTY');
INSERT INTO Account.reportTeams (id, name) VALUES (0, 'RC');

View File

@ -356,12 +356,13 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
}
$validId = isset($_GET['id']);
$idError = "";
$errorMsg = "";
$id = null;
$expanded = null;
$report = null;
$snapshot = null;
$messages = null;
if ($validId)
{
@ -372,11 +373,20 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
if ($report)
{
$snapshot = $report->getSnapshot();
if ($snapshot != null)
{
$messages = $snapshot->getMessages();
}
else
{
$errorMsg = 'No associated snapshot found for report.';
}
}
else
{
$validId = false;
$idError = "Invalid id.";
$errorMsg = "Invalid id.";
}
}
?>
@ -415,12 +425,15 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
</form>
</div>
<?php if (isset($_GET['id']) && !$validId && !empty($idError)): ?>
<?php if ((isset($_GET['id']) && !$validId) || !empty($errorMsg)): ?>
<div id="content" class="center-block" style="text-align: center; background-color: rgba(204, 34, 42, 0.52);">
<p class="error-oh-no" style="font-size: 60px;">What did you do?!?!?</p>
<img src="img/shaun.gif" />
<p class="error-oh-no" style="font-size: 40px;">Error: <?= $idError ?></p>
<br>
<?php if (!empty($errorMsg)): ?>
<p class="error-oh-no" style="font-size: 40px;">Error: <?= $errorMsg ?></p>
<br />
<?php endif; ?>
</div>
<?php else: ?>
<?php if (!isset($_GET['id'])) exit(); ?>
@ -440,9 +453,6 @@ WHERE snapshotMessageMap.snapshotId = snapshots.id
<div id="log">
<?php
// INITIALIZE
// Get messages and the amount that we are going to display
$messages = $snapshot->getMessages();
$messageCount = count($messages);
$displayAmount = $expanded || $messageCount <= collapsedMessageCount ? $messageCount : collapsedMessageCount;