-
Notifications
You must be signed in to change notification settings - Fork 0
Items
NR-Core contains a few useful Utils for serializing items and getting the Item Registry.
Ever want to make your item into a base64 string and take away all its ability to be cool? Now you can with NR-Core!
There are two simple methods you can call.
SeralizeItem.java
public void tortureItem() throws IOException {
ItemStack item = new ItemStack(Material.STICK);
String stringifiedItem = ItemSerializer.toBase64(item);
ItemStack wow = ItemSerializer.fromBase64(stringifiedItem);
}Super simple, you can use either method and store the itemstack how you want to!
Note: #toBase64(); may throw IOException
This is a an advanced feature for super-duper-cool developers who need to use the Bukkit Item Registry, look at this
What would any spigot library be without its own overly complex itembuilder !? Luckily, NR-Core's ItemBuilder is straight forward and to the point.
myCoolItem.java
public void myCoolItem() {
ItemStack item = ItemBuilder.of(Material.STICK, 5, "PowerStick", "&cEating this will kill you!").build();
}Wow! That's alot to unpack, Lets start alittle simpler, ItemBuilder can take loads of arguments, instead look at this!
myCoolItem.java
public void myCoolItem() {
ItemStack item = ItemBuilder.of(Material.STICK).build();
ItemStack item = ItemBuilder.of(Material.STICK, 1).build();
ItemStack item = ItemBuilder.of(Material.STICK, 1, "Stick Loard").build();
ItemStack item = ItemBuilder.of(Material.STICK, 1, "Stick Loard", "Lore Lore Lore!!").build();
}As you can see, ItemBuilder has lots of initalization methods,
Just like any function, you cans tring them all together, e.g. ItemBuilder.of(Material.STICK).amont(10).glow(true).build();
amount() Set the amount of the ItemStack.
modelData() Set the modeldata of the ItemStack.
name() Set the name of the ItemStack.
lore() Set the lore of the ItemStack.
enchant() Set the enchant and level of said enchant of the ItemStack.
flag() set the flags of the ItemStack.
glow() Make the ItemStack glow.
unbreakable() Set if the ItemStack can break or not.
durability() Set the durability of an ItemStack.
build() Convert ItemBuilder to ItemStack.
Leather Armor has never been easy with spigot, but now with NR-Core, making colored leather is easy as pie! (not that making a pie is easy)
Same general methods as ItemBuilder but with one exception!
coolLeatherClass.java
public void doTheDo(){
ItemStack leatherHelmet = ItemBuilder.of(LeatherType.LEATHER_HELMET, 1, "My helmet!").setColor(Color.BLUE).build();
}Super easy! Don't sweat it. Feel free to look at the source code of this util.
Now this is unique to NR-Core! Potions are now a peace of cake with this builder. We use the same constructors as ItemBuilder or LeatherBuilder, But this time we have PotionType (as seen in LeatherBuilder)
We have two more methods for Potions, setPotionData() and setColor()
More information on PotionData can be found here
setColor() Is easy! It takes the Color from bukkit or RGB!
And that's it for the Item Utils! Enjoy :)