Prevent non-handlers from closing a report

This commit is contained in:
Keir Nellyer 2016-07-14 22:16:53 +01:00
parent 1885854bc4
commit 7b5adc717d
2 changed files with 28 additions and 18 deletions

View File

@ -244,14 +244,7 @@ public class ReportManager
*/
public CompletableFuture<Long> saveReport(Report report)
{
CompletableFuture<Long> updateCompletableFuture = _reportRepository.updateReport(report);
updateCompletableFuture.exceptionally((throwable) -> {
_plugin.getLogger().log(Level.SEVERE, "Error whilst saving report.", throwable);
return null;
});
return updateCompletableFuture;
return _reportRepository.updateReport(report);
}
/**

View File

@ -1,11 +1,14 @@
package mineplex.core.report.command;
import java.util.Optional;
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.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ui.ReportResultPage;
@ -30,19 +33,33 @@ public class ReportCloseCommand extends CommandBase<ReportPlugin>
{
long reportId = Long.parseLong(args[0]);
String reason = F.combine(args, 1, null, false);
ReportManager reportManager = Plugin.getReportManager();
Plugin.getReportManager().isActiveReport(reportId).thenCompose(BukkitFuture.accept(isActive ->
reportManager.getReportRepository().getReport(reportId).thenAccept(report ->
{
if (isActive)
reportManager.isActiveReport(reportId).thenCompose(BukkitFuture.accept(isActive ->
{
ReportResultPage reportResultPage = new ReportResultPage(Plugin, reportId, player, reason);
reportResultPage.openInventory(); // report is closed when player selects the result
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "That report either does not exist or has been closed."));
}
}));
if (isActive)
{
int senderId = _commandCenter.GetClientManager().getAccountId(player);
Optional<Integer> handlerIdOptional = report.getHandlerId();
if (handlerIdOptional.isPresent() && handlerIdOptional.get() == senderId)
{
ReportResultPage reportResultPage = new ReportResultPage(Plugin, reportId, player, reason);
reportResultPage.openInventory(); // report is closed when player selects the result
}
else
{
player.sendMessage(F.main(Plugin.getName(), C.cRed + "You cannot close this report as you aren't the handler."));
}
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "That report either does not exist or has been closed."));
}
}));
});
}
}
}