From 72c49425253270d3b04aa940d90205c7c7d28526 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Fri, 18 Mar 2022 18:21:18 +0100 Subject: [PATCH] Replaces deprecated NBTItem calls --- .../handlers/DisplayItemHandler.java | 20 +++++------ .../com/songoda/ultimatekits/key/Key.java | 11 +++--- .../com/songoda/ultimatekits/kit/Kit.java | 12 +++---- .../com/songoda/ultimatekits/kit/KitItem.java | 35 +++++++++---------- 4 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java index be74743..52a2e8b 100644 --- a/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java +++ b/src/main/java/com/songoda/ultimatekits/handlers/DisplayItemHandler.java @@ -1,7 +1,6 @@ package com.songoda.ultimatekits.handlers; -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.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.Kit; import com.songoda.ultimatekits.kit.KitBlockData; @@ -15,7 +14,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -65,8 +63,8 @@ public class DisplayItemHandler { if (!kitBlockData.isDisplayingItems()) e.remove(); - NBTItem nbtItem = NmsManager.getNbt().of(i.getItemStack()); - int inum = nbtItem.has("num") ? nbtItem.getNBTObject("num").asInt() + 1 : 0; + NBTItem nbtItem = new NBTItem(i.getItemStack()); + int inum = nbtItem.hasKey("num") ? nbtItem.getInteger("num") + 1 : 0; int size = list.size(); if (inum > size || inum <= 0) inum = 1; @@ -81,9 +79,9 @@ public class DisplayItemHandler { meta.setDisplayName(null); meta.setLore(Collections.singletonList("Some lore stuff man.")); is.setItemMeta(meta); - nbtItem = NmsManager.getNbt().of(is); - nbtItem.set("num", inum); - i.setItemStack(nbtItem.finish()); + nbtItem = new NBTItem(is); + nbtItem.setInteger("num", inum); + i.setItemStack(nbtItem.getItem()); i.setPickupDelay(9999); return; } @@ -95,11 +93,11 @@ public class DisplayItemHandler { meta.setLore(Collections.singletonList("Display Item")); is.setItemMeta(meta); - NBTItem nbtItem = NmsManager.getNbt().of(is); - nbtItem.set("num", 0); + NBTItem nbtItem = new NBTItem(is); + nbtItem.setInteger("num", 0); Bukkit.getScheduler().runTask(plugin, () -> { - Item item = location.getWorld().dropItem(location.add(0, 1, 0), nbtItem.finish()); + Item item = location.getWorld().dropItem(location.add(0, 1, 0), nbtItem.getItem()); Vector vec = new Vector(0, 0, 0); item.setVelocity(vec); item.setPickupDelay(9999); diff --git a/src/main/java/com/songoda/ultimatekits/key/Key.java b/src/main/java/com/songoda/ultimatekits/key/Key.java index b538148..99293d2 100644 --- a/src/main/java/com/songoda/ultimatekits/key/Key.java +++ b/src/main/java/com/songoda/ultimatekits/key/Key.java @@ -1,7 +1,6 @@ package com.songoda.ultimatekits.key; -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.core.utils.ItemUtils; import com.songoda.core.utils.TextUtils; import com.songoda.ultimatekits.UltimateKits; @@ -73,11 +72,11 @@ public class Key { item.setItemMeta(meta); - NBTItem nbtItem = NmsManager.getNbt().of(item); - nbtItem.set("key", name); - nbtItem.set("kit", kit == null ? "ANY" : kit.getName()); + NBTItem nbtItem = new NBTItem(item); + nbtItem.setString("key", name); + nbtItem.setString("kit", kit == null ? "ANY" : kit.getName()); - return nbtItem.finish(); + return nbtItem.getItem(); } public String getName() { diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index ea3dc5d..e39e408 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -1,14 +1,12 @@ package com.songoda.ultimatekits.kit; import com.songoda.core.compatibility.CompatibleHand; -import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleSound; import com.songoda.core.configuration.Config; import com.songoda.core.gui.Gui; import com.songoda.core.gui.GuiManager; 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.core.utils.ItemUtils; import com.songoda.core.utils.TextUtils; import com.songoda.ultimatekits.UltimateKits; @@ -105,13 +103,13 @@ public class Kit implements Cloneable { public void processKeyUse(Player player) { ItemStack item = player.getItemInHand(); - NBTItem nbtItem = NmsManager.getNbt().of(item); + NBTItem nbtItem = new NBTItem(item); - if (!nbtItem.has("key") || !nbtItem.has("kit")) + if (!nbtItem.hasKey("key") || !nbtItem.hasKey("kit")) return; - String keyName = nbtItem.getNBTObject("key").asString(); - String kitName = nbtItem.getNBTObject("kit").asString(); + String keyName = nbtItem.getString("key"); + String kitName = nbtItem.getString("kit"); boolean any = kitName.equals("ANY"); Key key = plugin.getKeyManager().getKey(keyName); diff --git a/src/main/java/com/songoda/ultimatekits/kit/KitItem.java b/src/main/java/com/songoda/ultimatekits/kit/KitItem.java index 942f9cd..c044ede 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/KitItem.java +++ b/src/main/java/com/songoda/ultimatekits/kit/KitItem.java @@ -1,7 +1,6 @@ package com.songoda.ultimatekits.kit; -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.core.utils.TextUtils; import com.songoda.ultimatekits.UltimateKits; import com.songoda.ultimatekits.kit.type.KitContent; @@ -61,15 +60,15 @@ public class KitItem implements Cloneable { private void translateTags(ItemStack item) { if (item == null) return; - NBTItem nbtItem = NmsManager.getNbt().of(item); - if (nbtItem.has("chance")) - chance = nbtItem.getNBTObject("chance").asDouble(); - if (nbtItem.has("display-item")) - displayItem = Material.valueOf(nbtItem.getNBTObject("display-item").asString()); - if (nbtItem.has("display-name")) - displayName = nbtItem.getNBTObject("display-name").asString(); - if (nbtItem.has("display-lore")) - displayLore = nbtItem.getNBTObject("display-lore").asString(); + NBTItem nbtItem = new NBTItem(item); + if (nbtItem.hasKey("chance")) + chance = nbtItem.getDouble("chance"); + if (nbtItem.hasKey("display-item")) + displayItem = Material.valueOf(nbtItem.getString("display-item")); + if (nbtItem.hasKey("display-name")) + displayName = nbtItem.getString("display-name"); + if (nbtItem.hasKey("display-lore")) + displayLore = nbtItem.getString("display-lore"); } private String translateLine(String line) { @@ -102,16 +101,16 @@ public class KitItem implements Cloneable { } private ItemStack compileOptions(ItemStack item) { - NBTItem nbtItem = NmsManager.getNbt().of(item); + NBTItem nbtItem = new NBTItem(item); if (chance != 0) - nbtItem.set("chance", chance); + nbtItem.setDouble("chance", chance); if (displayItem != null) - nbtItem.set("display-item", displayItem.name()); + nbtItem.setString("display-item", displayItem.name()); if (displayName != null) - nbtItem.set("display-name", displayName); + nbtItem.setString("display-name", displayName); if (displayLore != null) - nbtItem.set("display-lore", displayLore); - return nbtItem.finish(); + nbtItem.setString("display-lore", displayLore); + return nbtItem.getItem(); } private String compileOptionsText() { @@ -224,7 +223,7 @@ public class KitItem implements Cloneable { } public KitItem clone() throws CloneNotSupportedException { - return (KitItem)super.clone(); + return (KitItem) super.clone(); } @Override