From 2c9839d7e25c993ac1eb90290e393e7bce9d367e Mon Sep 17 00:00:00 2001 From: CerealAxis <2741798712@qq.com> Date: Wed, 21 Feb 2024 14:33:37 +0800 Subject: [PATCH] Code Refactoring:Fixed potential bug in aggregate monitoring, ensuring no interference when aggregate monitoring is turned off. --- .github/workflows/release.yml | 2 +- settings.gradle.kts | 2 +- .../java/xaviermc/top/iseeyou/ConfigData.kt | 2 +- .../iseeyou/anticheat/AntiCheatListener.kt | 31 ++++++++++++++----- .../anticheat/SuspiciousPhotographer.kt | 4 ++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e96e56e..5873636 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,5 +34,5 @@ jobs: uses: marvinpinto/action-automatic-releases@latest with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - files: build/libs/ISeeYou-*-all.jar + files: build/libs/ISeeYou-Fork-*-all.jar prerelease: false \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index de1d375..6b7c607 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,4 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0" } -rootProject.name = "ISeeYou" \ No newline at end of file +rootProject.name = "ISeeYou-Fork" \ No newline at end of file diff --git a/src/main/java/xaviermc/top/iseeyou/ConfigData.kt b/src/main/java/xaviermc/top/iseeyou/ConfigData.kt index 79ab461..dff5f41 100644 --- a/src/main/java/xaviermc/top/iseeyou/ConfigData.kt +++ b/src/main/java/xaviermc/top/iseeyou/ConfigData.kt @@ -65,7 +65,7 @@ data class RecordSuspiciousPlayerConfig( var enableMatrixIntegration: Boolean = false, var aggregateMonitoring: Boolean = false, var recordMinutes: Long = 5, - var recordPath: String = "replay/suspicious/Themis/\${name}@\${uuid}", + var recordPath: String = "replay/suspicious/\${name}@\${uuid}", var themisRecordPath: String = "replay/suspicious/Themis/\${name}@\${uuid}", var matrixRecordPath: String = "replay/suspicious/Matrix/\${name}@\${uuid}" ) diff --git a/src/main/java/xaviermc/top/iseeyou/anticheat/AntiCheatListener.kt b/src/main/java/xaviermc/top/iseeyou/anticheat/AntiCheatListener.kt index 9ccfac8..3f8bb55 100644 --- a/src/main/java/xaviermc/top/iseeyou/anticheat/AntiCheatListener.kt +++ b/src/main/java/xaviermc/top/iseeyou/anticheat/AntiCheatListener.kt @@ -14,7 +14,6 @@ import java.time.Duration import java.time.LocalDateTime import java.util.* - val suspiciousPhotographers: MutableMap = mutableMapOf() object AntiCheatListener : Listener { @@ -38,7 +37,25 @@ object AntiCheatListener : Listener { fun onAntiCheatAction(player: Player, source: String? = null) { Bukkit.getScheduler().runTask(instance!!, Runnable { - val photographerName = (player.name + "_sus_" + UUID.randomUUID().toString().replace("-", "")).substring(0, 16) + val photographerName = if (toml!!.data.recordSuspiciousPlayer.aggregateMonitoring) { + val name = "Sus_${player.name}_${source ?: ""}_${UUID.randomUUID().toString().replace("-", "")}" + name.substring(0, 16) + } else { + val prefix = when (source) { + "Themis" -> "Th" + "Matrix" -> "Ma" + else -> throw IllegalArgumentException("Unknown source: $source") + } + val name = "$prefix${player.name}_${UUID.randomUUID().toString().replace("-", "")}" + name.substring(0, 16) + } + + val existingPhotographer = suspiciousPhotographers[player.name + source] + if (existingPhotographer != null) { + existingPhotographer.lastTagged = System.currentTimeMillis() + return@Runnable + } + val photographer = Bukkit.getPhotographerManager().createPhotographer(photographerName, player.location) if (photographer == null) { @@ -48,13 +65,13 @@ object AntiCheatListener : Listener { photographer.setFollowPlayer(player) val currentTime = LocalDateTime.now() val recordPath: String = if (toml!!.data.recordSuspiciousPlayer.aggregateMonitoring) { + toml!!.data.recordSuspiciousPlayer.recordPath + } else { when (source) { "Themis" -> toml!!.data.recordSuspiciousPlayer.themisRecordPath "Matrix" -> toml!!.data.recordSuspiciousPlayer.matrixRecordPath else -> throw IllegalArgumentException("Unknown source: $source") } - } else { - toml!!.data.recordSuspiciousPlayer.recordPath } .replace("\${name}", player.name) .replace("\${uuid}", player.uniqueId.toString()) @@ -65,13 +82,13 @@ object AntiCheatListener : Listener { recordFile.delete() } recordFile.createNewFile() - photographer.setRecordFile(recordFile) - suspiciousPhotographers[player.name] = SuspiciousPhotographer( + val suspiciousPhotographer = SuspiciousPhotographer( photographer = photographer, name = player.name, lastTagged = System.currentTimeMillis(), - source = source + source = source, ) + suspiciousPhotographers[player.name + source] = suspiciousPhotographer }) } diff --git a/src/main/java/xaviermc/top/iseeyou/anticheat/SuspiciousPhotographer.kt b/src/main/java/xaviermc/top/iseeyou/anticheat/SuspiciousPhotographer.kt index e238221..9acc8b6 100644 --- a/src/main/java/xaviermc/top/iseeyou/anticheat/SuspiciousPhotographer.kt +++ b/src/main/java/xaviermc/top/iseeyou/anticheat/SuspiciousPhotographer.kt @@ -5,6 +5,8 @@ import top.leavesmc.leaves.entity.Photographer data class SuspiciousPhotographer( val photographer: Photographer, val name: String, - val lastTagged: Long, +// var matrixlastTagged: Long, +// var themislastTagged: Long, + var lastTagged: Long, val source: String? = null )