Skip to content

Commit

Permalink
feat: add instantReplay
Browse files Browse the repository at this point in the history
  • Loading branch information
MC-XiaoHei committed May 3, 2024
1 parent 462a4df commit 71997cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/xor7/iseeyou/ConfigData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ data class FilterConfig(
data class InstantReplayConfig(
var enabled: Boolean = false,
var replayMinutes: Int = 5,
var createPerMinutes: Int = 1,
var createMinutes: Int = 1,
var recordPath: String = "replay/instant/\${name}@\${uuid}",
)
1 change: 1 addition & 0 deletions src/main/java/cn/xor7/iseeyou/EventListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ object EventListener : Listener {
val player = event.player
if (toml!!.data.instantReplay.enabled) {
InstantReplayManager.taskMap[player.uniqueId.toString()]?.cancel()
InstantReplayManager.taskMap.remove(player.uniqueId.toString())
}
val photographer: Photographer = photographers[player.uniqueId.toString()] ?: return
highSpeedPausedPhotographers.remove(photographer)
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/cn/xor7/iseeyou/InstantReplayManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ object InstantReplayManager {
}
val photographer = Bukkit
.getPhotographerManager()
.createPhotographer(UUID.randomUUID().toString(), player.location)?.apply {
val currentTime = LocalDateTime.now()
.createPhotographer(uuid.replace("-", "").substring(0, 16), player.location)
?.apply {
val recordPath: String = toml!!.data.instantReplay.recordPath
.replace("\${name}", player.name)
.replace("\${uuid}", player.uniqueId.toString())
File(recordPath).mkdirs()
val recordFile = File(recordPath + "/" + currentTime.format(DATE_FORMATTER) + ".mcpr")
if (recordFile.exists()) {
recordFile.delete()
}
recordFile.createNewFile()
val recordFile = File(recordPath + "/" + LocalDateTime.now().format(DATE_FORMATTER) + ".mcpr")
recordFileMap[uuid] = recordFile
setRecordFile(recordFile)
setFollowPlayer(player)
Expand All @@ -58,7 +54,7 @@ object InstantReplayManager {
}.runTaskTimer(
instance ?: return,
0,
(toml!!.data.instantReplay.createPerMinutes * 60 * 1000).toLong()
(toml!!.data.instantReplay.createMinutes * 60 * 20).toLong()
).also { task ->
taskMap[player.uniqueId.toString()] = task
}
Expand All @@ -74,7 +70,17 @@ object InstantReplayManager {
firstSubmitTime = expectedExpiration
}
}
val recordPath: String = toml!!.data.instantReplay.recordPath
.replace("\${name}", player.name)
.replace("\${uuid}", player.uniqueId.toString())
File(recordPath).mkdirs()
val recordFile = File(recordPath + "/" + LocalDateTime.now().format(DATE_FORMATTER) + ".mcpr")
if (recordFile.exists()) {
recordFile.delete()
}
recordFile.createNewFile()
photographerMap[firstSubmitUUID]?.stopRecording(toml!!.data.asyncSave) ?: return false
photographerMap.remove(firstSubmitUUID)
return true
}
}

0 comments on commit 71997cf

Please sign in to comment.