Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.github.pylonmc.pylon.core.recipe.RecipeType
import io.github.pylonmc.pylon.core.registry.PylonRegistry
import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureConfig
import io.github.pylonmc.pylon.core.resourcepack.armor.ArmorTextureEngine
import io.github.pylonmc.pylon.core.util.mergeGlobalConfig
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -157,6 +158,7 @@ object PylonCore : JavaPlugin(), PylonAddon {
launch {
delay(1.ticks)
loadRecipes()
loadResearches()
}

val end = System.currentTimeMillis()
Expand Down Expand Up @@ -194,6 +196,39 @@ object PylonCore : JavaPlugin(), PylonAddon {
logger.info("Loaded recipes in ${(end - start) / 1000.0}s")
}

private fun loadResearches() {
logger.info("Loading researches...")
val start = System.currentTimeMillis()

for (addon in PylonRegistry.ADDONS) {
val corePath = this.javaPlugin.dataFolder
.resolve("researches")
.resolve(addon.key.namespace + ".yml")

mergeGlobalConfig(addon, "researches.yml", corePath.toString())
}

val researchDir = dataPath.resolve("researches")
if (researchDir.exists()) {
for (namespaceDir in researchDir.listDirectoryEntries()) {
val namespace = namespaceDir.nameWithoutExtension

if (!namespaceDir.isRegularFile()) continue

val mainResearchConfig = Config(namespaceDir)
for (key in mainResearchConfig.keys) {
val nsKey = NamespacedKey(namespace, key)
val section = mainResearchConfig.getSection(key) ?: continue

Research.loadFromConfig(section, nsKey).register()
}
}
}

val end = System.currentTimeMillis()
logger.info("Loaded researches in ${(end - start) / 1000.0}s")
}

override fun onDisable() {
PacketEvents.getAPI().terminate()
ConnectingService.cleanup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package io.github.pylonmc.pylon.core.item.research
import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.ticks
import io.github.pylonmc.pylon.core.PylonCore
import io.github.pylonmc.pylon.core.config.ConfigSection
import io.github.pylonmc.pylon.core.config.PylonConfig
import io.github.pylonmc.pylon.core.config.adapter.ConfigAdapter
import io.github.pylonmc.pylon.core.datatypes.PylonSerializers
import io.github.pylonmc.pylon.core.event.PrePylonCraftEvent
import io.github.pylonmc.pylon.core.i18n.PylonArgument
Expand Down Expand Up @@ -297,6 +299,25 @@ data class Research(
}
}
}


@JvmStatic
fun loadFromConfig(section: ConfigSection, key : NamespacedKey) : Research {

try {
val material = section.getOrThrow("material", ConfigAdapter.MATERIAL)
val name = section.get("name", ConfigAdapter.STRING) ?: "pylon.${key.namespace}.research.${key.key}"
val cost = section.get("cost", ConfigAdapter.LONG)
val unlocks = section.get("unlocks", ConfigAdapter.SET.from(ConfigAdapter.NAMESPACED_KEY)) ?: emptySet()

return Research(key, material, Component.translatable(name), cost, unlocks)
} catch (e: Exception) {
throw IllegalArgumentException(
"Failed to load research '$key' from config",
e
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import net.kyori.adventure.text.TranslatableComponent
import net.kyori.adventure.text.TranslationArgumentLike
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
import net.kyori.adventure.translation.GlobalTranslator
import org.bukkit.NamespacedKey
import org.bukkit.block.Block
import org.bukkit.block.BlockFace
Expand All @@ -33,7 +32,6 @@ import org.joml.Vector3f
import org.joml.Vector3i
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodHandles
import java.util.Locale
import kotlin.math.absoluteValue
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
Expand Down