Skip to content

Commit

Permalink
Merge pull request #17 from MineInAbyss/develop
Browse files Browse the repository at this point in the history
Move startup to onLoad
  • Loading branch information
0ffz authored Nov 2, 2023
2 parents d7d1295 + a09df38 commit 2a14260
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mineinabyss.geary.papermc.bridge

import com.mineinabyss.geary.addons.GearyPhase
import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.papermc.bridge.actions.ExplosionSystem
Expand All @@ -18,12 +19,6 @@ import com.mineinabyss.idofront.plugin.listeners
class PaperBridge {
companion object : GearyAddonWithDefault<PaperBridge> {
override fun PaperBridge.install() {
gearyPaper.plugin.listeners(
DeathBridge(),
ItemActionsBridge(),
MobActionsBridge(),
)

geary.pipeline.addSystems(
CooldownDisplaySystem(),
ApplyAttribute(),
Expand All @@ -39,6 +34,14 @@ class PaperBridge {
TimeConditionChecker(),
ExplosionSystem(),
)

geary.pipeline.runOnOrAfter(GearyPhase.ENABLE) {
gearyPaper.plugin.listeners(
DeathBridge(),
ItemActionsBridge(),
MobActionsBridge(),
)
}
}

override fun default() = PaperBridge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mineinabyss.geary.papermc.plugin

import com.mineinabyss.geary.addons.GearyPhase.ENABLE
import com.mineinabyss.geary.autoscan.autoscan
import com.mineinabyss.geary.modules.ArchetypeEngineModule
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.papermc.GearyPaperConfigModule
import com.mineinabyss.geary.papermc.GearyPlugin
Expand All @@ -16,25 +17,28 @@ import com.mineinabyss.geary.papermc.tracking.entities.gearyMobs
import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull
import com.mineinabyss.geary.papermc.tracking.items.ItemTracking
import com.mineinabyss.geary.papermc.tracking.items.gearyItems
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.prefabs
import com.mineinabyss.geary.serialization.dsl.FileSystemAddon
import com.mineinabyss.geary.serialization.dsl.serialization
import com.mineinabyss.geary.uuid.UUIDTracking
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.messaging.logSuccess
import com.mineinabyss.idofront.plugin.listeners
import com.mineinabyss.idofront.serialization.SerializablePrefabItemService
import com.mineinabyss.serialization.formats.YamlFormat
import okio.FileSystem
import okio.Path.Companion.toOkioPath
import org.bukkit.entity.Player
import org.bukkit.event.Listener
import org.bukkit.inventory.ItemStack
import kotlin.io.path.isDirectory
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.name


class GearyPluginImpl : GearyPlugin() {
override fun onEnable() {
override fun onLoad() {
// Register DI
val configModule = GearyProductionPaperConfigModule(this)

Expand Down Expand Up @@ -94,10 +98,23 @@ class GearyPluginImpl : GearyPlugin() {
}
}


DI.add<SerializablePrefabItemService>(
object : SerializablePrefabItemService {
override fun encodeFromPrefab(item: ItemStack, prefabName: String) {
val result = gearyItems.createItem(PrefabKey.of(prefabName), item)
require(result != null) { "Failed to create serializable ItemStack from $prefabName, does the prefab exist and have a geary:set.item component?" }
}
})

// Register commands
GearyCommands()
}

override fun onEnable() {
ArchetypeEngineModule.start(DI.get<PaperEngineModule>())
}

override fun onDisable() {
server.worlds.forEach { world ->
world.entities.forEach entities@{ entity ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package com.mineinabyss.geary.papermc.plugin

import co.touchlab.kermit.Logger
import co.touchlab.kermit.StaticConfig
import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.geary.engine.archetypes.ArchetypeEngine
import com.mineinabyss.geary.modules.ArchetypeEngineModule
import com.mineinabyss.geary.modules.GearyModuleProvider
import com.mineinabyss.geary.papermc.GearyPlugin
import com.mineinabyss.geary.papermc.gearyPaper
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.time.ticks
import kotlinx.coroutines.delay

class PaperEngineModule(val plugin: GearyPlugin) :
ArchetypeEngineModule(tickDuration = 1.ticks) {
Expand All @@ -18,10 +17,7 @@ class PaperEngineModule(val plugin: GearyPlugin) :

companion object: GearyModuleProvider<PaperEngineModule> {
override fun start(module: PaperEngineModule) {
module.plugin.launch {
delay(1.ticks) // Waits until first tick has complete (all plugins loaded)
ArchetypeEngineModule.start(module)
}
DI.add<PaperEngineModule>(module)
}

override fun init(module: PaperEngineModule) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mineinabyss.geary.papermc.tracking.entities

import com.mineinabyss.geary.addons.GearyPhase
import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault
import com.mineinabyss.geary.datatypes.ComponentId
import com.mineinabyss.geary.helpers.componentId
Expand All @@ -26,13 +27,15 @@ interface EntityTracking {
}

override fun EntityTracking.install() {
gearyPaper.plugin.listeners(EntityWorldEventTracker())
geary.pipeline.addSystems(
TrackOnSetBukkitComponent(),
UntrackOnRemoveBukkitComponent(),
AttemptSpawnListener(),
AttemptSpawnMythicMob()
)
geary.pipeline.runOnOrAfter(GearyPhase.ENABLE) {
gearyPaper.plugin.listeners(EntityWorldEventTracker())
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mineinabyss.geary.papermc.tracking.items

import com.mineinabyss.geary.addons.GearyPhase
import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault
import com.mineinabyss.geary.datatypes.GearyEntity
import com.mineinabyss.geary.modules.geary
Expand Down Expand Up @@ -36,16 +37,19 @@ interface ItemTracking {
override fun default(): ItemTracking = NMSBackedItemTracking()

override fun ItemTracking.install() {
gearyPaper.plugin.listeners(
loginListener,
SetItemIgnoredPropertyListener(),
MythicMobDropSystem()
)
geary.pipeline.addSystems(
InventoryTrackerSystem(),
CustomModelDataToPrefabTracker(),
SetItemMigrationSystem()
)

geary.pipeline.runOnOrAfter(GearyPhase.ENABLE) {
gearyPaper.plugin.listeners(
loginListener,
SetItemIgnoredPropertyListener(),
MythicMobDropSystem()
)
}
}
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kotlin.code.style=official
group=com.mineinabyss
version=0.26
idofrontVersion=0.20.1
version=0.27
idofrontVersion=0.20.6
gearyVersion=0.23-SNAPSHOT

0 comments on commit 2a14260

Please sign in to comment.