From e881f3b56b904c16a488579380d5dceae828c1b2 Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Wed, 1 Jan 2020 12:19:48 -0800 Subject: Update 1.0.1 --- .../kotlinforforge/AutoKotlinEventBusSubscriber.kt | 1 - .../thedarkcolour/kotlinforforge/KotlinForForge.kt | 6 +-- .../kotlinforforge/KotlinLanguageProvider.kt | 6 +-- .../kotlinforforge/KotlinModContainer.kt | 43 ++++++++++------------ .../kotlin/thedarkcolour/kotlinforforge/Logger.kt | 5 +++ src/main/resources/META-INF/mods.toml | 2 +- 6 files changed, 30 insertions(+), 33 deletions(-) create mode 100644 src/main/kotlin/thedarkcolour/kotlinforforge/Logger.kt (limited to 'src/main') diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt index 9f81c93..eae9ef5 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt @@ -8,7 +8,6 @@ import net.minecraftforge.fml.loading.FMLEnvironment import net.minecraftforge.fml.loading.moddiscovery.ModAnnotation import net.minecraftforge.forgespi.language.ModFileScanData import org.objectweb.asm.Type -import thedarkcolour.kotlinforforge.KotlinForForge.logger import thedarkcolour.kotlinforforge.forge.FORGE_BUS import thedarkcolour.kotlinforforge.forge.MOD_BUS import java.util.* diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt index f6139bc..aef44e5 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinForForge.kt @@ -1,13 +1,9 @@ package thedarkcolour.kotlinforforge import net.minecraftforge.fml.common.Mod -import org.apache.logging.log4j.LogManager -import org.apache.logging.log4j.Logger /** * Set 'modLoader' in mods.toml to "kotlinforforge" and loaderVersion to "[1,)". */ @Mod("kotlinforforge") -object KotlinForForge { - internal val logger: Logger = LogManager.getLogger() -} \ No newline at end of file +object KotlinForForge \ No newline at end of file diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt index 7d68f7e..a98fda7 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinLanguageProvider.kt @@ -15,7 +15,7 @@ class KotlinLanguageProvider : FMLJavaModLanguageProvider() { return Consumer { scanResult -> val target = scanResult.annotations.stream() .filter { data -> data.annotationType == MODANNOTATION } - .peek { data -> KotlinForForge.logger.debug(Logging.SCAN, "Found @Mod class ${data.classType.className} with id ${data.annotationData["value"]}") } + .peek { data -> logger.debug(Logging.SCAN, "Found @Mod class ${data.classType.className} with id ${data.annotationData["value"]}") } .map { data -> KotlinModTarget(data.classType.className, data.annotationData["value"] as String) } .collect(Collectors.toMap({ target: KotlinModTarget -> target.modId }, { it }, { a, _ -> a })) scanResult.addLanguageLoader(target) @@ -29,8 +29,8 @@ class KotlinLanguageProvider : FMLJavaModLanguageProvider() { class KotlinModTarget constructor(private val className: String, val modId: String) : IModLanguageProvider.IModLanguageLoader { override fun loadMod(info: IModInfo, modClassLoader: ClassLoader, modFileScanResults: ModFileScanData): T { val ktContainer = Class.forName("thedarkcolour.kotlinforforge.KotlinModContainer", true, Thread.currentThread().contextClassLoader) - KotlinForForge.logger.debug(Logging.LOADING, "Loading KotlinModContainer from classloader ${Thread.currentThread().contextClassLoader} - got ${ktContainer.classLoader}}") - val constructor = ktContainer.getConstructor(IModInfo::class.java, String::class.java, ClassLoader::class.java, ModFileScanData::class.java)!! + logger.debug(Logging.LOADING, "Loading KotlinModContainer from classloader ${Thread.currentThread().contextClassLoader} - got ${ktContainer.classLoader}}") + val constructor = ktContainer.declaredConstructors[0]//(IModInfo::class.java, String::class.java, ClassLoader::class.java, ModFileScanData::class.java)!! return constructor.newInstance(info, className, modClassLoader, modFileScanResults) as T } } diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt index 3446a7a..7c8101d 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/KotlinModContainer.kt @@ -18,8 +18,8 @@ import java.util.function.Supplier * * */ -class KotlinModContainer(info: IModInfo, className: String, loader: ClassLoader, private val scanData: ModFileScanData) : ModContainer(info) { - private val modClass: Class<*> +class KotlinModContainer(private val info: IModInfo, private val className: String, private val loader: ClassLoader, private val scanData: ModFileScanData) : ModContainer(info) { + //private val modClass: Class<*> /** Use a separate logger because KotlinForForge.logger isn't initialized yet */ private val logger = LogManager.getLogger() private lateinit var modInstance: Any @@ -27,32 +27,22 @@ class KotlinModContainer(info: IModInfo, className: String, loader: ClassLoader, init { logger.debug(Logging.LOADING, "Creating KotlinModContainer instance for {} with classLoader {} & {}", className, loader, javaClass.classLoader) - triggerMap[ModLoadingStage.CONSTRUCT] = dummy().andThen(::beforeEvent).andThen(::constructMod).andThen(::afterEvent) - triggerMap[ModLoadingStage.CREATE_REGISTRIES] = dummy().andThen(::beforeEvent).andThen(::fireEvent).andThen(::afterEvent) - triggerMap[ModLoadingStage.LOAD_REGISTRIES] = dummy().andThen(::beforeEvent).andThen(::fireEvent).andThen(::afterEvent) - triggerMap[ModLoadingStage.COMMON_SETUP] = dummy().andThen(::beforeEvent).andThen(::preInitMod).andThen(::fireEvent).andThen(::afterEvent) - triggerMap[ModLoadingStage.SIDED_SETUP] = dummy().andThen(::beforeEvent).andThen(::fireEvent).andThen (::afterEvent) - triggerMap[ModLoadingStage.ENQUEUE_IMC] = dummy().andThen(::beforeEvent).andThen(::initMod).andThen(::fireEvent).andThen(::afterEvent) - triggerMap[ModLoadingStage.PROCESS_IMC] = dummy().andThen(::beforeEvent).andThen(::fireEvent).andThen(::afterEvent) - triggerMap[ModLoadingStage.COMPLETE] = dummy().andThen(::beforeEvent).andThen(::completeLoading).andThen(::fireEvent).andThen(::afterEvent) - triggerMap[ModLoadingStage.GATHERDATA] = dummy().andThen(::beforeEvent).andThen(::fireEvent).andThen(::afterEvent) + triggerMap[ModLoadingStage.CONSTRUCT] = dummy().andThen(::constructMod).andThen(::afterEvent) + triggerMap[ModLoadingStage.CREATE_REGISTRIES] = dummy().andThen(::fireEvent).andThen(::afterEvent) + triggerMap[ModLoadingStage.LOAD_REGISTRIES] = dummy().andThen(::fireEvent).andThen(::afterEvent) + triggerMap[ModLoadingStage.COMMON_SETUP] = dummy().andThen(::fireEvent).andThen(::afterEvent) + triggerMap[ModLoadingStage.SIDED_SETUP] = dummy().andThen(::fireEvent).andThen (::afterEvent) + triggerMap[ModLoadingStage.ENQUEUE_IMC] = dummy().andThen(::fireEvent).andThen(::afterEvent) + triggerMap[ModLoadingStage.PROCESS_IMC] = dummy().andThen(::fireEvent).andThen(::afterEvent) + triggerMap[ModLoadingStage.COMPLETE] = dummy().andThen(::fireEvent).andThen(::afterEvent) + triggerMap[ModLoadingStage.GATHERDATA] = dummy().andThen(::fireEvent).andThen(::afterEvent) eventBus = BusBuilder.builder().setExceptionHandler(::onEventFailed).setTrackPhases(false).build() configHandler = Optional.of(Consumer { event -> eventBus.post(event) }) val ctx = KotlinModLoadingContext(this) contextExtension = Supplier { ctx } - try { - modClass = Class.forName(className, true, loader) - logger.debug(Logging.LOADING, "Loaded kotlin modclass ${modClass.name} with ${modClass.classLoader}") - } catch (e: Throwable) { - logger.error(Logging.LOADING, "Failed to load kotlin class $className", e) - throw ModLoadingException(info, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmodclass", e) - } } - private fun completeLoading(lifecycleEvent: LifecycleEventProvider.LifecycleEvent) {} - private fun initMod(lifecycleEvent: LifecycleEventProvider.LifecycleEvent) {} private fun dummy(): Consumer = Consumer {} - private fun beforeEvent(lifecycleEvent: LifecycleEventProvider.LifecycleEvent) {} private fun onEventFailed(iEventBus: IEventBus, event: Event, iEventListeners: Array, i: Int, throwable: Throwable) { logger.error(EventBusErrorMessage(event, i, iEventListeners, throwable)) @@ -78,9 +68,16 @@ class KotlinModContainer(info: IModInfo, className: String, loader: ClassLoader, } } - private fun preInitMod(lifecycleEvent: LifecycleEventProvider.LifecycleEvent) {} - private fun constructMod(lifecycleEvent: LifecycleEventProvider.LifecycleEvent) { + val modClass: Class<*> + try { + modClass = Class.forName(className, true, loader) + logger.debug(Logging.LOADING, "Loaded kotlin modclass ${modClass.name} with ${modClass.classLoader}") + } catch (e: Throwable) { + logger.error(Logging.LOADING, "Failed to load kotlin class $className", e) + throw ModLoadingException(info, ModLoadingStage.CONSTRUCT, "fml.modloading.failedtoloadmodclass", e) + } + try { logger.debug(Logging.LOADING, "Loading mod instance ${getModId()} of type ${modClass.name}") modInstance = modClass.kotlin.objectInstance ?: modClass.newInstance() diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/Logger.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/Logger.kt new file mode 100644 index 0000000..8500863 --- /dev/null +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/Logger.kt @@ -0,0 +1,5 @@ +package thedarkcolour.kotlinforforge + +import org.apache.logging.log4j.LogManager + +internal val logger = LogManager.getLogger() \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 0aa5be1..7f4e0be 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -33,6 +33,6 @@ Kotlin for Forge. Allows mods to use the Kotlin programming language. [[mods]] #mandatory displayName="Kotlin for Forge" # Name of mod modId="kotlinforforge" # Modid -version="1.0.0" # Version of kotlinforforge +version="1.0.1" # Version of kotlinforforge authors="TheDarkColour" # Author credits="Herobrine knows all." # Credits \ No newline at end of file -- cgit