mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-26 02:17:38 +01:00
fix: replace deprecated calls to item-nbt-api with the new ones
This commit is contained in:
parent
bcec303d5a
commit
61c236249c
@ -2,8 +2,9 @@ package com.craftaro.ultimatestacker.listeners;
|
|||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleHand;
|
import com.craftaro.core.compatibility.CompatibleHand;
|
||||||
import com.craftaro.core.hooks.ProtectionManager;
|
import com.craftaro.core.hooks.ProtectionManager;
|
||||||
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBT;
|
||||||
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.iface.ReadableNBT;
|
||||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
|
||||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||||
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
||||||
import com.craftaro.ultimatestacker.api.events.spawner.SpawnerBreakEvent;
|
import com.craftaro.ultimatestacker.api.events.spawner.SpawnerBreakEvent;
|
||||||
@ -86,7 +87,7 @@ public class BlockListeners implements Listener {
|
|||||||
//Add to stack
|
//Add to stack
|
||||||
if (clickAction == Action.RIGHT_CLICK_BLOCK && !player.hasPermission("ultimatestacker.block.nostack")) {
|
if (clickAction == Action.RIGHT_CLICK_BLOCK && !player.hasPermission("ultimatestacker.block.nostack")) {
|
||||||
if (inHand.getType().equals(Material.AIR)) return;
|
if (inHand.getType().equals(Material.AIR)) return;
|
||||||
if(!blockType.equals(XMaterial.matchXMaterial(inHand))) return;
|
if (!blockType.equals(XMaterial.matchXMaterial(inHand))) return;
|
||||||
//Add all held items to stack
|
//Add all held items to stack
|
||||||
if (Settings.ALWAYS_ADD_ALL.getBoolean() || isSneaking) {
|
if (Settings.ALWAYS_ADD_ALL.getBoolean() || isSneaking) {
|
||||||
stack.add(inHandAmount);
|
stack.add(inHandAmount);
|
||||||
@ -108,8 +109,8 @@ public class BlockListeners implements Listener {
|
|||||||
//Remove all items from stack
|
//Remove all items from stack
|
||||||
int amountToRemove = Math.min(Settings.MAX_REMOVEABLE.getInt(), stack.getAmount());
|
int amountToRemove = Math.min(Settings.MAX_REMOVEABLE.getInt(), stack.getAmount());
|
||||||
ItemStack removed = stack.getMaterial().parseItem();
|
ItemStack removed = stack.getMaterial().parseItem();
|
||||||
removed.setAmount(amountToRemove-1);
|
removed.setAmount(amountToRemove - 1);
|
||||||
stack.take(amountToRemove-1);
|
stack.take(amountToRemove - 1);
|
||||||
if (Settings.ADD_TO_INVENTORY.getBoolean()) {
|
if (Settings.ADD_TO_INVENTORY.getBoolean()) {
|
||||||
player.getInventory().addItem(removed);
|
player.getInventory().addItem(removed);
|
||||||
} else {
|
} else {
|
||||||
@ -138,7 +139,7 @@ public class BlockListeners implements Listener {
|
|||||||
if (isSneaking || player.hasPermission("ultimatestacker.block.nostack")) return;
|
if (isSneaking || player.hasPermission("ultimatestacker.block.nostack")) return;
|
||||||
//Check if player clicked the same type as the clicked block
|
//Check if player clicked the same type as the clicked block
|
||||||
if (inHand.getType().equals(Material.AIR)) return;
|
if (inHand.getType().equals(Material.AIR)) return;
|
||||||
if(!blockType.equals(XMaterial.matchXMaterial(inHand))) return;
|
if (!blockType.equals(XMaterial.matchXMaterial(inHand))) return;
|
||||||
if (clickAction != Action.RIGHT_CLICK_BLOCK) return;
|
if (clickAction != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
//Create new stack
|
//Create new stack
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -201,7 +202,7 @@ public class BlockListeners implements Listener {
|
|||||||
//remove fullstacks-1 and add back overflow as a new item stack
|
//remove fullstacks-1 and add back overflow as a new item stack
|
||||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
if (overflow > 0) {
|
if (overflow > 0) {
|
||||||
hand.takeItem(player, fullStacks+1);
|
hand.takeItem(player, fullStacks + 1);
|
||||||
ItemStack overflowItem = Methods.getSpawnerItem(blockType, overflow);
|
ItemStack overflowItem = Methods.getSpawnerItem(blockType, overflow);
|
||||||
if (player.getInventory().firstEmpty() == -1) {
|
if (player.getInventory().firstEmpty() == -1) {
|
||||||
block.getWorld().dropItemNaturally(block.getLocation().add(.5, 0, .5), overflowItem);
|
block.getWorld().dropItemNaturally(block.getLocation().add(.5, 0, .5), overflowItem);
|
||||||
@ -345,9 +346,10 @@ public class BlockListeners implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getSpawnerAmount(ItemStack item) {
|
private int getSpawnerAmount(ItemStack item) {
|
||||||
NBTItem nbtItem = new NBTItem(item);
|
ReadableNBT nbtItem = NBT.readNbt(item);
|
||||||
if (nbtItem.hasKey("spawner_stack_size"))
|
if (nbtItem.hasTag("spawner_stack_size")) {
|
||||||
return nbtItem.getInteger("spawner_stack_size");
|
return nbtItem.getInteger("spawner_stack_size");
|
||||||
|
}
|
||||||
|
|
||||||
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 1;
|
if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName()) return 1;
|
||||||
if (item.getItemMeta().getDisplayName().contains(":")) {
|
if (item.getItemMeta().getDisplayName().contains(":")) {
|
||||||
|
@ -2,10 +2,8 @@ package com.craftaro.ultimatestacker.listeners;
|
|||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleHand;
|
import com.craftaro.core.compatibility.CompatibleHand;
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
import com.craftaro.core.nms.Nms;
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBT;
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTCompound;
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.iface.ReadableNBT;
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTEntity;
|
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
|
||||||
import com.craftaro.core.utils.EntityUtils;
|
import com.craftaro.core.utils.EntityUtils;
|
||||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||||
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
||||||
@ -108,7 +106,7 @@ public class SpawnerListeners implements Listener {
|
|||||||
|
|
||||||
if (!Settings.EGGS_CONVERT_SPAWNERS.getBoolean()
|
if (!Settings.EGGS_CONVERT_SPAWNERS.getBoolean()
|
||||||
|| (event.getItem().hasItemMeta() && event.getItem().getItemMeta().hasDisplayName()
|
|| (event.getItem().hasItemMeta() && event.getItem().getItemMeta().hasDisplayName()
|
||||||
&& !new NBTItem(event.getItem()).hasKey("UC"))) {
|
&& !NBT.readNbt(event.getItem()).hasTag("UC"))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +124,7 @@ public class SpawnerListeners implements Listener {
|
|||||||
.replace("MOOSHROOM", "MUSHROOM_COW")
|
.replace("MOOSHROOM", "MUSHROOM_COW")
|
||||||
.replace("ZOMBIE_PIGMAN", "PIG_ZOMBIE"));
|
.replace("ZOMBIE_PIGMAN", "PIG_ZOMBIE"));
|
||||||
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
|
else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
|
||||||
Nms.getImplementations().getNbt().of(event.getItem()).toString();
|
ReadableNBT entityTag = NBT.readNbt(event.getItem()).getCompound("EntityTag");
|
||||||
NBTCompound entityTag = new NBTItem(event.getItem()).getCompound("EntityTag");
|
|
||||||
if (entityTag != null) {
|
if (entityTag != null) {
|
||||||
entityType = EntityType.fromName(entityTag.getString("id"));
|
entityType = EntityType.fromName(entityTag.getString("id"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.craftaro.ultimatestacker.utils;
|
package com.craftaro.ultimatestacker.utils;
|
||||||
|
|
||||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBT;
|
||||||
import com.craftaro.core.third_party.de.tr7zw.nbtapi.NBTItem;
|
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.ultimatestacker.UltimateStacker;
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
||||||
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
|
||||||
import com.craftaro.ultimatestacker.api.stack.item.StackedItem;
|
import com.craftaro.ultimatestacker.api.stack.item.StackedItem;
|
||||||
@ -104,9 +104,10 @@ public class Methods {
|
|||||||
((BlockStateMeta) meta).setBlockState(cs);
|
((BlockStateMeta) meta).setBlockState(cs);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
NBTItem nbtItem = new NBTItem(item);
|
NBT.modify(item, readableItemNBT -> {
|
||||||
nbtItem.setInteger("spawner_stack_size", amount);
|
readableItemNBT.setInteger("spawner_stack_size", amount);
|
||||||
return nbtItem.getItem();
|
});
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInt(String number) {
|
public static boolean isInt(String number) {
|
||||||
|
Loading…
Reference in New Issue
Block a user