Getting Started
On this page: How to import and prepare your project
Adding KTools as dependency
- Maven
- Gradle
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io/</url>
</repository>
<dependency>
<groupId>com.github.KPGTB</groupId>
<artifactId>KTools</artifactId>
<version>{VERSION}</version>
<scope>provided</scope>
</dependency>
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.KPGTB:KTools:{VERSION}'
}
note
Remember to replace {VERSION}
to version of KTools that you want to use!
You also need to add KTools as dependency in your plugin.yml
plugin.yml
depend: [KTools]
Preparing plugin
After adding KTools as dependency, you can start cooding. First of all, you need to get ToolsObjectWrapper
. To make it, in onEnable()
crete new instance of ToolsInitializer
. With that, you can create new instance of ToolsObjectWrapper
.
public final class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
ToolsInitializer initializer = new ToolsInitializer(this);
ToolsObjectWrapper wrapper = new ToolsObjectWrapper(initializer);
}
}
Initializer creates also BukkitAudiences from AdventureAPI, so you need to handle it.
public final class MyPlugin extends JavaPlugin {
private BukkitAudiences adventure;
@Override
public void onEnable() {
ToolsInitializer initializer = new ToolsInitializer(this);
this.adventure = initializer.getAdventure();
ToolsObjectWrapper wrapper = new ToolsObjectWrapper(initializer);
}
@Override
public void onDisable() {
if (adventure != null) adventure.close();
}
}
tip
- Info
- ExampleWrapper.class
- MyPlugin.class
ToolsObjectWrapper
is an object that will be accessed via constructors in commands, listeners, items etc. You can extend it like you want.
public class ExampleWrapper extends ToolsObjectWrapper {
private final String exampleField;
public ExampleWrapper(ToolsInitializer initializer, String exampleField) {
super(initializer);
this.exampleField = exampleField;
}
public String getExampleField() {
return exampleField;
}
}
public final class MyPlugin extends JavaPlugin {
private BukkitAudiences adventure;
@Override
public void onEnable() {
ToolsInitializer initializer = new ToolsInitializer(this);
this.adventure = initializer.getAdventure();
ExampleWrapper wrapper = new ExampleWrapper(initializer, "some text");
}
@Override
public void onDisable() {
if (adventure != null) adventure.close();
}
}