Skip to content

Developer API

DSH105 edited this page Aug 2, 2013 · 10 revisions

Access The API

The EchoPet Developer API can be accessed used the following method.

import com.github.dsh105.echopet.EchoPet
import com.github.dsh105.echopet.api.EchoPetAPI

public EchoPetAPI getEchoPetAPI() {
    Plugin plugin = this.getServer().getPluginManager().getPlugin("EchoPet");
    if (plugin == null || !(plugin instanceof EchoPet)) {
        return null;
    }

    return ((EchoPet) plugin).getAPI();
}

Using The API

The EchoPet Developer API allows developers access to a wide range of utilities that can be used to control Pets initiated using the plugin. It also allows control over the Pet AI System and Target Selection.

List Of Methods

Method Name Description/Function
givePet(Player.class, PetType.class, Boolean.class) Gives a Pet to the specified player. If the third parameter is true, the player will also be notified of their new Pet.
removePet(Player.class, Boolean.class Removes any Pet a player has.
hasPet(Player.class) Checks whether a Player has a Pet. Returns a boolean value depending on the result.
getPet(Player.class) Gets a Player's Pet. Will return null if the Player does not have a Pet.
getAllPets() Returns an Array of all active Pets.
teleportPet(Pet.class, Location.class) Teleport's a Pet to a certain Location. The Pet's owner can be retrieved using pet.getOwner()
addData(Pet.class, PetData.class) Applies/adds the specified data to a Pet.
removeData(Pet.class, PetData.class) Removes/deactivates a data option for a Pet.
hasData(Pet.class, PetData.class) Checks whether a Pet has a data option enabled.
setAttackTarget(Pet.class, LivingEntity.class) Sets a Pet's target to the specified LivingEntity. Note that if the Attack Goal has not been added to the Pet's AI, this will not work.
getAttackTarget(Pet.class) Gets the current Attack Target of a Pet. Will return null if the Pet does not have an Attack Target.
addGoal(Pet.class, GoalType.class) Adds a predefined Goal to a Pet's AI. Usage example: addGoal(petInstance, GoalType.ATTACK);
addGoal(Pet.class, PetGoal.class, String.class) Adds an extension of PetGoal.class to a Pet's AI. A tutorial on this can be found below.
removeGoal(Pet.class, GoalType.class) Removes a predefined Goal from a Pet's AI. Usage example: removeGoal(petInstance, GoalType.ATTACK);
removeGoal(Pet.class, String.class) Removes a Goal from a Pet's AI by it's Identifier
removeGoal(Pet.class, PetGoal.class) Removes a Goal instance from a Pet's AI

Referenced Classes:

  • Player.class: Player object from the Bukkit API
  • PetType.class: API Enumeration, representing all available Pet Types (com.github.dsh105.echopet.data.PetData)
  • Pet.class: Represents a Pet object (com.github.dsh105.echopet.entity.pet.Pet)
  • Location.class: Location object from the Bukkit API
  • PetData.class: API Enumeration of all valid Data options for all Pets. Note that only some data types may be applied to certain Pets. Use pet.getPetType() (com.github.dsh105.echopet.data.PetType) to check Entity Types
  • LivingEntity.class: Represents a Living Entity (org.bukkit.entity.LivingEntity)
  • GoalType.class: API Enumeration of already included Goals to add to a Pet's AI
  • PetGoal.class: API Super class representing all PetGoals. A tutorial for extending this can be found below.

Custom Events

|Event Name|Function| |:--------:| |PetAttackEvent|Called when a Pet attempts to damage a target. Cancelling this event will not cancel the animation, only the damage dealt.| |PetDamageEvent|Called when a Pet is damaged.| |PetInteractEvent|Called when a Player interacts (right or left click) with a Pet.| |PetMenuOpenEvent|Called when a Pet's Owner opens the PetMenu for their Pet.| |PetMoveEvent|Called when a Pet moves while following it's Owner or riding.| |PetRideJumpEvent|Called when a Player attempts to jump while riding their Pet.| |PetRideMoveEvent|Called when a Player moves while riding their Pet.| |PetSpawnEvent|Called when a Pet spawns.| |PetTeleportEvent|Called when a Pet teleports.|

Extending PetGoal

TODO

Live Chat

Got something to share? Or just want to talk with the creators of EchoPet? Come join us in IRC - #techcable @ irc.spi.gt

Clone this wiki locally