From be01423c016e87cda01f51ab696b72def5364fbd Mon Sep 17 00:00:00 2001 From: Fandit Date: Wed, 2 Jul 2025 13:10:43 -0400 Subject: [PATCH 1/2] Added warnings of previous trial timings --- .../org/openredstone/trialore/TrialCommand.kt | 40 ++++++++++++++++++- .../org/openredstone/trialore/TrialOre.kt | 5 ++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt b/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt index 995641c..5bd7a33 100644 --- a/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt +++ b/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt @@ -7,6 +7,7 @@ import java.time.Instant import java.time.LocalDateTime import java.time.ZoneOffset import java.time.temporal.ChronoUnit +import java.util.UUID fun getDate(timestamp: Long) = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneOffset.UTC) @@ -32,9 +33,35 @@ class TrialCommand( private val version: String, ) : BaseCommand() { + private fun isTrialOkay(testificate: UUID): Boolean { + val trials = trialORE.database.getTrials(testificate) + val now = System.currentTimeMillis() + + val recentTrials = trials.map { trialORE.database.getTrialInfo(it) } + .filter { + val trialTime = it.start.toLong() + trialTime >= now - trialORE.config.periodDays * 24 * 60 * 60 * 1000L + } + .sortedByDescending { it.start } + + if (recentTrials.size >= trialORE.config.countPerPeriod) { + return false + } + + val mostRecent = recentTrials.firstOrNull() + if (mostRecent != null) { + val hoursSinceLast = (now - mostRecent.start.toLong()) / (1000 * 60 * 60) + if (hoursSinceLast < trialORE.config.minSpacingHours) { + return false + } + } + + return true + } + @Default() @Subcommand("info") - @Description("Information about a TrialORE") + @Description("Information about TrialORE") fun onInfo(player: Player) { player.renderMiniMessage("Current TrialORE version: $version") player.renderMiniMessage("For more details on commands, " + @@ -72,6 +99,11 @@ class TrialCommand( player.renderMessage(note) } } + + // Warn of recent trials + if (!this.isTrialOkay(testificate)) { + player.renderMiniMessage("Warning: According to TrialORE settings, this user is ineligible for trial. Check past trials") + } } @CommandAlias("trialstart") @@ -96,6 +128,12 @@ class TrialCommand( if (!app.startsWith("https://discourse.openredstone.org/")) { throw TrialOreException("Invalid app: $app") } + + // Warn of recent trials + if (!this.isTrialOkay(testificate.uniqueId)) { + player.renderMiniMessage("Warning: According to TrialORE settings, this user is ineligible for trial. Check past trials") + } + player.renderMessage("Starting trial of ${testificate.name}") testificate.renderMessage("Starting trial with ${player.name}") trialORE.startTrial(player.uniqueId, testificate.uniqueId, app) diff --git a/src/main/kotlin/org/openredstone/trialore/TrialOre.kt b/src/main/kotlin/org/openredstone/trialore/TrialOre.kt index ee01063..b6010a8 100644 --- a/src/main/kotlin/org/openredstone/trialore/TrialOre.kt +++ b/src/main/kotlin/org/openredstone/trialore/TrialOre.kt @@ -42,7 +42,10 @@ data class TrialOreConfig( val testificateGroup: String = "testificate", val builderGroup: String = "builder", val webhook: String = "webhook", - val abandonForgiveness: Long = 6000 + val abandonForgiveness: Long = 6000, + val countPerPeriod: Int = 2, + val periodDays: Int = 7, + val minSpacingHours: Int = 24 ) data class TrialMeta( From 3baf387b7283819031f7be85b019dc105e506058 Mon Sep 17 00:00:00 2001 From: Th3F4nd1t Date: Wed, 2 Jul 2025 13:38:53 -0400 Subject: [PATCH 2/2] Update TrialCommand.kt --- src/main/kotlin/org/openredstone/trialore/TrialCommand.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt b/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt index 5bd7a33..f9ab6c5 100644 --- a/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt +++ b/src/main/kotlin/org/openredstone/trialore/TrialCommand.kt @@ -40,7 +40,7 @@ class TrialCommand( val recentTrials = trials.map { trialORE.database.getTrialInfo(it) } .filter { val trialTime = it.start.toLong() - trialTime >= now - trialORE.config.periodDays * 24 * 60 * 60 * 1000L + trialTime >= now - trialORE.config.periodDays * 24 * 60 * 60L } .sortedByDescending { it.start }