Developer API - jojodmo/CustomItems GitHub Wiki
If you don't have Custom Items, you can still include the Custom Items API in your plugin! Just use this placeholder jar:
https://github.com/jojodmo/CustomItems/blob/master/API/CustomItemsAPI_PLACEHOLDER.jar Note that this is non-functional, but when a server with Custom Items installed uses your plugin, the API will work as intended!
ItemBridge
If you just want to parse a String into an ItemStack, check out ItemBridge! It's super simple to add to your plugin, and lets you parse strings into Minecraft items, CustomItem items, and items from other plugins, with ease!
Block Storage Format
If you're interested in the way CustomItems stores blocks, see CustomItems region storage format
API Documentation
There's a lot of methods available in the API! You can view the source code of the API here to see a full list of available methods, and documentation on each:
https://github.com/jojodmo/CustomItems/blob/master/API/CustomItemsAPI.java
Using the API
One way you can check if the server has Custom Items installed by using
boolean hasCUI = Bukkit.getPluginManager().getPlugin("CustomItems") != null;
The API can be accessed using the class
com.jojodmo.customitems.api.CustomItemsAPI
Each method has JavaDocs attached, so you can read the documentation by looking at those. There's a bunch of other methods you can find by reading the JavaDocs, but here are four important ones:
String
s to ItemStack
s
Parsing ItemStack getCustomItem(String id)
Returns the ItemStack that is represented by the Custom Item with the ID id
, or null
if it doesn't exist. This also handles the plugin's prefix for item IDs, so you could easily add this to your plugin, and allow players to use item IDs like "cui:myCustomItem".
You can easily add two lines of code to your method of parsing ItemStack
s from String
s to allow players to use Custom Item IDs like "cui:myCustomItem" in your plugin!
String input = "cui:myCustomItem";
ItemStack matched = matchItemStack(input);
public ItemStack matchItemStack(String input){
ItemStack is = CustomItemsAPI.getCustomItem(input); // line one to add
if(is != null){return is;} // line two to add
//your other ItemStack matching code, like
return new ItemStack(Material.matchMaterial(input));
}
ItemStack
's Custom Item ID
Finding an String getCustomItemID(ItemStack stack)
This will return the Custom Item ID of the ItemStack
stack, or null
if the stack is not a Custom Item.
So, if you wanted to get either the CustomItem ID of an item or the Minecraft material of an item, you could do something like this
public String getItemStackType(ItemStack stack){
if(stack == null){return null;} // fix null-pointer exceptions incase this code is copied and pasted :)
String customItemID = CustomItemsAPI.getCustomItemID(stack);
if(stack != null){return "cui:" + customItemID;} // prefix CustomItem IDs with "cui:"
return "minecraft:" + stack.getType().name(); // prefix Minecraft items with "minecraft:"
}
Getting the CustomItem ID of a block
String getCustomItemIDAtBlock(Block block)
This will get the ID of the CustomItem at the given block, and will return null
if the block is not from CustomItems
Setting a CustomItems block at a location
Block setCustomItemIDAtBlock(Block block, String id, boolean doBlockUpdate)
Returns the Block that has been updated, or null
if the CustomItem id you provided doesn't exist. If you provide null
for id, this will remove whatever block is at that location (whether or not it's a CustomItems block), and will always return the block