Skip to content
BigTallahasee edited this page Oct 26, 2021 · 3 revisions

Setting your own working copy of the project

Ensure you have a working version of the JDK (Java Development Kit).

The following steps are for the Eclipse development environment, but will be similar on other IDEs.

  • Fork the repository by clicking on the Fork icon on the top right of the page. You can also simply clone or download it by going to the main page.
  • In Eclipse, go to File -> Import... -> Maven -> Existing Maven Projects.
  • In the Root Directory field, select the location where you downloaded the Pet Master repository.
  • Tick the pom.xml box that appears in the Projects field and click Finish.
  • To compile the plugin, in the Package Explorer window, right click on the imported project, then Run As -> Maven Install.
  • The plugin will be generated in the target folder of the project.

Listening to change ownership events

The following functionality is only available since Pet Master version 1.3 (November 2016).

In your own plugin project, you might want to be notified when a player changes the ownership of a pet (/petm setowner and /petm free commands). That's simple!

  • If you have a Maven project, add the following to your pom.xml:
<repository>
    <id>MCShared-mvn-repo</id>
    <url>https://raw.github.com/PyvesB/MCShared/mvn-repo/</url>
</repository>
<dependency>
    <groupId>com.hm.mcshared</groupId>
    <artifactId>MCShared</artifactId>
    <version>????</version>
    <scope>provided</scope>
</dependency>

Replace ???? with the latest version of the library, which you can find here. For instance 1.0.4.

  • Alternatively, download the latest version of Pet Master from Bukkit or Spigot and add the file to the build path of your project.
  • Add a new class similar to the following in your project:
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.hm.mcshared.event.PlayerChangeAnimalOwnershipEvent;
...

public class PlayerChangeAnimalOwnershipListener implements Listener {

	...

	@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
	public void onPlayerChangeAnimalOwnership(PlayerChangeAnimalOwnershipEvent event) {
		...
	}
}
  • Make sure you add some code to verify that Pet Master is running, and register the listener to your plugin. For instance in your main plugin class:
...
if (Bukkit.getPluginManager().isPluginEnabled("PetMaster")) {
    getServer().getPluginManager().registerEvents(new PlayerChangeAnimalOwnershipListener(), this);
}
...
  • Beware, a call to the getNewOwner of PlayerChangeAnimalOwnershipEvent can return null if a player uses the /free pet command!
  • Add Pet Master as a dependency or soft-dependency in your plugin.yml:
# Make Pet Master compulsory:
depend: [PetMaster]
# Or make Pet Master optional:
softdepend: [PetMaster]
  • Congratulations, your listener code will be run each time a player changes the ownership of a pet!