Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.20.2' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Feb 17, 2024
2 parents 53e5ed2 + 92c26c9 commit 611c929
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ After you boot the server a new file will be generated in the path
| `"pause_unloaded_chunks"` | <p> If an area of chunks is being recorded and the area is unloaded and this is set to `true` then the replay will pause the recording until the chunks are loaded again. </p> <p> If set to false the chunks will be recorded as if they were loaded. </p> |
| `"pause_notify_players"` | <p> If `pause_unloaded_chunks` is enabled and this is enabled then when the recording for the chunk area is paused or resumed all online players will be notified. </p> |
| `"restart_after_max_file_size"` | <p> If a max file size is set and this limit is reached then the replay recording will automatically restart creating a new replay file. </p> |
| `"include_compressed_in_status"` | <p> Includes the compressed file size of the replays when you do `/replay status`, for long replays this may cause the status message to take a while to be displayed, so you can disable it. </p> |
| `"fix_carpet_bot_view_distance"` | <p> If you are recording carpet bots you want to enable this as it sets the view distance to the server view distance. Otherwise it will only record a distance of 2 chunks around the bot. |
| `"ignore_sound_packets"` | <p> If you are recording a large area for a timelapse it's unlikely you'll want to record any sounds, these can eat up significant storage space. </p> |
| `"ignore_light_packets"` | <p> Light is calculated on the client as well as on the server so light packets are mostly redundant. </p> |
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ permissions_version=0.3-SNAPSHOT
fabric_version=0.91.0+1.20.1
carpet_version=1.4.112

mod_version=1.0.3
mod_version=1.0.4

org.gradle.jvmargs=-Xmx4000m
54 changes: 40 additions & 14 deletions src/main/kotlin/me/senseiwells/replay/commands/ReplayCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import net.minecraft.server.level.ServerLevel
import net.minecraft.world.level.ChunkPos
import org.apache.commons.lang3.builder.StandardToStringStyle
import org.apache.commons.lang3.builder.ToStringBuilder
import java.util.concurrent.CompletableFuture

object ReplayCommand {
@JvmStatic
Expand Down Expand Up @@ -300,22 +301,44 @@ object ReplayCommand {
.append(if (ServerReplay.config.enabled) "enabled" else "disabled")
.append("\n")

this.appendRecorders(builder, "Players", PlayerRecorders.all(), style)
this.appendRecorders(builder, "Chunks", ChunkRecorders.all(), style)
val players = this.getStatusFuture("Players", PlayerRecorders.all(), style)
val chunks = this.getStatusFuture("Chunks", ChunkRecorders.all(), style)

context.source.sendSystemMessage(Component.literal(builder.removeSuffix("\n").toString()))
CompletableFuture.runAsync {
for (player in players) {
builder.append(player.join())
}
for (chunk in chunks) {
builder.append(chunk.join())
}

context.source.server.execute {
context.source.sendSuccess(
{ Component.literal(builder.removeSuffix("\n").toString()) },
true
)
}
}

context.source.sendSuccess({
var message = "Generating replay status..."
if (ServerReplay.config.includeCompressedReplaySizeInStatus) {
message += "\nCalculating compressed sizes of replays (this may take a while)"
}
Component.literal(message)
}, true)
return 1
}

private fun appendRecorders(
builder: StringBuilder,
private fun getStatusFuture(
type: String,
recorders: Collection<ReplayRecorder>,
style: StandardToStringStyle,
) {
): List<CompletableFuture<String>> {
if (recorders.isNotEmpty()) {
builder.append("Currently Recording $type:").append("\n")
for ((recorder, compressed) in recorders.map { it to it.getCompressedRecordingSize() }) {
val futures = ArrayList<CompletableFuture<String>>()
futures.add(CompletableFuture.completedFuture("Currently Recording $type:\n"))
for (recorder in recorders) {
val seconds = recorder.getTotalRecordingTime() / 1000
val hours = seconds / 3600
val minutes = seconds % 3600 / 60
Expand All @@ -326,15 +349,18 @@ object ReplayCommand {
.append("name", recorder.getName())
.append("time", time)
.append("raw", FileUtils.formatSize(recorder.getRawRecordingSize()))
.append("compressed", FileUtils.formatSize(compressed.join()))
if (ServerReplay.config.debug) {
sub.append("debug", recorder.getDebugPacketData())
if (ServerReplay.config.includeCompressedReplaySizeInStatus) {
val compressed = recorder.getCompressedRecordingSize()
futures.add(compressed.thenApplyAsync {
"${sub.append("compressed", FileUtils.formatSize(it))}\n"
})
} else {
futures.add(CompletableFuture.completedFuture("$sub\n"))
}
builder.append(sub.toString()).append("\n")
}
} else {
builder.append("Not Currently Recording $type").append("\n")
return futures
}
return listOf(CompletableFuture.completedFuture("Not Currently Recording $type\n"))
}

private fun suggestChunkX(): SuggestionProvider<CommandSourceStack> {
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/me/senseiwells/replay/config/ReplayConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class ReplayConfig {
@SerialName("restart_after_max_file_size")
var restartAfterMaxFileSize = false

@SerialName("include_compressed_in_status")
var includeCompressedReplaySizeInStatus = true

@SerialName("pause_unloaded_chunks")
var skipWhenChunksUnloaded = false
@SerialName("pause_notify_players")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object ResourceLocationSerializer: KSerializer<ResourceLocation> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("dimension", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: ResourceLocation) {

encoder.encodeString(value.toString())
}

Expand Down

0 comments on commit 611c929

Please sign in to comment.