From a039d079248b1947dfc8369715b3f20ea3106bd8 Mon Sep 17 00:00:00 2001 From: Gecko! <74975165+SmartGecko44@users.noreply.github.com> Date: Thu, 27 Jun 2024 23:17:25 +0200 Subject: [PATCH] Removed usage of deprecated functions --- .../java/org/gecko/spigotadmintoys/gui/ConfigGUI.java | 8 +++++--- .../spigotadmintoys/gui/logic/CreateButtonItem.java | 9 +++++---- .../org/gecko/spigotadmintoys/items/TriggerItems.java | 9 +++++---- .../gecko/spigotadmintoys/items/weapons/Shortbow.java | 8 +++++--- .../gecko/spigotadmintoys/listeners/BarrierListener.java | 7 ++++--- .../gecko/spigotadmintoys/listeners/BedrockListener.java | 7 ++++--- .../gecko/spigotadmintoys/listeners/BucketListener.java | 7 ++++--- .../org/gecko/spigotadmintoys/listeners/SphereMaker.java | 7 ++++--- .../spigotadmintoys/listeners/WaterBucketListener.java | 7 ++++--- 9 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java b/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java index 487544d..f6edaa5 100644 --- a/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java +++ b/src/main/java/org/gecko/spigotadmintoys/gui/ConfigGUI.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.gui; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -14,6 +15,8 @@ import org.gecko.spigotadmintoys.data.ConfigurationManager; import org.gecko.spigotadmintoys.logic.SetAndGet; +import java.util.function.Function; + public class ConfigGUI implements Listener { public static final String ENABLE_BUCKET = "Enable Bucket"; @@ -131,8 +134,7 @@ private boolean isClickEventValid(InventoryClickEvent event) { private void handleItemClick(Player player, ItemStack clickedItem) { if (clickedItem != null && (clickedItem.getType() == Material.INK_SACK || clickedItem.getType() == Material.PAPER || clickedItem.getType() == Material.CONCRETE || clickedItem.getType() == Material.ARROW)) { - NBTItem nbtItem = new NBTItem(clickedItem); - String identifier = nbtItem.getString("Ident"); + String identifier = NBT.get(clickedItem, (Function) nbt -> nbt.getString("Ident")); short data = clickedItem.getDurability(); if (handleButtonFeatures(player, identifier, data)) { diff --git a/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java b/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java index e67373c..8627587 100644 --- a/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java +++ b/src/main/java/org/gecko/spigotadmintoys/gui/logic/CreateButtonItem.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.gui.logic; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -8,6 +9,7 @@ import java.util.Collections; import java.util.List; +import java.util.function.Consumer; public class CreateButtonItem { @@ -28,9 +30,8 @@ public ItemStack createButtonItem(Material material, String name, short data, St meta.setLore(loreToString); item.setItemMeta(meta); - NBTItem nbtItem = new NBTItem(item); - nbtItem.setString("Ident", ident); + NBT.modify(item, (Consumer) nbt -> nbt.setString("Ident", ident)); - return nbtItem.getItem(); + return item; } } diff --git a/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java b/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java index e823aae..bdbd2e0 100644 --- a/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java +++ b/src/main/java/org/gecko/spigotadmintoys/items/TriggerItems.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.items; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadWriteItemNBT; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -8,6 +9,7 @@ import java.util.Collections; import java.util.List; +import java.util.function.Consumer; public class TriggerItems { @@ -21,9 +23,8 @@ public ItemStack createCustomItem(Material material, String name, short data, St meta.setLore(loreToList); item.setItemMeta(meta); - NBTItem nbtItem = new NBTItem(item); - nbtItem.setString("Ident", ident); + NBT.modify(item, (Consumer) nbt -> nbt.setString("Ident", ident)); - return nbtItem.getItem(); + return item; } } diff --git a/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java b/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java index cb00208..3e23a38 100644 --- a/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java +++ b/src/main/java/org/gecko/spigotadmintoys/items/weapons/Shortbow.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.items.weapons; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Arrow; @@ -12,6 +13,8 @@ import org.gecko.spigotadmintoys.enchantments.enchants.weapons.bows.BowListener; import org.gecko.spigotadmintoys.items.TriggerItems; +import java.util.function.Function; + public class Shortbow implements Listener { public static final String SHORTBOWCONST = "Shortbow"; @@ -31,8 +34,7 @@ public void onPlayerBowClick(PlayerInteractEvent event) { return; } - NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); - String identifier = nbtItem.getString("Ident"); + String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident")); if (!identifier.equals(SHORTBOWCONST)) { return; diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java index 2684beb..18c80b4 100644 --- a/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java +++ b/src/main/java/org/gecko/spigotadmintoys/listeners/BarrierListener.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.listeners; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -20,6 +21,7 @@ import org.gecko.spigotadmintoys.logic.SetAndGet; import java.util.*; +import java.util.function.Function; public class BarrierListener implements Listener { @@ -61,8 +63,7 @@ public void barrierBreakEventHandler(BlockBreakEvent event) { BucketListener bucketListener = setAndGet.getBucketListener(); BedrockListener bedrockListener = setAndGet.getBedrockListener(); WaterBucketListener waterBucketListener = setAndGet.getWaterBucketListener(); - NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); - String identifier = nbtItem.getString("Ident"); + String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident")); radiusLimit = setAndGet.getRadiusLimit(); realRadiusLimit = radiusLimit - 2; showRemoval = setAndGet.getShowRemoval(); diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java index 25cfca4..e911044 100644 --- a/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java +++ b/src/main/java/org/gecko/spigotadmintoys/listeners/BedrockListener.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.listeners; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -24,6 +25,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.Set; +import java.util.function.Function; public class BedrockListener implements Listener { @@ -168,8 +170,7 @@ private void bedrockPlayerSource(BlockBreakEvent event) { return; } Player player = event.getPlayer(); - NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); - String identifier = nbtItem.getString("Ident"); + String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident")); // Check if the bucket is filling with water if (player.getInventory().getItemInMainHand().getType() == Material.BEDROCK && identifier.equalsIgnoreCase("Custom Bedrock") && (!IMMUTABLE_MATERIALS.contains(event.getBlock().getType()))) { allRemovalActive = false; diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java index 5a4aebd..fb6fa7c 100644 --- a/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java +++ b/src/main/java/org/gecko/spigotadmintoys/listeners/BucketListener.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.listeners; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -20,6 +21,7 @@ import org.gecko.spigotadmintoys.logic.SetAndGet; import java.util.*; +import java.util.function.Function; public class BucketListener implements Listener { @@ -63,8 +65,7 @@ public void onBucketFill(PlayerBucketFillEvent event) { BarrierListener barrierListener = setAndGet.getBarrierListener(); BedrockListener bedrockListener = setAndGet.getBedrockListener(); WaterBucketListener waterBucketListener = setAndGet.getWaterBucketListener(); - NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); - String identifier = nbtItem.getString("Ident"); + String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident")); radiusLimit = setAndGet.getRadiusLimit(); realRadiusLimit = radiusLimit - 2; showRemoval = setAndGet.getShowRemoval(); diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java b/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java index 30a1767..48cac0b 100644 --- a/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java +++ b/src/main/java/org/gecko/spigotadmintoys/listeners/SphereMaker.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.listeners; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -22,6 +23,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.Set; +import java.util.function.Function; public class SphereMaker implements Listener { @@ -64,8 +66,7 @@ public void onBlockBreak(BlockBreakEvent event) { BedrockListener bedrockListener = setAndGet.getBedrockListener(); BucketListener bucketListener = setAndGet.getBucketListener(); WaterBucketListener waterBucketListener = setAndGet.getWaterBucketListener(); - NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); - String identifier = nbtItem.getString("Ident"); + String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident")); radiusLimit = setAndGet.getRadiusLimit(); realradiusLimit = setAndGet.getRadiusLimit() - 2; if (realradiusLimit > 1 && !barrierListener.isBlockRemovalActive() && !bedrockListener.isAllRemovalActive() && !bucketListener.isWauhRemovalActive() && !waterBucketListener.isTsunamiActive() && !IMMUTABLE_MATERIALS.contains(event.getBlock().getType()) && identifier.equals("SphereMaker")) { diff --git a/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java b/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java index 9fa8d9f..862aac7 100644 --- a/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java +++ b/src/main/java/org/gecko/spigotadmintoys/listeners/WaterBucketListener.java @@ -1,6 +1,7 @@ package org.gecko.spigotadmintoys.listeners; -import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBT; +import de.tr7zw.changeme.nbtapi.iface.ReadableItemNBT; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -20,6 +21,7 @@ import org.gecko.spigotadmintoys.logic.SetAndGet; import java.util.*; +import java.util.function.Function; public class WaterBucketListener implements Listener { @@ -60,8 +62,7 @@ public void tsunamiClick(PlayerBucketEmptyEvent event) { BucketListener bucketListener = setAndGet.getBucketListener(); BarrierListener barrierListener = setAndGet.getBarrierListener(); BedrockListener bedrockListener = setAndGet.getBedrockListener(); - NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand()); - String identifier = nbtItem.getString("Ident"); + String identifier = NBT.get(event.getPlayer().getInventory().getItemInMainHand(), (Function) nbt -> nbt.getString("Ident")); radiusLimit = setAndGet.getRadiusLimit(); realRadiusLimit = radiusLimit - 2; showRemoval = setAndGet.getShowRemoval();