Skip to content

Commit 3ad8d28

Browse files
committed
Allow use shopId to direct mark different item as same item if NBTAPI installed
1 parent 3f70985 commit 3ad8d28

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/main/java/org/maxgamer/quickshop/util/matcher/item/BukkitItemMatcherImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.maxgamer.quickshop.util.matcher.item;
2121

22+
import de.tr7zw.nbtapi.NBTItem;
2223
import lombok.AllArgsConstructor;
2324
import org.bukkit.inventory.ItemStack;
2425
import org.bukkit.plugin.Plugin;
@@ -27,6 +28,8 @@
2728
import org.maxgamer.quickshop.QuickShop;
2829
import org.maxgamer.quickshop.api.shop.ItemMatcher;
2930

31+
import java.util.Objects;
32+
3033
/**
3134
* A simple impl for ItemMatcher
3235
*
@@ -72,6 +75,19 @@ public boolean matches(@Nullable ItemStack original, @Nullable ItemStack tester)
7275
if ((original == null) != (tester == null)) {
7376
return false;
7477
}
78+
79+
original = original.clone();
80+
original.setAmount(1);
81+
tester = tester.clone();
82+
tester.setAmount(1);
83+
84+
if (plugin.getNbtapi() != null) {
85+
NBTItem nbtItemOriginal = new NBTItem(original);
86+
NBTItem nbtItemTester = new NBTItem(tester);
87+
if (Objects.equals(nbtItemOriginal.getString("shopId"), nbtItemTester.getString("shopId"))) {
88+
return true;
89+
}
90+
}
7591
return tester.isSimilar(original);
7692
}
7793
}

src/main/java/org/maxgamer/quickshop/util/matcher/item/QuickShopItemMatcherImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.maxgamer.quickshop.util.matcher.item;
2121

2222
import de.leonhard.storage.sections.FlatFileSection;
23+
import de.tr7zw.nbtapi.NBTItem;
2324
import lombok.AllArgsConstructor;
2425
import org.bukkit.attribute.Attribute;
2526
import org.bukkit.block.ShulkerBox;
@@ -144,6 +145,14 @@ public boolean matches(@Nullable ItemStack requireStack, @Nullable ItemStack giv
144145
givenStack = givenStack.clone();
145146
givenStack.setAmount(1);
146147

148+
if (plugin.getNbtapi() != null) {
149+
NBTItem nbtItemOriginal = new NBTItem(requireStack);
150+
NBTItem nbtItemTester = new NBTItem(givenStack);
151+
if (Objects.equals(nbtItemOriginal.getString("shopId"), nbtItemTester.getString("shopId"))) {
152+
return true;
153+
}
154+
}
155+
147156
if (workType == 1) {
148157
return requireStack.isSimilar(givenStack);
149158
}

0 commit comments

Comments
 (0)