ItemDataLib
A simple Spigot library to store metadata in ItemStack (1.8+). Supports 1.14's PersistentDataContainer !
Description
ItemDataLib is a Spigot (Java) library which store metadata in ItemStack. Data is persistent even after the server restart.
How it works
ItemDataLib uses two differents ways to store metadata. The better way will be chosen by the library itself depending of the server version.
Add to project
This library can be added to your buildpath locally using your IDE (Eclipse: Java Build Path β Depedencies, IntelliJ IDEA: Project Structure β Librairies)
You can also use Maven or Gradle to add this library.
Jitpack will be used in these examples.
Maven:
- Repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
- Dependency:
<dependency>
<groupId>com.github.Iltotore</groupId>
<artifactId>ItemDataLib</artifactId>
<version>Tag</version>
</dependency>
Gradle:
- Repository
repositories {
...
maven { url 'https://jitpack.io' }
}
- Dependency
dependencies {
implementation 'com.github.Iltotore:ItemDataLib:Tag'
}
Usage
Step 1: Create a new instance of CustomMetaFactory
The CustomMetaFactory's constructor require a JavaPlugin. This is an example in a JavaPlugin's method.
public void onEnable(){
customMetaFactory = new CustomMetaFactory(this);
}
Step 2: Create a new CustomItemMeta
You need to create a CustomItemMeta to edit/read ItemStack's metadata. To create a new CustomItemMeta, use the method CustomMetaFactory#createCustomMeta(ItemMeta) where the parameter is the ItemMeta to edit.
ItemStack item = new ItemStack(Material.STONE);
ItemMeta meta = item.getItemMeta();
CustomItemMeta customMeta = customMetaFactory.createCustomMeta(meta);
Step 3: Usage of CustomItemMeta
Supported data: primitives, String, UUID
- Reading To read metadata of a CustomItemMeta, call these methods:
Type | Method |
---|---|
Primitives | get{PrimitiveName}(String) |
String | getString(String) |
UUID | getUniqueId(String) |
- Editing To Edit CustomItemMeta's metadata, use these methods:
Type | Method |
---|---|
Primitives | set{PrimitiveName}(String) |
String | setString(String) |
UUID | setUniqueId(String) |
Note: Don't forget to use CustomItemMeta#updateMeta to apply changes ! You can reset changes by using CustomItemMeta#updateMap