Skip to content

Commit

Permalink
Fix plugin entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiwells committed Jul 24, 2024
1 parent 19f97ec commit 69b827f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ tasks {
publishing {
publications {
create<MavenPublication>("mavenJava") {
groupId = "com.github.senseiwells"
artifactId = "ServerReplay"
version = getGitHash()
from(project.components.getByName("java"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package me.senseiwells.replay.api

import me.senseiwells.replay.ServerReplay
import me.senseiwells.replay.api.ServerReplayPluginManager.registerPlugin
import me.senseiwells.replay.chunk.ChunkRecorder
import me.senseiwells.replay.player.PlayerRecorder
import net.fabricmc.loader.api.FabricLoader

/**
Expand Down Expand Up @@ -42,6 +44,18 @@ object ServerReplayPluginManager {
this.plugins.add(plugin)
}

internal fun startReplay(recorder: PlayerRecorder) {
for (plugin in this.plugins) {
plugin.onPlayerReplayStart(recorder)
}
}

internal fun startReplay(recorder: ChunkRecorder) {
for (plugin in this.plugins) {
plugin.onChunkReplayStart(recorder)
}
}

internal fun loadPlugins() {
val containers = FabricLoader.getInstance().getEntrypointContainers("server_replay", ServerReplayPlugin::class.java)
for (container in containers) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/me/senseiwells/replay/chunk/ChunkRecorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.longs.LongOpenHashSet
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import me.senseiwells.replay.ServerReplay
import me.senseiwells.replay.api.ServerReplayPluginManager
import me.senseiwells.replay.mixin.chunk.WitherBossAccessor
import me.senseiwells.replay.mixin.rejoin.ChunkMapAccessor
import me.senseiwells.replay.player.PlayerRecorder
Expand Down Expand Up @@ -98,6 +99,7 @@ class ChunkRecorder internal constructor(
RejoinedReplayPlayer.rejoin(this.dummy, this)
this.spawnPlayer()
this.sendChunksAndEntities()
ServerReplayPluginManager.startReplay(this)

val chunks = this.level.chunkSource.chunkMap as ChunkMapAccessor
for (pos in this.chunks) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.senseiwells.replay.player

import com.mojang.authlib.GameProfile
import me.senseiwells.replay.api.ServerReplayPluginManager
import me.senseiwells.replay.recorder.ChunkSender
import me.senseiwells.replay.recorder.ReplayRecorder
import me.senseiwells.replay.rejoin.RejoinedReplayPlayer
Expand Down Expand Up @@ -81,6 +82,7 @@ class PlayerRecorder internal constructor(
val player = this.player ?: return false
RejoinedReplayPlayer.rejoin(player, this)
this.sendChunksAndEntities()
ServerReplayPluginManager.startReplay(this)
return true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.senseiwells.replay.rejoin

import me.senseiwells.replay.api.ServerReplayPluginManager
import me.senseiwells.replay.chunk.ChunkRecorder
import me.senseiwells.replay.ducks.`ServerReplay$PackTracker`
import me.senseiwells.replay.player.PlayerRecorder
import me.senseiwells.replay.recorder.ReplayRecorder
import me.senseiwells.replay.viewer.ReplayViewerUtils
import net.minecraft.nbt.CompoundTag
Expand Down Expand Up @@ -53,13 +50,6 @@ class RejoinedReplayPlayer private constructor(
place(rejoined, RejoinGamePacketListener(rejoined, connection, cookies), player) {
recorder.shouldHidePlayerFromTabList(it)
}

for (plugin in ServerReplayPluginManager.plugins) {
when (recorder) {
is PlayerRecorder -> plugin.onPlayerReplayStart(recorder)
is ChunkRecorder -> plugin.onChunkReplayStart(recorder)
}
}
}

fun place(
Expand Down

0 comments on commit 69b827f

Please sign in to comment.