-
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 turn 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.
SerializeItem.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 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 a lot to unpack, Let's start a little 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 initialization methods,
Just like any function, you can string 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.
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!
Everyone's favorite, yet sometimes stupidly hard to do. NR-Core's SkullBuilder is super easy to use.
skullyorscully.java
public void doTheDo(Player p){
ItemStack skull = SkullBuilder.of(1, "Someone's Skull").setHeadTexture(p).build();
}And just like that you are able to create a skull of the given player's head! setHeadTexture(); takes a player, offlineplayer, uuid, or texture string if you're crazZzy.
And that's it for the ItemUtils! Enjoy :)