diff options
author | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-12-10 16:45:39 -0800 |
---|---|---|
committer | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-12-10 16:45:39 -0800 |
commit | 4390d994bbee18ef5ed77f2f5429e3079af84b40 (patch) | |
tree | 49ce5c61b37e8d1431fbc6b28f4072524a17cbdd | |
parent | 60b4afc3c7755b5682584a89c0c91dc6e8478926 (diff) | |
download | KotlinForForge-4390d994bbee18ef5ed77f2f5429e3079af84b40.tar.gz KotlinForForge-4390d994bbee18ef5ed77f2f5429e3079af84b40.tar.bz2 KotlinForForge-4390d994bbee18ef5ed77f2f5429e3079af84b40.zip |
adding files
3 files changed, 97 insertions, 19 deletions
diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt index 46cdc4d..0189ea7 100644 --- a/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber.kt @@ -17,11 +17,12 @@ import java.util.stream.Collectors * Handles [net.minecraftforge.fml.common.Mod.EventBusSubscriber] */ @Suppress("unused") -internal object AutoKotlinEventBusSubscriber { - private val EVENT_BUS_SUBSCRIBER: Type = Type.getType(Mod.EventBusSubscriber::class.java) +object AutoKotlinEventBusSubscriber { + @PublishedApi + internal val EVENT_BUS_SUBSCRIBER: Type = Type.getType(Mod.EventBusSubscriber::class.java) /** - * Registers Kotlin objects that are annotated with [Mod.EventBusSubscriber] + * Registers Kotlin objects and companion objects that are annotated with [Mod.EventBusSubscriber] * This allows you to declare an object that subscribes to the event bus * without making all the [net.minecraftforge.eventbus.api.SubscribeEvent] annotated with [JvmStatic] * @@ -31,22 +32,7 @@ internal object AutoKotlinEventBusSubscriber { * public object ExampleSubscriber { * @SubscribeEvent * public fun onItemRegistry(event: RegistryEvent.Register<Item>) { - * println("Look! We're in items :)") - * } - * } - * - * This also works with companion objects. - * You must define the [net.minecraftforge.eventbus.api.SubscribeEvent] methods inside the companion object. - * Example Usage: - * - * public class ExampleSubscriberClass { - * - * @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) - * companion object ExampleSubscriberCompanion { - * @SubscribeEvent - * public fun onItemRegistry(event: RegistryEvent.Register<Item>) { - * println("Look! We're in items :)") - * } + * println("Look! We're in items!") * } * } */ diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/forge/EventBus.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/EventBus.kt new file mode 100644 index 0000000..8fb2552 --- /dev/null +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/forge/EventBus.kt @@ -0,0 +1,16 @@ +package thedarkcolour.kotlinforforge.forge + +import net.minecraftforge.common.MinecraftForge +import net.minecraftforge.eventbus.api.IEventBus + +/** + * The forge event bus. + * Many events that occur during the game are fired on this bus. + * + * Examples: + * @see net.minecraftforge.event.entity.player.PlayerEvent + * @see net.minecraftforge.event.entity.living.LivingEvent + * @see net.minecraftforge.event.world.BlockEvent + */ +val FORGE_BUS: IEventBus + inline get() = MinecraftForge.EVENT_BUS
\ No newline at end of file diff --git a/src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt b/src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt new file mode 100644 index 0000000..29150f0 --- /dev/null +++ b/src/main/kotlin/thedarkcolour/kotlinforforge/webgenerator/WebGenerator.kt @@ -0,0 +1,76 @@ +@file:JvmName("WebGenerator") + +package thedarkcolour.kotlinforforge.webgenerator + +import org.apache.commons.io.FileUtils +import org.jsoup.Jsoup +import org.jsoup.nodes.Attribute +import org.jsoup.nodes.Attributes +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import org.jsoup.parser.Tag +import java.io.File +import java.nio.charset.Charset + +fun main() = run() + +fun run() { + // val v = Files.newDirectoryStream(File("C:\\Things\\mods\\thedarkcolour.kotlinforforge\\thedarkcolour\\thedarkcolour.kotlinforforge").toPath()) + // val mavenMetadata = File("C:\\Things\\mods\\thedarkcolour.kotlinforforge\\thedarkcolour\\thedarkcolour.kotlinforforge\\maven-metadata.xml") + + //val webHtml = Jsoup.parse(File("..\\KotlinForForge\\thedarkcolour\\thedarkcolour.kotlinforforge\\web.html"), null).childNodes()[0] + //webHtml.childNodes()[2].childNodes()[5].childNodes().filterIsInstance<Element>().forEach(::println) + + val thedarkcolour = File("C:\\Things\\mods\\KotlinForForge\\thedarkcolour") + + val web = File("C:\\Things\\mods\\KotlinForForge\\thedarkcolour\\web.html") + val webHtml = Jsoup.parse(web, "UTF-8") + + for (file in thedarkcolour.listFiles()!!) { + if (file.isDirectory) { + val pre = webHtml.getElementsByAttributeValue("href", "../index.html") + .parents() + .first() + val attr = Attributes().put(Attribute("href", file.absolutePath.replace("${thedarkcolour.absolutePath}\\", "") + "/web.html")) + + if (pre.getElementsByAttributeValue("href", attr.get("href")).isEmpty()) { + pre.appendChild(Element(Tag.valueOf("a"), webHtml.baseUri(), attr)) + + val innerWeb = File("${file.absolutePath}\\web.html") + innerWeb.createNewFile() + } + //webHtml.allElements.find { + // it.tagName() == "body" + //}!!.allElements.find { + // it.tagName() == "pre" + //}!!.allElements.find { + // print(it.attr("href")) + // it.className() == "" + //}//.appendChild((Element(Tag.valueOf("a"), "hi"))) + } + } + + FileUtils.writeStringToFile(web, webHtml.outerHtml(), Charset.defaultCharset()) + + /* + <body> + <h1>Index of /thedarkcolour.kotlinforforge/</h1> + <hr> + <pre><a href="../web.html">../</a> + <a href="1.0.0/web.html">1.0.0</a> + <a href="maven-metadata.xml">maven-metadata.xml</a> + <a href="maven-metadata.xml.md5">maven-metadata.xml.md5</a> + <a href="maven-metadata.xml.sha1">maven-metadata.xml.sha1</a> + </pre> + <hr> + </body> + */ +} + +fun getPre(doc: Document): Element { + return doc.getElementsByAttributeValue("href", "../web.html") + .parents() + .first() ?: doc.getElementsByAttributeValue("href", "../index.html") + .parents() + .first() +}
\ No newline at end of file |