Skip to content
EricLangezaal edited this page Jun 18, 2021 · 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. I highly advise you to build against the special sources-jar, as that allows you to use the JavaDoc. 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.4.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]

Loading the JavaDoc

As stated above, please make sure you build against the sources-jar, which has a built-in JavaDoc. To load JavaDocs in Intellij IDEA, right-click on your pom.xml -> Maven -> Download Sources and Documentation. In Eclipse you have to click on your project folder -> Maven -> Download JavaDoc.

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, make sure to look at the JavaDoc (explained in the section above). If you have any question, you can always ask them here or on Spigot.

Clone this wiki locally