Replace deprecated NBTItem calls

This commit is contained in:
Christian Koop 2022-03-18 20:35:14 +01:00
parent a4a7ae7f22
commit 6189d5b921
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
11 changed files with 110 additions and 115 deletions

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.listeners.item;
import com.songoda.core.nms.nbt.NBTCompound;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.utils.single.RomanNumber;
@ -17,7 +17,7 @@ public class BlackScrollListener extends ItemListener {
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.has("black-scroll") || !cursor.getNBTObject("black-scroll").asBoolean()) {
if (!cursor.hasKey("black-scroll") || !cursor.getBoolean("black-scroll")) {
return;
}
@ -31,11 +31,11 @@ public class BlackScrollListener extends ItemListener {
}
String id = getRandomElement(compound.getKeys());
int level = compound.getInt(id);
int level = compound.getInteger(id);
Enchant enchant = instance.getEnchantManager().getValueUnsafe(id);
ItemStack toSet = instance.getEnchantUtils().removeEnchant(event.getCurrentItem(), enchant);
event.getWhoClicked().getInventory().addItem(enchant.getBook().get(enchant, level, cursor.getInt("success-rate"), 100));
event.getWhoClicked().getInventory().addItem(enchant.getBook().get(enchant, level, cursor.getInteger("success-rate"), 100));
event.setCurrentItem(toSet);
instance.getLocale().getMessage("blackscroll.success")

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.listeners.item;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EnchantResult;
import com.songoda.epicenchants.events.EnchantApplyEvent;
@ -30,16 +30,16 @@ public class BookListener extends ItemListener {
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.has("book-item") || !cursor.getNBTObject("book-item").asBoolean()) {
if (!cursor.hasKey("book-item") || !cursor.getBoolean("book-item")) {
return;
}
event.setCancelled(true);
ItemStack toApply = event.getCurrentItem();
Enchant enchant = instance.getEnchantManager().getValue(cursor.getNBTObject("enchant").asString()).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
Enchant enchant = instance.getEnchantManager().getValue(cursor.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(current.finish()))) {
if (!enchant.getItemWhitelist().contains(CompatibleMaterial.getMaterial(current.getItem()))) {
return;
}
// get total amount of enchantments on item
@ -53,9 +53,9 @@ public class BookListener extends ItemListener {
return;
}
int level = cursor.getNBTObject("level").asInt();
int successRate = cursor.getNBTObject("success-rate").asInt();
int destroyRate = cursor.getNBTObject("destroy-rate").asInt();
int level = cursor.getInteger("level");
int successRate = cursor.getInteger("success-rate");
int destroyRate = cursor.getInteger("destroy-rate");
EnchantApplyEvent enchantEvent = new EnchantApplyEvent(toApply, enchant, level, successRate, destroyRate);
Bukkit.getPluginManager().callEvent(enchantEvent);
@ -83,7 +83,7 @@ public class BookListener extends ItemListener {
@Override
void onClick(PlayerInteractEvent event, NBTItem clicked) {
if (!clicked.has("mystery-book") || !clicked.getNBTObject("mystery-book").asBoolean()) {
if (!clicked.hasKey("mystery-book") || !clicked.getBoolean("mystery-book")) {
return;
}
@ -93,7 +93,7 @@ public class BookListener extends ItemListener {
return;
}
Group group = instance.getGroupManager().getValue(clicked.getNBTObject("group").asString()).orElseThrow(() -> new IllegalStateException("Book without group!"));
Group group = instance.getGroupManager().getValue(clicked.getString("group")).orElseThrow(() -> new IllegalStateException("Book without group!"));
Optional<Enchant> enchant = instance.getEnchantManager().getRandomEnchant(group);

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.listeners.item;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
@ -16,28 +16,28 @@ public class DustListener extends ItemListener {
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.has("dust") || !cursor.getNBTObject("dust").asBoolean()) {
if (!cursor.hasKey("dust") || !cursor.getBoolean("dust")) {
return;
}
if (!current.has("book-item") || !current.getNBTObject("book-item").asBoolean()) {
if (!current.hasKey("book-item") || !current.getBoolean("book-item")) {
return;
}
Enchant enchant = instance.getEnchantManager().getValue(current.getNBTObject("enchant").asString()).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
Enchant enchant = instance.getEnchantManager().getValue(current.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
if (!enchant.getGroup().equals(instance.getGroupManager().getValue(cursor.getNBTObject("group").asString()).orElseThrow(() -> new IllegalStateException("Dust without group!")))) {
if (!enchant.getGroup().equals(instance.getGroupManager().getValue(cursor.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!")))) {
return;
}
int successRate = current.getNBTObject("success-rate").asInt();
int successRate = current.getInteger("success-rate");
if (successRate == 100) {
return;
}
successRate = Math.min(successRate + cursor.getNBTObject("percentage").asInt(), 100);
event.setCurrentItem(enchant.getBook().get(enchant, current.getNBTObject("level").asInt(), successRate, current.getNBTObject("destroy-rate").asInt()));
successRate = Math.min(successRate + cursor.getInteger("percentage"), 100);
event.setCurrentItem(enchant.getBook().get(enchant, current.getInteger("level"), successRate, current.getInteger("destroy-rate")));
event.setCancelled(true);
useItem(event);
@ -45,7 +45,7 @@ public class DustListener extends ItemListener {
@Override
void onClick(PlayerInteractEvent event, NBTItem clicked) {
if (!clicked.has("secret-dust") || !clicked.getNBTObject("secret-dust").asBoolean()) {
if (!clicked.hasKey("secret-dust") || !clicked.getBoolean("secret-dust")) {
return;
}
@ -55,8 +55,8 @@ public class DustListener extends ItemListener {
return;
}
Group group = instance.getGroupManager().getValueUnsafe(clicked.getNBTObject("group").asString());
int rate = ThreadLocalRandom.current().nextInt(clicked.getNBTObject("min-rate").asInt(), clicked.getNBTObject("max-rate").asInt());
Group group = instance.getGroupManager().getValueUnsafe(clicked.getString("group"));
int rate = ThreadLocalRandom.current().nextInt(clicked.getInteger("min-rate"), clicked.getInteger("max-rate"));
useItem(event);
event.getPlayer().getInventory().addItem(instance.getSpecialItems().getDust(group, null, rate, false));

View File

@ -1,7 +1,6 @@
package com.songoda.epicenchants.listeners.item;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
@ -32,7 +31,7 @@ public abstract class ItemListener implements Listener {
return;
}
onApply(event, NmsManager.getNbt().of(event.getCursor()), NmsManager.getNbt().of(event.getCurrentItem()));
onApply(event, new NBTItem(event.getCursor()), new NBTItem(event.getCurrentItem()));
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -45,7 +44,7 @@ public abstract class ItemListener implements Listener {
return;
}
onClick(event, NmsManager.getNbt().of(event.getItem()));
onClick(event, new NBTItem(event.getItem()));
}
void useItem(InventoryClickEvent event) {

View File

@ -1,7 +1,7 @@
package com.songoda.epicenchants.listeners.item;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import org.bukkit.event.inventory.InventoryClickEvent;
@ -15,13 +15,13 @@ public class WhiteScrollListener extends ItemListener {
@Override
void onApply(InventoryClickEvent event, NBTItem cursor, NBTItem current) {
if (!cursor.has("white-scroll") || !cursor.getNBTObject("white-scroll").asBoolean()) {
if (!cursor.hasKey("white-scroll") || !cursor.getBoolean("white-scroll")) {
return;
}
event.setCancelled(true);
if (current.has("protected")) {
if (current.hasKey("protected")) {
instance.getLocale().getMessage("whitescroll.alreadyapplied")
.sendPrefixedMessage(event.getWhoClicked());
return;
@ -30,10 +30,10 @@ public class WhiteScrollListener extends ItemListener {
if (!instance.getItemGroup().isValid(CompatibleMaterial.getMaterial(event.getCurrentItem())))
return;
current.set("protected", true);
current.setBoolean("protected", true);
instance.getLocale().getMessage("whitescrollapplied").sendPrefixedMessage(event.getWhoClicked());
ItemStack toSet = new ItemBuilder(current.finish()).addLore(instance.getSpecialItems().getWhiteScrollLore()).build();
ItemStack toSet = new ItemBuilder(current.getItem()).addLore(instance.getSpecialItems().getWhiteScrollLore()).build();
event.getClickedInventory().setItem(event.getSlot(), toSet);
useItem(event);

View File

@ -1,8 +1,7 @@
package com.songoda.epicenchants.menus;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Enchant;
import com.songoda.epicenchants.objects.Group;
@ -123,9 +122,9 @@ public class AlchemistMenu extends FastInv {
ItemStack toHandle = itemStack.clone();
toHandle.setAmount(1);
NBTItem nbtItem = NmsManager.getNbt().of(toHandle);
NBTItem nbtItem = new NBTItem(toHandle);
if (!nbtItem.has("book-item") && !nbtItem.has("dust")) {
if (!nbtItem.hasKey("book-item") && !nbtItem.hasKey("dust")) {
instance.getLocale().getMessage("alchemist.notinterested").sendPrefixedMessage(player);
return false;
}
@ -136,13 +135,13 @@ public class AlchemistMenu extends FastInv {
return false;
}
int successRate = nbtItem.getNBTObject("success-rate").asInt();
int successRate = nbtItem.getInteger("success-rate");
// Both slots empty
if (getInventory().getItem(LEFT_SLOT) == null && getInventory().getItem(RIGHT_SLOT) == null) {
if (nbtItem.has("book-item")) {
Enchant enchant = instance.getEnchantManager().getValue(nbtItem.getNBTObject("enchant").asString()).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
int level = nbtItem.getNBTObject("level").asInt();
if (nbtItem.hasKey("book-item")) {
Enchant enchant = instance.getEnchantManager().getValue(nbtItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
int level = nbtItem.getInteger("level");
if (enchant.getMaxLevel() == level) {
instance.getLocale().getMessage("alchemist.maxlevelbook")
@ -150,7 +149,7 @@ public class AlchemistMenu extends FastInv {
return false;
}
} else {
Group group = instance.getGroupManager().getValue(nbtItem.getNBTObject("group").asString()).orElseThrow(() -> new IllegalStateException("Dust without group!"));
Group group = instance.getGroupManager().getValue(nbtItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
if (group.getOrder() == instance.getGroupManager().getValues().stream().mapToInt(Group::getOrder).max().orElse(0) || successRate == 100) {
instance.getLocale().getMessage("alchemist." + (successRate == 100 ? "maxpercentagedust" : "highestgroupdust"))
@ -163,21 +162,21 @@ public class AlchemistMenu extends FastInv {
return true;
}
NBTItem other = NmsManager.getNbt().of(getInventory().getItem(getInventory().getItem(LEFT_SLOT) == null ? RIGHT_SLOT : LEFT_SLOT));
NBTItem other = new NBTItem(getInventory().getItem(getInventory().getItem(LEFT_SLOT) == null ? RIGHT_SLOT : LEFT_SLOT));
int emptySlot = getInventory().getItem(LEFT_SLOT) == null ? LEFT_SLOT : RIGHT_SLOT;
if (other.has("book-item")) {
if (!nbtItem.getNBTObject("enchant").asString().equals(other.getNBTObject("enchant").asString())) {
if (other.hasKey("book-item")) {
if (!nbtItem.getString("enchant").equals(other.getString("enchant"))) {
instance.getLocale().getMessage("alchemist.differentenchantment").sendPrefixedMessage(player);
return false;
}
if (nbtItem.getNBTObject("level").asInt() != other.getNBTObject("level").asInt()) {
if (nbtItem.getInteger("level") != other.getInteger("level")) {
instance.getLocale().getMessage("alchemist.differentlevels").sendPrefixedMessage(player);
return false;
}
} else {
if (!nbtItem.getNBTObject("group").asString().equals(other.getNBTObject("group").asString())) {
if (!nbtItem.getString("group").equals(other.getString("group"))) {
instance.getLocale().getMessage("alchemist.differentgroups").sendPrefixedMessage(player);
return false;
}
@ -200,18 +199,18 @@ public class AlchemistMenu extends FastInv {
return;
}
NBTItem leftItem = NmsManager.getNbt().of(getInventory().getItem(LEFT_SLOT));
NBTItem rightItem = NmsManager.getNbt().of(getInventory().getItem(RIGHT_SLOT));
NBTItem leftItem = new NBTItem(getInventory().getItem(LEFT_SLOT));
NBTItem rightItem = new NBTItem(getInventory().getItem(RIGHT_SLOT));
int ecoCost;
int expCost;
if (leftItem.has("book-item")) {
int level = leftItem.getNBTObject("level").asInt();
Enchant enchant = instance.getEnchantManager().getValue(leftItem.getNBTObject("enchant").asString()).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
int leftSuccess = leftItem.getNBTObject("success-rate").asInt();
int rightSuccess = rightItem.getNBTObject("success-rate").asInt();
int leftDestroy = leftItem.getNBTObject("destroy-rate").asInt();
int rightDestroy = rightItem.getNBTObject("destroy-rate").asInt();
if (leftItem.hasKey("book-item")) {
int level = leftItem.getInteger("level");
Enchant enchant = instance.getEnchantManager().getValue(leftItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
int leftSuccess = leftItem.getInteger("success-rate");
int rightSuccess = rightItem.getInteger("success-rate");
int leftDestroy = leftItem.getInteger("destroy-rate");
int rightDestroy = rightItem.getInteger("destroy-rate");
Placeholder[] placeholders = new Placeholder[] {
of("left_success_rate", leftSuccess),
@ -238,11 +237,11 @@ public class AlchemistMenu extends FastInv {
getInventory().setItem(PREVIEW_SLOT, enchant.getBook().get(enchant, level + 1, successRate, destroyRate));
} else {
Group group = instance.getGroupManager().getValue(leftItem.getNBTObject("group").asString()).orElseThrow(() -> new IllegalStateException("Dust without group!"));
Group group = instance.getGroupManager().getValue(leftItem.getString("group")).orElseThrow(() -> new IllegalStateException("Dust without group!"));
Placeholder[] placeholders = new Placeholder[] {
of("left_percentage", leftItem.getNBTObject("percentage").asInt()),
of("right_percentage", rightItem.getNBTObject("percentage").asInt())
of("left_percentage", leftItem.getInteger("percentage")),
of("right_percentage", rightItem.getInteger("percentage"))
};
int successRate = getFromFormula("dust.percentage-formula", placeholders);

View File

@ -1,8 +1,7 @@
package com.songoda.epicenchants.menus;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTCompound;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.ItemType;
import com.songoda.epicenchants.objects.Enchant;
@ -169,9 +168,9 @@ public class TinkererMenu extends FastInv {
return NONE;
}
NBTItem nbtItem = NmsManager.getNbt().of(itemStack);
NBTItem nbtItem = new NBTItem(itemStack);
if (nbtItem.has("book-item")) {
if (nbtItem.hasKey("book-item")) {
return BOOK;
}
@ -206,7 +205,7 @@ public class TinkererMenu extends FastInv {
switch (itemType) {
case BOOK:
getInventory().setItem(emptySlot.get().getValue(), instance.getSpecialItems().getSecretDust(NmsManager.getNbt().of(finalItemStack)));
getInventory().setItem(emptySlot.get().getValue(), instance.getSpecialItems().getSecretDust(new NBTItem(finalItemStack)));
break;
case ENCHANTED:
getInventory().setItem(emptySlot.get().getValue(), instance.getHookManager().getUltimateBottles().get().createBottle("Tinkerer", getExpAmount(finalItemStack)));
@ -236,9 +235,9 @@ public class TinkererMenu extends FastInv {
total.addAndGet(section.getInt(enchantment.getName(), section.getInt("DEFAULT")) * level);
});
NBTItem nbtItem = NmsManager.getNbt().of(itemStack);
NBTItem nbtItem = new NBTItem(itemStack);
if (!nbtItem.has("enchants")) {
if (!nbtItem.hasKey("enchants")) {
return total.get();
}
@ -250,7 +249,7 @@ public class TinkererMenu extends FastInv {
enchantments.getKeys().forEach(key -> {
Enchant enchant = instance.getEnchantManager().getValueUnsafe(key);
total.addAndGet(section.getInt(enchant.getIdentifier(), enchant.getGroup().getTinkererExp()) * enchantments.getInt(key));
total.addAndGet(section.getInt(enchant.getIdentifier(), enchant.getGroup().getTinkererExp()) * enchantments.getInteger(key));
});
return total.get();

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.objects;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
import com.songoda.epicenchants.utils.settings.Settings;
@ -81,13 +81,13 @@ public class BookItem {
.lore(toSet);
NBTItem nbtItem = itemBuilder.nbt();
nbtItem.set("book-item", true);
nbtItem.set("success-rate", successRate);
nbtItem.set("destroy-rate", destroyRate);
nbtItem.set("level", level);
nbtItem.set("enchant", enchant.getIdentifier());
nbtItem.setBoolean("book-item", true);
nbtItem.setInteger("success-rate", successRate);
nbtItem.setInteger("destroy-rate", destroyRate);
nbtItem.setInteger("level", level);
nbtItem.setString("enchant", enchant.getIdentifier());
return nbtItem.finish();
return nbtItem.getItem();
}
public static class BookItemBuilder {

View File

@ -1,8 +1,7 @@
package com.songoda.epicenchants.utils;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTCompound;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTCompound;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.core.utils.TextUtils;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.enums.EnchantResult;
@ -49,7 +48,7 @@ public class EnchantUtils {
}
public Tuple<ItemStack, EnchantResult> apply(ItemStack itemStack, Enchant enchant, int level, int successRate, int destroyRate) {
boolean hasProtection = NmsManager.getNbt().of(itemStack).has("protected");
boolean hasProtection = new NBTItem(itemStack).hasKey("protected");
Map<Enchant, Integer> currentEnchantMap = getEnchants(itemStack);
Set<String> currentIds = currentEnchantMap.keySet().stream().map(Enchant::getIdentifier).collect(Collectors.toSet());
@ -71,8 +70,8 @@ public class EnchantUtils {
if (GeneralUtils.chance(destroyRate)) {
if (hasProtection) {
NBTItem nbtItem = new ItemBuilder(itemStack).removeLore(instance.getSpecialItems().getWhiteScrollLore()).nbt();
nbtItem.remove("protected");
return Tuple.of(nbtItem.finish(), PROTECTED);
nbtItem.removeKey("protected");
return Tuple.of(nbtItem.getItem(), PROTECTED);
}
return Tuple.of(new ItemStack(Material.AIR), BROKEN_FAILURE);
}
@ -94,19 +93,19 @@ public class EnchantUtils {
NBTItem nbtItem = itemBuilder.nbt();
NBTCompound compound = nbtItem.getCompound("enchants");
compound.set(enchant.getIdentifier(), level);
NBTCompound compound = nbtItem.getOrCreateCompound("enchants");
compound.setInteger(enchant.getIdentifier(), level);
return Tuple.of(nbtItem.finish(), SUCCESS);
return Tuple.of(nbtItem.getItem(), SUCCESS);
}
public Map<Enchant, Integer> getEnchants(ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) {
return Collections.emptyMap();
}
NBTItem nbtItem = NmsManager.getNbt().of(itemStack);
NBTItem nbtItem = new NBTItem(itemStack);
if (!nbtItem.has("enchants")) {
if (!nbtItem.hasKey("enchants")) {
return Collections.emptyMap();
}
@ -117,7 +116,7 @@ public class EnchantUtils {
}
return compound.getKeys().stream().filter(key -> instance.getEnchantManager().getValueUnsafe(key) != null)
.collect(Collectors.toMap(key -> instance.getEnchantManager().getValueUnsafe(key), compound::getInt));
.collect(Collectors.toMap(key -> instance.getEnchantManager().getValueUnsafe(key), compound::getInteger));
}
public void handlePlayer(@NotNull Player player, @Nullable LivingEntity opponent, Event event, TriggerType triggerType) {
@ -139,7 +138,7 @@ public class EnchantUtils {
return null;
}
NBTItem nbtItem = NmsManager.getNbt().of(itemStack);
NBTItem nbtItem = new NBTItem(itemStack);
if (nbtItem.getCompound("enchants") == null) {
return itemStack;
@ -148,8 +147,8 @@ public class EnchantUtils {
String format = enchant.getFormat().replace("{level}", "").trim();
String text = format.isEmpty() ? enchant.getColoredIdentifier(false) : format;
nbtItem.getCompound("enchants").remove(enchant.getIdentifier());
ItemBuilder output = new ItemBuilder(nbtItem.finish());
nbtItem.getCompound("enchants").removeKey(enchant.getIdentifier());
ItemBuilder output = new ItemBuilder(nbtItem.getItem());
output.removeLore(TextUtils.formatText(text));
return output.build();
}

View File

@ -1,6 +1,6 @@
package com.songoda.epicenchants.utils;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.EpicEnchants;
import com.songoda.epicenchants.objects.Group;
import com.songoda.epicenchants.utils.objects.ItemBuilder;
@ -24,8 +24,8 @@ public class SpecialItems {
public ItemStack getWhiteScroll(int amount) {
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("white-scroll")).nbt();
nbtItem.set("white-scroll", true);
ItemStack itemStack = nbtItem.finish();
nbtItem.setBoolean("white-scroll", true);
ItemStack itemStack = nbtItem.getItem();
itemStack.setAmount(amount);
@ -36,10 +36,10 @@ public class SpecialItems {
int successRate = chance == -1 ? ThreadLocalRandom.current().nextInt(Settings.BLACK_MIN.getInt(), Settings.BLACK_MAX.getInt() + 1) : chance;
NBTItem nbtItem = new ItemBuilder(instance.getFileManager().getConfiguration("items/special-items").getConfigurationSection("black-scroll"), of("success-rate", successRate)).nbt();
nbtItem.set("black-scroll", true);
nbtItem.set("success-rate", successRate);
nbtItem.setBoolean("black-scroll", true);
nbtItem.setInteger("success-rate", successRate);
ItemStack itemStack = nbtItem.finish();
ItemStack itemStack = nbtItem.getItem();
itemStack.setAmount(amount);
@ -51,14 +51,14 @@ public class SpecialItems {
of("group-color", group.getColor()),
of("group-name", group.getName())).nbt();
nbtItem.set("mystery-book", true);
nbtItem.set("group", group.getIdentifier());
return nbtItem.finish();
nbtItem.setBoolean("mystery-book", true);
nbtItem.setString("group", group.getIdentifier());
return nbtItem.getItem();
}
public ItemStack getSecretDust(NBTItem book) {
Group group = instance.getEnchantManager().getValueUnsafe(book.getNBTObject("enchant").asString()).getGroup();
return getSecretDust(group, (int) Math.floor(book.getNBTObject("success-rate").asInt() / 10.0));
Group group = instance.getEnchantManager().getValueUnsafe(book.getString("enchant")).getGroup();
return getSecretDust(group, (int) Math.floor(book.getInteger("success-rate") / 10.0));
}
public ItemStack getSecretDust(Group group, int max) {
@ -68,11 +68,11 @@ public class SpecialItems {
of("max-rate", max),
of("min-rate", 0)).nbt();
nbtItem.set("secret-dust", true);
nbtItem.set("group", group.getIdentifier());
nbtItem.set("max-rate", max + 1);
nbtItem.set("min-rate", 1);
return nbtItem.finish();
nbtItem.setBoolean("secret-dust", true);
nbtItem.setString("group", group.getIdentifier());
nbtItem.setInteger("max-rate", max + 1);
nbtItem.setInteger("min-rate", 1);
return nbtItem.getItem();
}
public ItemStack getDust(Group group, @Nullable String type, int percentage, boolean command) {
@ -108,14 +108,14 @@ public class SpecialItems {
of("percentage", percentage)).nbt();
if (type.equalsIgnoreCase("mystery")) {
return nbtItem.finish();
return nbtItem.getItem();
}
nbtItem.set("dust", true);
nbtItem.set("percentage", percentage);
nbtItem.set("group", group.getIdentifier());
nbtItem.setBoolean("dust", true);
nbtItem.setInteger("percentage", percentage);
nbtItem.setString("group", group.getIdentifier());
return nbtItem.finish();
return nbtItem.getItem();
}
public String getWhiteScrollLore() {

View File

@ -1,7 +1,6 @@
package com.songoda.epicenchants.utils.objects;
import com.songoda.core.nms.NmsManager;
import com.songoda.core.nms.nbt.NBTItem;
import com.songoda.core.third_party.de.tr7zw.nbtapi.NBTItem;
import com.songoda.epicenchants.objects.Placeholder;
import com.songoda.epicenchants.utils.single.ConfigParser;
import com.songoda.epicenchants.utils.single.GeneralUtils;
@ -265,7 +264,7 @@ public class ItemBuilder {
}
public NBTItem nbt() {
return NmsManager.getNbt().of(build());
return new NBTItem(build());
}
/*