Skip to content

Commit

Permalink
Switched from NbtItem to Nbt.modify (#853)
Browse files Browse the repository at this point in the history
* Switched from NbtItem to Nbt.modify

see Iridium-Development/IridiumCore#99

* refactored (ty boiscljo)

* added parentheses
  • Loading branch information
sh0inx authored May 19, 2024
1 parent 4120244 commit d0771b1
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.iridium.iridiumskyblock.managers;

import com.iridium.iridiumcore.dependencies.nbtapi.NBT;
import com.iridium.iridiumcore.dependencies.nbtapi.NBTCompound;
import com.iridium.iridiumcore.dependencies.nbtapi.NBTFile;
import com.iridium.iridiumcore.dependencies.nbtapi.NBTItem;
import com.iridium.iridiumcore.dependencies.paperlib.PaperLib;
import com.iridium.iridiumcore.dependencies.xseries.XMaterial;
import com.iridium.iridiumcore.dependencies.xseries.XBiome;
Expand Down Expand Up @@ -690,19 +690,23 @@ public ItemStack getIslandCrystal(int amount) {
ItemStack itemStack = ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getConfiguration().islandCrystal, Collections.singletonList(
new Placeholder("amount", String.valueOf(amount))
));
NBTItem nbtItem = new NBTItem(itemStack);
NBTCompound nbtCompound = nbtItem.getOrCreateCompound("iridiumskyblock");
nbtCompound.setInteger("islandCrystals", amount);
return nbtItem.getItem();

NBT.modify(itemStack, readWriteItemNBT -> {
readWriteItemNBT.getOrCreateCompound("iridiumskyblock").setInteger("islandCrystals", amount);
});

return itemStack;
}

public int getIslandCrystals(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) return 0;
NBTCompound nbtCompound = new NBTItem(itemStack).getOrCreateCompound("iridiumskyblock");
if (nbtCompound.hasKey("islandCrystals")) {
return nbtCompound.getInteger("islandCrystals");
}
return 0;

return NBT.get(itemStack, readableItemNBT -> {
if(readableItemNBT.getCompound("iridiumskyblock").hasTag("islandCrystals")) {
return readableItemNBT.getCompound("iridiumskyblock").getInteger("islandCrystals");
}
return 0;
});
}

public List<User> getMembersOnIsland(Island island) {
Expand Down

0 comments on commit d0771b1

Please sign in to comment.