API

FoodBalance_Logo

API

FoodBalanceAPI for VERSION 2.0

I made a little API so other developers can interact easier with the food-system of FoodBalance. This could be handy if you'd like to reset all values or add certain food-points by using a command, eating custom foods etc. To use the API, include the latest jar to your java project and access the functions below using the FoodBalanceAPI class. Make sure you have put FoodBalance in your plugin.yml dependencies!

/**
 * The main class to use will be the ValueManager.
 * Use this to acces the ValueManager.
 */
ValueManager vm = FoodBalanceAPI.getValueManager();

/**
 * Resets the whole balance of a player.
 * All normal categories will go back to 0
 * and the hydration will be reset to 900.
 */
vm.resetValues(Player player);

/**
 * Mutates a food-category.
 * FoodType (enum): [CARBOHYDRATE, VITAMIN,
 * PROTEIN, WATER] 
 */
vm.setValue(FoodType type, Player player, int value);

/**
 * Get the current value of a food-category.
 */
vm.getValue(FoodType type, Player player);

/**
 * 'Easy'-mutate of all categories. All parameters are mutations.
 */
FoodBalanceAPI.eat(Player player, int carbohydrates, int proteins, int vitamins, int water);

For example you'd made a plugin which allows you to make carrot-cake (carbohydrates=2, vitamins=2) you could interact with FoodBalance like so:

@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
    //Your special code.
    FoodBalanceAPI.eat(e.getPlayer(), 2, 0, 2, 0);
}

-SugarCaney


Comments

Posts Quoted:
Reply
Clear All Quotes