Replaces deprecated NBTItem calls

This commit is contained in:
Christian Koop 2022-03-18 18:21:18 +01:00
parent 14af8a50b6
commit 72c4942525
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
4 changed files with 36 additions and 42 deletions

View File

@ -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);

View File

@ -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() {

View File

@ -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);

View File

@ -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