Developer API

The Developer API for vHunger v1.2.4 is still being fleshed out and will receive new features as updates progress. This page attempts to detail what you can do with vHunger as an import.

Retrieving Access

It is possible to retrieve access to a variety of classes and methods.

Accessing vHunger itself

Your plugin needs to gain access to the whole vHunger plugin. In your main class, add the following:

import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import com.valygard.vhunger.Hunger;

public class ExampleClass extends JavaPlugin
{
	public Hunger getHungerPlugin() {
		Plugin plugin = getServer().getPluginManager().getPlugin("Hunger");

		//If vHunger is not loaded
		if (plugin == null || !(plugin instanceof Hunger)) {
			return null; // Or you could use setEnabled(false), or throw an exception.
		}

		return (Hunger) plugin;
	}
}

Now, anywhere you want to get the main class and all it's contents, you can use getHungerPlugin();

Accessing the HungerUtils

The HungerUtils class provides access to a variety of methods used in events and commands. Using the previous code, you can get the utils with the following method:

public HungerUtils getUtils() {
	return getHungerPlugin().getUtils();
}

Now, if you wanted to go further, such as add a configurable potion effect to a player in the same setup used in vHunger, you could do the following:

public void givePotionEffect(Player p, PotionEffectType effectType) {
	getUtils().addEffect(p, effectType);
}

Events

vHunger has two custom events. Both are called when the food level of a player changes, but one scales the hunger depletion while the other adds potion effects.

Calling events

The HungerChangeEvent constructor requires the Hunger class and a player. To call it, you might do something like this:

public void callHungerChange(Player player) {
	getServer().getPluginManager().callEvent(new HungerChangeEvent(getHungerPlugin(), player));
}

To call the ScaleHungerEvent, which requires the same parameters, you could do something similar:

public void callScaledHunger(Player player) {
	getServer().getPluginManager().callEvent(new ScaleHungerEvent(getHungerPlugin(), player));
}

This page is a stub. It will be expanded at a later point in time.
You can download vHunger v1.2.4 here.