🔨 update and adjust nbtapi methods

Took 9 minutes
This commit is contained in:
Kiran Hart 2023-09-29 13:08:00 -04:00
parent f19604d507
commit 176da26b2e
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
2 changed files with 12 additions and 8 deletions

View File

@ -458,7 +458,7 @@ public class AuctionAPI {
}
public String getHeadTexture(final ItemStack item) {
final String textureBase64 = NBT.get(item, nbt -> nbt.getCompound("SkullOwner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value"));
final String textureBase64 = NBT.get(item, nbt -> (String) nbt.getCompound("SkullOwner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value"));
final String textureJson = new String(Base64.getDecoder().decode(textureBase64));
final JsonObject object = JsonParser.parseString(textureJson).getAsJsonObject();
@ -612,7 +612,7 @@ public class AuctionAPI {
}
public boolean isRepaired(final ItemStack item) {
return NBT.get(item, nbt -> nbt.hasTag("AuctionHouseRepaired"));
return NBT.get(item, nbt -> (boolean) nbt.hasTag("AuctionHouseRepaired"));
}
public double calculateListingFee(double basePrice) {
@ -790,7 +790,7 @@ public class AuctionAPI {
// Check NBT tags
for (String nbtTag : Settings.BLOCKED_NBT_TAGS.getStringList()) {
if (NBT.get(itemStack, nbt -> nbt.hasTag(nbtTag))) {
if (NBT.get(itemStack, nbt -> (boolean) nbt.hasTag(nbtTag))) {
AuctionHouse.getInstance().getLocale().getMessage("general.blockednbttag").processPlaceholder("nbttag", nbtTag).sendPrefixedMessage(player);
return false;
}

View File

@ -21,6 +21,7 @@ package ca.tweetzy.auctionhouse.helpers;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.flight.nbtapi.NBT;
import ca.tweetzy.flight.nbtapi.iface.ReadableItemNBT;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import org.bukkit.inventory.ItemStack;
@ -28,30 +29,33 @@ import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
@UtilityClass
public final class BundleUtil {
public boolean isBundledItem(@NonNull final ItemStack itemStack) {
return itemStack.getType() != XMaterial.AIR.parseMaterial() && NBT.get(itemStack, nbt -> nbt.hasTag("AuctionBundleItem"));
final boolean hasBundleTag = NBT.get(itemStack, nbt -> (boolean) nbt.hasTag("AuctionBundleItem"));
return itemStack.getType() != XMaterial.AIR.parseMaterial() && hasBundleTag;
}
public List<ItemStack> extractBundleItems(@NonNull final ItemStack itemStack) {
final List<ItemStack> items = new ArrayList<>();
final int totalBundledItems = NBT.get(itemStack, nbt -> nbt.getInteger("AuctionBundleItem"));
final int totalBundledItems = NBT.get(itemStack, nbt -> (int) nbt.getInteger("AuctionBundleItem"));
for (int i = 0; i < totalBundledItems; i++) {
int finalI = i;
if (NBT.get(itemStack, nbt -> nbt.hasTag("AuctionBundleItem-" + finalI)))
items.add(AuctionAPI.getInstance().deserializeItem(NBT.get(itemStack, nbt -> nbt.getByteArray("AuctionBundleItem-" + finalI))));
if (NBT.get(itemStack, (Function<ReadableItemNBT, Boolean>) nbt -> nbt.hasTag("AuctionBundleItem-" + finalI)))
items.add(AuctionAPI.getInstance().deserializeItem(NBT.get(itemStack, nbt -> (byte[]) nbt.getByteArray("AuctionBundleItem-" + finalI))));
}
if (!items.isEmpty())
return items;
final ItemStack[] bundledItems = NBT.get(itemStack, nbt -> nbt.getItemStackArray("AuctionBundleItems"));
final ItemStack[] bundledItems = NBT.get(itemStack, nbt -> (ItemStack[]) nbt.getItemStackArray("AuctionBundleItems"));
return new ArrayList<>(Arrays.asList(bundledItems));
}
}