Giter Club home page Giter Club logo

kotlinloader's Introduction

KotlinLoader


Kotlin PluginLoader for Spigot.

KotlinLoader

Kotlin is a wonderful growing programming language with support for the JVM. This allows us to write Minecraft Plugins in Kotlin. While this works fine, it does bring some inconveniences. To run kotlin, it is mandatory for the kotlin library files to be available at runtime. While it is possible to provide these classes with the -classpath option, when starting the JVM, most spigot servers run in managed environments. The go-to workaround for this problem is to add these library files to the final jar by shading them. This will increase your jar size a lot.

KotlinLoader provides a custom PluginLoader, that will provide the Kotlin library classes for you.\

Included Kotlin Libraries

  • kotlin-stdlib
  • kotlin-stdlib-jdk8
  • kotlin-stdlib-jdk7
  • kotlinx-coroutines
  • kotlin-reflect

Pros

  • Write Idiomatic Kotlin!
  • The main class can be an object singleton, instead of a normal class.
  • Decrease size of the final plugin jar.

Cons

  • This plugin uses a lot of reflection and injection hacks to allows Kotlin classes to be accessed by JavaPlugins
  • Plugins extending KotlinPlugin should be located in the <server_root>/plugins/kotlin folder.

Roadmap

  • Add support for .kts configuration
  • Add support for annotation based plugin descriptions
  • Add BungeeCord support

Usage

In the spigot server

Build or download the plugin and place it into your plugins folder like any other plugin. Note that plugins running with this pluginloader should go into the <server_root>/plugins/kotlin folder!

When writing a plugin

The KotlinLoader offers two ways to write a plugin.

A regelar KotlinPlugin should be written as any other Spigot Plugin. The main class should extend KotlinPlugin. It is possible to use object for the main class.

Events

The current Bukkit Event system does not fit within idiomatic Kotlin. The mandatory HandlerList forces you to write ugly companion objects which a @JvmStatic annotation. The KotlinLoader Plugin provides an event generation system which write this boilerplate for you!

Normal Events

Events using this generator feature should either extend dev.steyn.kotlinloader.api.event.Event as superclass or have the dev.steyn.kotlinloader.api.event.GenHandlers annotation. The latter one was introduced for applying the generator feature for Events which require a different superclass. Instantiation of the class dev.steyn.kotlinloader.api.event.Event is illegal outside of use of superclass. Please use the normal Bukkit event class.

Cancellable

The bukkit system for cancellable events also forces you to write alot of boilerplate. KotlinLoader introduces a default implementation which can be used through delegation.

class ServerFooEvent : Event() 

@GenHandlers
class PlayerFooEvent(who: Player) : PlayerEvent(who)

class CancellablePlayerFooEvent(who: Player) : PlayerEvent(who), Cancellable by Cancellable.default()

Compiling

KotlinLoader is a maven project. Use mvn package to build to project.

Dependency Information

Maven

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.steenooo</groupId>
    <artifactId>kotlin-loader</artifactId>
    <version>1.2.2</version>
    <scope>provided</scope>
</dependency>

Gradle

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
  
dependencies {
	        implementation 'com.github.steenooo:kotlin-loader:1.2.2'
	}

This project was inspired by ScalaLoader

kotlinloader's People

Contributors

steenooo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.