diff --git a/src/main/kotlin/network/warzone/mars/report/ReportFeature.kt b/src/main/kotlin/network/warzone/mars/report/ReportFeature.kt index f679d13..0e02fbf 100644 --- a/src/main/kotlin/network/warzone/mars/report/ReportFeature.kt +++ b/src/main/kotlin/network/warzone/mars/report/ReportFeature.kt @@ -21,10 +21,12 @@ object ReportFeature : Feature(), Listener { @EventHandler - fun onReportCreate(event: PlayerReportEvent) = runBlocking { + fun onReportCreate(event: PlayerReportEvent) { val onlineStaff = Bukkit.getOnlinePlayers().filter { it.hasPermission("pgm.staff") } .map { SimplePlayer(it.uniqueId, it.name) }.toSet() - ReportService.create(event.player.simple, event.sender.simple, event.reason, onlineStaff) + Mars.async { + ReportService.create(event.player.simple, event.sender.simple, event.reason, onlineStaff) + } } override fun getCommands(): List = listOf(ReportCommands()) diff --git a/src/main/kotlin/network/warzone/mars/report/commands/ReportCommands.kt b/src/main/kotlin/network/warzone/mars/report/commands/ReportCommands.kt index 5543dee..1a14f82 100644 --- a/src/main/kotlin/network/warzone/mars/report/commands/ReportCommands.kt +++ b/src/main/kotlin/network/warzone/mars/report/commands/ReportCommands.kt @@ -61,22 +61,22 @@ class ReportCommands { fun report(@Sender sender: Player, target: Player, @Text reason: String) { val matchPlayer = sender.matchPlayer val match = matchPlayer.match - if (!sender.hasPermission(Permissions.STAFF)) { + val needsCooldown = !sender.hasPermission(Permissions.STAFF) + if (needsCooldown) { // Check for cooldown val lastReport: Instant? = LAST_REPORT_SENT.getIfPresent(sender.uniqueId) - lastReport ?: LAST_REPORT_SENT.put(sender.uniqueId, Instant.now()) - - val timeSinceReport: Duration = Duration.between(lastReport, Instant.now()) - val secondsRemaining: Long = REPORT_COOLDOWN_SECONDS - timeSinceReport.getSeconds() - if (secondsRemaining > 0) { - val secondsComponent: TextComponent = text(secondsRemaining.toString()) - val secondsLeftComponent: TextComponent = text() + if (lastReport != null) { + val timeSinceReport: Duration = Duration.between(lastReport, Instant.now()) + val secondsRemaining: Long = REPORT_COOLDOWN_SECONDS - timeSinceReport.getSeconds() + if (secondsRemaining > 0) { + val secondsComponent: TextComponent = text(secondsRemaining.toString()) + val secondsLeftComponent: TextComponent = text() .append(secondsComponent) .append(text(if (secondsRemaining != 1L) "misc.seconds" else "misc.second")).build() - matchPlayer.sendWarning(text("Please wait ").append(secondsLeftComponent).append(text(" before running that command again"))) - return + matchPlayer.sendWarning(text("Please wait ").append(secondsLeftComponent).append(text(" before running that command again"))) + return + } } - } val accused: MatchPlayer? = match.getPlayer(target) @@ -115,6 +115,9 @@ class ReportCommands { reason = reason ) ) + if (needsCooldown) { + LAST_REPORT_SENT.put(sender.uniqueId, Instant.now()) + } ChatDispatcher.broadcastAdminChatMessage(component, match, Optional.of(REPORT_NOTIFY_SOUND)) }