-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Note
If you would like to use experimental builds of craftsnet, you nee to add our experimental repository too. (https://repo.craftsblock.de/#/experimental)
It is important to note that you first need CraftsNet and also the CraftsCore. The three ... in the snippets symbolise other repositories or dependencies that you may have included.
We also support not only gradle and maven, but also a variety of other providers, which you can view on our repo server. (CraftsNet & CraftsCore)
repositories {
...
maven { url "https://repo.craftsblock.de/releases" }
mavenCentral()
}
dependencies {
...
implementation "de.craftsblock:craftsnet:VERSION"
implementation "de.craftsblock:craftscore:VERSION"
}<repositories>
...
<repository>
<id>craftsblock-releases</id>
<name>CraftsBlock Repositories</name>
<url>https://repo.craftsblock.de/releases</url>
</repository>
</repositories>
<dependencies>
...
<dependency>
<groupId>de.craftsblock</groupId>
<artifactId>craftsnet</artifactId>
<version>VERSION</version>
</dependency>
<dependency>
<groupId>de.craftsblock</groupId>
<artifactId>craftscore</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>CraftsNet can be initialized in three different ways.
Note
As of CraftsNet v3.3.5 the addon class is optional. If your addon class is empty you can instead use a hollow addon. To use a hollow addon simple do not specify the main class in the addon.json.
First of all you need to create a new class which extends from Addon. This class will be used as base class for starting your system.
import de.craftsblock.craftsnet.addon.Addon;
public class MyAddon extends Addon {
@Override
public void onEnable() {
}
}After that you'll need to create a addon.json, which is located in your resources folder. (This file must be located in the root of the comiled jar) The advanced schema for the addon.json can be found here: https://github.com/CraftsBlock/CraftsNet/wiki/addon.json
{
"name": "MyCoolAddon",
"main": "MyAddon"
}CraftsNet can also be started via the CraftsNetBuilder. The builder for CraftsNet can be obtained via CraftsNet#create().
import de.craftsblock.craftsnet.CraftsNet;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
CraftsNet craftsNet = CraftsNet.create().build();
}
}If you want to test your addon in your ide without the need of setting up a CraftsNet instance you can use the AddonContainingBuilder. For this you'll need to specify the @Meta annotation on your addon class.
Note
Do not disable the addon system via the withAddonSystem option as this also disables the specified addons.
import de.craftsblock.craftsnet.CraftsNet;
import de.craftsblock.craftsnet.addon.Addon;
import de.craftsblock.craftsnet.addon.meta.annotations.Meta;
import java.io.IOException;
@Meta(name = "MyCoolAddon")
public class MyAddon extends Addon {
public static void main(String[] args) throws IOException {
CraftsNet.create(MyAddon.class).build();
}
@Override
public void onEnable() {
logger().info("Started from AddonContainingBuilder");
}
}If you need to load an addon which do not specifies the @Meta annotaion you can set it manually via the builder.
CraftsNet.create(MyAddon.class)
.map(MyAddon.class, "MyCoolAddon")
.build();