Skip to content

Link to the GDK

The first thing you want to do when creating your own game mode, is to register a UHCGameModule on the GDK registry. To do so, you must first declare a class implementing the UHCGameModule interface :

MyUHC.kt
import fr.noradrenalin.gdk.module.UHCGameModule
class MyUHC : UHCGameModule() {
override fun name(): String = "My incredible UHC"
override fun description(): String = "MyUHC is the best UHC you'll ever get to play !"
}

Once you’ve created your own UHCGameModule, you now need to register it when enabling your own plugin :

MyMain.kt
import fr.noradrenalin.gdk.GDKMain
import fr.noradrenalin.myuhc.game.MyUHC
import org.bukkit.plugin.java.JavaPlugin
class MyMain : JavaPlugin() {
// ...
override fun onEnable() {
super.onEnable()
val optionalGDK = GDKMain.getInstance()
if (optionalGDK.isPresent) {
optionalGDK.get().gdkGamesRegistry.registerModule(MyUHC())
} else {
throw NoSuchElementException("Couldn't find GDK plugin instance on the server, please install the UHCGDK plugin first !")
}
}
// ...
}

In this example, you can see we try to access the GDK main instance. If this instance exists, then we register our MyUHC game module in the GDK game registry, otherwise, we throw an error saying what went wrong and how to fix it (for better understanding from non-developers).

Once you’ve done so, you can compile and test your plugin. When starting your server, this should appear in the server console :

Server console
...
[UHCGDK] [My incredible UHC] registered as a UHC game module
...

If you see this output, your game mode is now detectable and detected by the GDK !