Skip to content
EricLangezaal edited this page Feb 15, 2022 · 15 revisions

Hook into PetDragon using the developer API

This step-by-step tutorial explains how you can make your plugin hook into PetDragon.

Import with Maven

In order to build against PetDragon, you have to add it as a local dependency. To do so, you have to build against the jar as released on Spigot. Either add this jar to your local Maven repository or use a system dependency to link to the file itself. For both, use the following (along with a systemPath for the second option):

<dependencies>
   <dependency>
       <groupId>com.ericdebouwer</groupId>
       <artifactId>PetDragon</artifactId>
       <version>1.5.2</version> <!-- replace with the latest version -->
   </dependency>
</dependencies>

Set PetDragon as (soft)depend

Add "PetDragon" as a (soft)depend in your plugin.yml. See the snippet below for an example. If you set it as a softdepend, don't forget to actually check if the plugin is present before accessing the API.

name: ExamplePlugin
version: 1.0
main: your.main.path.here
depend: [PetDragon]

Using the API

Once everything is setup, you can start using the API. All available methods can be found under the PetDragonAPI class. You can for example spawn a PetDragon for a player, in quite a similar fashion to how you spawn entities in the Spigot API. In the example below I spawn a dragon, and rename it to "Hello World" before it is spawned in.

Player player = ...
EnderDragon dragon = PetDragonAPI.getInstance().spawnDragon(player.getLocation(), player.getUniqueId(), (dragon) -> {
            dragon.setCustomName("Hello World");
            dragon.setCustomNameVisible(true);
        });

If you want to know how to use a method, you can look at the source code hosted here. If you have any question, you can always ask them here or on Spigot.