Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Code Refactoring:Fixed potential bug in aggregate monitoring, ensurin…
Browse files Browse the repository at this point in the history
…g no interference when aggregate monitoring is turned off.
  • Loading branch information
CerealAxis committed Feb 21, 2024
1 parent e6b3464 commit 2c9839d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
rootProject.name = "ISeeYou"
rootProject.name = "ISeeYou-Fork"
2 changes: 1 addition & 1 deletion src/main/java/xaviermc/top/iseeyou/ConfigData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
Expand Down
31 changes: 24 additions & 7 deletions src/main/java/xaviermc/top/iseeyou/anticheat/AntiCheatListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.time.Duration
import java.time.LocalDateTime
import java.util.*


val suspiciousPhotographers: MutableMap<String, SuspiciousPhotographer> = mutableMapOf()

object AntiCheatListener : Listener {
Expand All @@ -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) {
Expand All @@ -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())
Expand All @@ -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
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 2c9839d

Please sign in to comment.