Skip to content

Commit 343ff32

Browse files
committed
added unbreaking for legacy
1 parent a31c73d commit 343ff32

File tree

3 files changed

+14
-22
lines changed

3 files changed

+14
-22
lines changed

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/CreateItemStack.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,17 @@
99
import org.broken.arrow.library.itemcreator.meta.enhancement.EnhancementWrapper;
1010
import org.broken.arrow.library.itemcreator.meta.potion.PotionTypeWrapper;
1111
import org.broken.arrow.library.itemcreator.utility.ConvertToItemStack;
12-
import org.broken.arrow.library.itemcreator.utility.Tuple;
1312
import org.broken.arrow.library.itemcreator.utility.builders.ItemBuilder;
1413
import org.broken.arrow.library.itemcreator.utility.nbt.NBTDataWriter;
1514
import org.broken.arrow.library.logging.Logging;
1615
import org.broken.arrow.library.logging.Validate;
17-
import org.broken.arrow.library.nbt.RegisterNbtAPI;
18-
import org.bukkit.DyeColor;
19-
import org.bukkit.FireworkEffect;
2016
import org.bukkit.Material;
21-
import org.bukkit.NamespacedKey;
22-
import org.bukkit.block.banner.Pattern;
2317
import org.bukkit.enchantments.Enchantment;
2418
import org.bukkit.inventory.ItemFlag;
2519
import org.bukkit.inventory.ItemStack;
2620
import org.bukkit.inventory.meta.Damageable;
2721
import org.bukkit.inventory.meta.ItemMeta;
2822
import org.bukkit.inventory.meta.PotionMeta;
29-
import org.bukkit.potion.PotionEffect;
3023

3124
import javax.annotation.Nonnull;
3225
import javax.annotation.Nullable;
@@ -550,8 +543,9 @@ private ItemStack getItemStack(@Nonnull ItemStack itemStack) {
550543
if (!isAir(itemStack.getType())) {
551544
itemStack = setNbt(itemStack);
552545

553-
final ItemMeta itemMeta = itemStack.getItemMeta();
554-
setMetadata(itemStack, itemMeta);
546+
ItemMeta itemMeta = itemStack.getItemMeta();
547+
itemMeta = setMetadata(itemStack, itemMeta);
548+
555549
if (this.metaHandler != null)
556550
this.metaHandler.applyMeta(itemStack, itemMeta);
557551
itemStack.setItemMeta(itemMeta);
@@ -569,7 +563,7 @@ private ItemStack setNbt(ItemStack itemStack) {
569563
return itemStack;
570564
}
571565

572-
private void setMetadata(ItemStack itemStack, final ItemMeta itemMeta) {
566+
private ItemMeta setMetadata(ItemStack itemStack, final ItemMeta itemMeta) {
573567
if (itemMeta != null) {
574568
if (this.displayName != null) {
575569
itemMeta.setDisplayName(translateColors(this.displayName));
@@ -579,6 +573,7 @@ private void setMetadata(ItemStack itemStack, final ItemMeta itemMeta) {
579573
}
580574
addItemMeta(itemStack, itemMeta);
581575
}
576+
return setUnbreakableMeta(itemMeta);
582577
}
583578

584579

@@ -611,10 +606,8 @@ private ItemStack checkTypeOfItem(final Object object) {
611606

612607
private void addItemMeta(@Nonnull final ItemStack itemStack, @Nonnull final ItemMeta itemMeta) {
613608
this.setDamageMeta(itemStack, itemMeta);
614-
if (this.serverVersion > 10.0F)
615-
setUnbreakableMeta(itemMeta);
616-
this.addCustomModelData(itemMeta);
617609

610+
this.addCustomModelData(itemMeta);
618611
if (isShowEnchantments() || !this.getItemFlags().isEmpty() || this.isGlow())
619612
hideEnchantments(itemMeta);
620613
}
@@ -651,9 +644,8 @@ private void hideEnchantments(final ItemMeta itemMeta) {
651644
}
652645
}
653646

654-
655-
private void setUnbreakableMeta(final ItemMeta itemMeta) {
656-
itemMeta.setUnbreakable(isUnbreakable());
647+
private ItemMeta setUnbreakableMeta(final ItemMeta itemMeta) {
648+
return ItemCreator.applyUnbreakable(itemMeta,isUnbreakable());
657649
}
658650

659651
private void addCustomModelData(final ItemMeta itemMeta) {

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/ItemCreator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public ItemCreator(final Plugin pluginInstance, boolean turnOffLogger) {
7272

7373
this.convertItems = new ConvertToItemStack(serverVersion.getServerVersion());
7474

75-
Bukkit.getScheduler().runTaskLater(pluginInstance, () -> UnbreakableUtil.isUnbreakable(null), 1L);
7675
try {
7776
TextTranslator.getInstance();
7877
} catch (NoClassDefFoundError ignore) {

Item Creator/src/main/java/org/broken/arrow/library/itemcreator/utility/compound/LegacyNBT.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
public class LegacyNBT {
2424
private static final Logging logger = new Logging(NbtData.class);
2525

26-
private LegacyNBT() {}
26+
private LegacyNBT() {
27+
}
2728

2829
/**
2930
* Creates a new {@link NmsItemSession} for the given Bukkit {@link ItemStack}.
@@ -106,7 +107,7 @@ public static class NmsItemSession {
106107

107108
Class<?> craftItemStack = Class.forName(craftPath + ".inventory.CraftItemStack");
108109
Class<?> nmsItemStack = Class.forName(nmsPath + ".ItemStack");
109-
Class<?> nbtTagCompound = Class.forName(nmsPath + ".NBTTagCompound");
110+
Class<?> nbtTagCompound = Class.forName(getNbtTagPath());
110111

111112
asNMSCopyItem = craftItemStack.getMethod("asNMSCopy", ItemStack.class);
112113
bukkitCopy = craftItemStack.getMethod("asBukkitCopy", nmsItemStack);
@@ -346,10 +347,10 @@ public boolean getBoolean(@Nonnull String key) {
346347
return false;
347348
}
348349

349-
private static String getNbtTagPath() {
350-
return getNmsPath() + ".NBTTagCompound";
351-
}
350+
}
352351

352+
private static String getNbtTagPath() {
353+
return getNmsPath() + ".NBTTagCompound";
353354
}
354355

355356
private static String getNmsPath() {

0 commit comments

Comments
 (0)