Creating an Adapter
Introduction
Typewriter is a dynamic platform that supports the development of adapters, which are modular components enhancing the overall functionality. Adapters are self-contained, easily shareable, and integrate smoothly into the TypeWriter system. They allow you to create custom entries and have them show up in the web panel. This guide is tailored to guide you through the process of creating an adapter, suitable for both beginners and experienced developers.
Prerequisites
- Java Development Kit (JDK) 21 or higher.
- An Integrated Development Environment (IDE) such as IntelliJ IDEA or Eclipse.
- A basic understanding of Gradle and the Spigot API.
Step 1: Setting Up a Gradle Project
Begin by establishing a Gradle project for your Typewriter adapter. Below is a comprehensive setup for your build.gradle.kts
:
plugins {
kotlin("jvm") version "2.0.0"
id("io.github.goooler.shadow") version "8.1.7"
}
// Replace with your own information
group = "me.yourusername"
version = "0.0.1"
repositories {
// Typewriter required repositories
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.codemc.io/repository/maven-releases/")
maven("https://repo.opencollab.dev/maven-snapshots/")
maven("https://jitpack.io")
// Add other necessary repositories
}
dependencies {
compileOnly("com.github.gabber235:typewriter:main-SNAPSHOT") // Latest release version
// Add other dependencies as needed
}
tasks.withType<ShadowJar> {
exclude("kotlin/**")
exclude("META-INF/maven/**")
// Important: Use the relocated commandapi which is shadowed by the plugin
relocate("dev.jorel.commandapi", "com.github.gabber235.typewriter.extensions.commandapi") {
include("dev.jorel.commandapi.**")
}
}
kotlin {
jvmToolchain(21)
}
Ensure to replace placeholders like me.yourusername
with your project details.
Choosing the TypeWriter Version
Select the appropriate TypeWriter dependency version: For stable and tested features, use the latest release version:
compileOnly("com.github.gabber235:typewriter:main-SNAPSHOT")
This is suitable for most development needs and is recommended for general adapter creation.
If you need the latest features and improvements (which might be unstable), use the latest development version:
compileOnly("com.github.gabber235:typewriter:develop-SNAPSHOT")
Note that this version may include changes that are not yet fully tested or documented.
If you need a specific version, visit the JitPack page and select the version you need.
Step 2: Creating an Adapter Class
After setting up your project, create an adapter class. Here's an example:
import me.gabber235.typewriter.adapters.Adapter
import me.gabber235.typewriter.adapters.TypewriterAdapter
@Adapter("Example", "An example adapter for documentation purposes", "0.0.1")
object ExampleAdapter : TypewriterAdapter() {
override fun initialize() {
// Do something when the adapter is initialized
}
override fun shutdown() {
// Do something when the adapter is shutdown
}
}
Step 3: Building the Adapter
After creating the adapter class, build the adapter. This can be done by running the shadowJar
Gradle task.
This will generate a JAR file in the build/libs
directory.
This JAR file can be used as an adapter in TypeWriter.
Place the JAR file in the plugins/TypeWriter/adapters
directory and restart the server.
Typewriter will automatically load the adapter and run it.
If any problems occur, check the console for errors and ensure that the adapter is properly configured. If you need help, join the Discord server and ask for help.
What's Next?
After creating an adapter, you can start adding features to it. Check out the Creating Entries guide to learn how to add entries to your adapter.