UtilityAPI icon

UtilityAPI -----

Make your life easier and faster.



UtilityAPI is in a very early stage of development and many features are still to come. If you wand a specific feature let me know and I'll see if I can implement it :)

Current Features:

Crafting
  • Add crafting recipes faster and get more control over them
Code (Text):
// The Material[] has to have 9 entries. They translate to the 9 slots in a crafting table (left to right)
// There is an overload for this method which takes in all 9 Material items instead of an array
// Material.AIR means the slot in the crafting table will have to be empty
Material[] ingredients = {Material.AIR, Material.COAL, Material.AIR,
                    Material.COAL, Material.COAL_BLOCK, Material.COAL,
                    Material.AIR, Material.COAL, Material.AIR};
CraftRecipe recipe = new CraftRecipe(new ItemStack(Material.DIAMOND), ingredients, "DiamondRecipe", this);
recipe.addRecipe();

  • Add smithing recipes easier and with more control
Code (Text):
        SmithRecipe recipe = new SmithRecipe(new ItemStack(Material.NETHERITE_PICKAXE), Material.IRON_PICKAXE, Material.DIAMOND, "DiamondPick", this);
        recipe.setResult(new ItemStack(Material.DIAMOND_PICKAXE));
        recipe.addRecipe();


Cooldowns
  • Easy to use cooldowns
Code (Text):
// First create a cooldown
// Give it a time and TimeScale (Minutes or Seconds)
Cooldown cooldown = new Cooldown(10, TimeScale.SECONDS);
           
   
// Add a player to a cooldown
cooldown.addPlayerToCooldown(player);
   
// Remove a player from a cooldown
cooldown.removePlayerFromCooldown(player);
   
// Check if player is on cooldown
// Returns true/ false
cooldown.isOnCooldown(player);
   
// Get remaining time
// Returns an integer
cooldown.getRemainingCooldown(player);    // This will always return in the unit that was given when the cooldown was created
cooldown.getRemainingCooldown(player, TimeScale.MINUTES);    // This will return in the given unit


Item and ItemBuilder
  • Item works like ItemStacks but applies the ItemMeta for you.
Code (Text):
Item item = new Item(Material.GOLDEN_SWORD);
item.addEnchant(Enchantment.FIRE_ASPECT, 1, true);
item.setName(ChatColor.RED + "Fire Sword");
item.addFlags(ItemFlag.HIDE_ENCHANTS);
item.setUnbreakable(true);
           
player.getInventory().addItem(item.getItemStack());

  • ItemBuilder allows you to create ItemStacks in just one line of code. It's perfect for just small Items you need to quickly create or test around with.
Code (Text):
ItemStack stack = new ItemBuilder(Material.DIAMOND_SWORD).setDisplayName(ChatColor.BLUE + "Ice Sword").addEnchant(Enchantment.KNOCKBACK, 3).addFlags(ItemFlag.HIDE_ENCHANTS).addToLore(ChatColor.WHITE + "Freezes Players").getItemStack();


Inventory
  • Remove a certain amount of items from an inventory or player.
Code (Text):
utilityAPI.inventory.removeItem(player, Material.STICK, 10);
  • Check if a player inventory contains certain items.
Code (Text):
if(utilityAPI.inventory.containsItems(player, Material.STICK, 10)) {
    player.sendMessage(ChatColor.GREEN + "You own at least 10 sticks!");
}


Usage

To use UtilityAPI you have to do 3 things:

  1. Include the UtilityAPI.jar in your project and put it in your plugins folder
  2. Add a depend to your plugin.yml:
    Code (Text):
    depend: [UtilityAPI]
  3. Put this line of code in your main class:
    Code (Text):
    public static UtilityAPI utilityAPI = (UtilityAPI) Bukkit.getServer().getPluginManager().getPlugin("UtilityAPI");

Now you can access the UtilityAPI's methods!

If you want to create crafting recipes or smithing recipes follow the code examples given in the Crafting category.

If you want to use the inventory methods follow the examples given in the Inventory category.


There is no documentation yet but I'm working on it.

This is my first API so if you have any tips or hints on how to make it better feel free to post them :)

If you need any help you can join myDiscord:
https://discord.gg/AkAdFf8NjB
Resource Information
Author:
----------
Total Downloads: 248
First Release: Feb 23, 2022
Last Update: Feb 26, 2022
Category: ---------------
All-Time Rating:
0 ratings
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings