API

MobHealth's API

This page describes how to use MobHealth's API in your own plugins. Advanced coders please bear with me ;)

How to Include MobHealth

Firstly you'll need to Hook onto Mob Health.
After adding MobHealth as an external jar (just like you did with the craftbukkit jar) you can use this code to check for MobHealth.

In the main class declarations:

public static Boolean hasMobHealth;

in your onEnable():

this.hasMobHealth = this.getServer().getPluginManager().isPluginEnabled("MobHealth");

Now you can check {YourMainClassname}.hasMobHealth to see if MobHealth is enabled.

Using the API

The API has 3 methods you can call. showNotification, getMobHealth and getMobMaxHealth.

Before any API calls you'll need a reference to MobHealthAPI.

if (MainClass.hasMobHealth  ) {
	MobHealth pMobHealth = (MobHealth) plugin.getServer().getPluginManager().getPlugin("MobHealth");
	MobHealthAPI mobHealthAPI = pMobHealth.getAPI(pMobHealth);
}

getMobHealth

Just hand it the LivingEntity you want to know about ;)

int health = mobHealthAPI.getMobHealth(targetEntity);

getMobMaxHealth

Again, just hand it the LivingEntity you want to know about ;)

int maxHealth = mobHealthAPI.getMobMaxHealth(targetEntity);

sendNotification

This ones more complicated ;)

You can call it as a normal damage event, or as a Skill or Spell event.

For damage use this syntax.

mobHealthAPI.showNotification(player, damageOutput, mobtype, mobsHealth, mobsMaxHealth, damagerMob);

Where the values are as follow.

  • Player player: Who to show the notification to.
  • String damageOutput: Damage amount to show - e.g. "5", "5 (+1)" ,"2 (-1)"
  • String mobtype: Name of the Mob
  • String mobsHealth: Health of the Mob.
  • String mobsMaxHealth: Mobs Maximum Health
  • Entity damagerMob: The entity that caused the damage. If a projectile or tameable entity then an appropriate icon will be used for the icon.
    Otherwise (or if null) then the icon will be whatever is held by the player specified in the first argument.

For skills/spells use this syntax.

mobHealthAPI.showNotification(player, damageOutput, mobtype, mobsHealth, mobsMaxHealth, skillName);

Values are the same as for damage - 'cept that the String skillName is used instead of the damagerMob and echoed as appropriate in the notification.


Comments

Posts Quoted:
Reply
Clear All Quotes