Improve code and error logging
This commit is contained in:
parent
0783f3b693
commit
87df6804c9
@ -11,6 +11,7 @@ import mineplex.core.chatsnap.command.PushSnapshotsCommand;
|
||||
import mineplex.core.chatsnap.command.PushSnapshotsHandler;
|
||||
import mineplex.core.command.CommandCenter;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.report.command.ReportHandlerNotification;
|
||||
@ -36,7 +37,7 @@ public class ReportManager
|
||||
|
||||
private static final int ABUSE_BAN_THRESHOLD = 1;
|
||||
|
||||
private JavaPlugin _javaPlugin;
|
||||
private JavaPlugin _plugin;
|
||||
private SnapshotManager _snapshotManager;
|
||||
private CoreClientManager _clientManager;
|
||||
private String _serverName;
|
||||
@ -45,10 +46,10 @@ public class ReportManager
|
||||
private final ReportRepository _reportRepository;
|
||||
private final ReportProfileRepository _reportProfileRepository;
|
||||
|
||||
public ReportManager(JavaPlugin javaPlugin, SnapshotManager snapshotManager, CoreClientManager clientManager,
|
||||
public ReportManager(JavaPlugin plugin, SnapshotManager snapshotManager, CoreClientManager clientManager,
|
||||
String serverName, int serverWeight)
|
||||
{
|
||||
_javaPlugin = javaPlugin;
|
||||
_plugin = plugin;
|
||||
_snapshotManager = snapshotManager;
|
||||
_clientManager = clientManager;
|
||||
_serverName = serverName;
|
||||
@ -56,11 +57,11 @@ public class ReportManager
|
||||
|
||||
_reportRepository = new ReportRepository(this);
|
||||
|
||||
_reportProfileRepository = new ReportProfileRepository(javaPlugin);
|
||||
_reportProfileRepository = new ReportProfileRepository(plugin);
|
||||
|
||||
ServerCommandManager commandManager = ServerCommandManager.getInstance();
|
||||
ReportNotificationCallback notificationCallback = new ReportNotificationCallback(this);
|
||||
PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(_snapshotManager, _javaPlugin.getLogger());
|
||||
PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(_snapshotManager, _plugin.getLogger());
|
||||
commandManager.registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, notificationCallback);
|
||||
commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler);
|
||||
}
|
||||
@ -92,7 +93,7 @@ public class ReportManager
|
||||
|
||||
Report report = _reportRepository.getOngoingReport(suspectId, category)
|
||||
.exceptionally(throwable -> {
|
||||
_javaPlugin.getLogger().log(Level.SEVERE, "Error fetching ongoing report.", throwable);
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error fetching ongoing report.", throwable);
|
||||
return Optional.empty();
|
||||
}).thenCompose(reportIdOptional -> reportIdOptional.isPresent() ? _reportRepository.getReport(reportIdOptional.get()) : CompletableFuture.completedFuture(null))
|
||||
.join();
|
||||
@ -104,15 +105,15 @@ public class ReportManager
|
||||
|
||||
report.addReportReason(new ReportMessage(reporterId, reason, _serverName, _serverWeight));
|
||||
|
||||
_reportRepository.updateReport(report)
|
||||
saveReport(report)
|
||||
.exceptionally(throwable -> {
|
||||
_javaPlugin.getLogger().log(Level.SEVERE, "Error updating report to database.", throwable);
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error updating report to database.", throwable);
|
||||
return null;
|
||||
}).join(); // join (block) so that report is assigned an id
|
||||
|
||||
return report;
|
||||
}).exceptionally(throwable -> {
|
||||
_javaPlugin.getLogger().log(Level.SEVERE, "Error whilst reporting player.", throwable);
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error whilst reporting player.", throwable);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@ -156,12 +157,14 @@ public class ReportManager
|
||||
pushCommand.publish();
|
||||
}
|
||||
|
||||
_reportRepository.updateReport(report);
|
||||
|
||||
saveReport(report);
|
||||
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);
|
||||
new ReportHandlerMessageTask(this, report).runTaskTimer(_plugin, 20L * 10, 20L * 10);
|
||||
|
||||
reportHandler.sendMessage(
|
||||
F.main(getReportPrefix(reportId), C.cAqua + "You are now handling this report."));
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +193,10 @@ public class ReportManager
|
||||
}
|
||||
|
||||
report.setReportResult(reportResult);
|
||||
_reportRepository.updateReport(report).thenAccept(reportId ->
|
||||
|
||||
CompletableFuture<Long> saveCompletableFuture = saveReport(report);
|
||||
|
||||
saveCompletableFuture.thenAccept(reportId ->
|
||||
{
|
||||
_reportRepository.clearCache(reportId);
|
||||
|
||||
@ -208,6 +214,18 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the amount of reports this player has filed which have been marked abusive,
|
||||
* this value is then compared with the abuse threshold to determine whether the player
|
||||
@ -222,7 +240,7 @@ public class ReportManager
|
||||
|
||||
return _reportRepository.getResultCount(accountId, ReportResultType.ABUSIVE)
|
||||
.exceptionally(throwable -> {
|
||||
_javaPlugin.getLogger().log(Level.SEVERE, "Error fetching user report result count.", throwable);
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error fetching user report result count.", throwable);
|
||||
return 0;
|
||||
}).thenApply(abusiveReportsCount -> abusiveReportsCount < ABUSE_BAN_THRESHOLD);
|
||||
}
|
||||
@ -278,6 +296,9 @@ public class ReportManager
|
||||
}
|
||||
|
||||
return false;
|
||||
}).exceptionally(throwable -> {
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error fetching reports player is handling.", throwable);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@ -314,7 +335,7 @@ public class ReportManager
|
||||
|
||||
if (priority <= 0)
|
||||
{
|
||||
System.out.println("Closing report due to expiration");
|
||||
System.out.println("Closing report due to expiration (#" + report.getId().orElse((long) -1) + ").");
|
||||
closeReport(report, null, new ReportResult(ReportResultType.EXPIRED, null));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user