|
20 | 20 | import org.jetbrains.annotations.Nullable; |
21 | 21 |
|
22 | 22 | import java.util.ArrayList; |
| 23 | +import java.util.HashSet; |
23 | 24 | import java.util.List; |
| 25 | +import java.util.Set; |
24 | 26 |
|
25 | 27 | public class NPCUtil { |
26 | 28 | @NotNull |
@@ -63,64 +65,28 @@ public static List<NPC> getNPCsInRange(MovecraftLocation center) { |
63 | 65 | return result; |
64 | 66 | } |
65 | 67 |
|
66 | | - @Nullable |
67 | | - public static TradableGUIItem getUnloadItem(@NotNull List<NPC> nearbyMerchants, ItemStack compareItem, Main dtlTradersPlugin) { |
68 | | - TradableGUIItem result = null; |
69 | | - for (NPC cargoMerchant : nearbyMerchants) { |
70 | | - if (result != null) |
71 | | - break; |
72 | | - String guiName = cargoMerchant.getTrait(TraderTrait.class).getGUIName(); |
73 | | - AGUI gui = dtlTradersPlugin.getGuiListService().getGUI(guiName); |
74 | | - TradeGUI tradeGUI = (TradeGUI) gui; |
75 | | - result = null; |
76 | | - for (TradeGUIPage page : tradeGUI.getPages()) { |
77 | | - if (page == null) continue; |
78 | | - for (AGUIItem tempItem : page.getItems("sell")) { |
79 | | - if (!(tempItem instanceof TradableGUIItem)) continue; |
80 | | - if (tempItem.getMainItem().isSimilar(compareItem)) { |
81 | | - if (tempItem.getMainItem().getAmount() > 1) |
82 | | - continue; |
83 | | - result = (TradableGUIItem) tempItem; |
84 | | - break; |
85 | | - } |
86 | | - } |
87 | | - if (result == null || result.getTradePrice() == 0.0) { |
88 | | - return null; |
89 | | - } |
90 | | - } |
91 | | - } |
92 | | - return result; |
93 | | - } |
94 | | - |
95 | | - @Nullable |
96 | | - public static TradableGUIItem getLoadItem(@NotNull List<NPC> nearbyMerchants, ItemStack compareItem, Main dtlTradersPlugin) { |
97 | | - TradableGUIItem result = null; |
98 | | - for (NPC cargoMerchant : nearbyMerchants) { |
99 | | - String guiName = cargoMerchant.getTrait(TraderTrait.class).getGUIName(); |
| 68 | + @NotNull |
| 69 | + public static Set<TradableGUIItem> getItems(@NotNull List<NPC> merchants, ItemStack item, Main dtlTradersPlugin, String shopMode) { |
| 70 | + Set<TradableGUIItem> result = new HashSet<>(); |
| 71 | + for (NPC merchant : merchants) { |
| 72 | + String guiName = merchant.getTrait(TraderTrait.class).getGUIName(); |
100 | 73 | AGUI gui = dtlTradersPlugin.getGuiListService().getGUI(guiName); |
101 | | - TradeGUI tradeGUI = (TradeGUI) gui; |
102 | | - for (TradeGUIPage page : tradeGUI.getPages()) { |
103 | | - if (page == null) |
104 | | - continue; |
| 74 | + if (!(gui instanceof TradeGUI)) |
| 75 | + continue; |
105 | 76 |
|
106 | | - for (AGUIItem tempItem : page.getItems("buy")) { |
107 | | - if (!(tempItem instanceof TradableGUIItem)) |
| 77 | + for (TradeGUIPage page : ((TradeGUI) gui).getPages()) { |
| 78 | + for (AGUIItem guiItem : page.getItems(shopMode)) { |
| 79 | + if (!(guiItem instanceof TradableGUIItem tradableItem)) |
| 80 | + continue; |
| 81 | + if (!guiItem.getMainItem().isSimilar(item) || guiItem.getMainItem().getAmount() > 1) |
108 | 82 | continue; |
109 | 83 |
|
110 | | - TradableGUIItem tradeItem = (TradableGUIItem) tempItem; |
111 | | - if (tradeItem.getMainItem().isSimilar(compareItem)) { |
112 | | - if (tempItem.getMainItem().getAmount() > 1) |
113 | | - continue; |
114 | | - |
115 | | - result = tradeItem; |
116 | | - break; |
| 84 | + result.add(tradableItem); |
| 85 | + if (Config.debug) { |
| 86 | + CargoMain.getInstance().getLogger().info("Found for $" + tradableItem.getTradePrice() + " in " + merchant.getId() + "/" + page.getPageName()); |
117 | 87 | } |
118 | 88 | } |
119 | | - if (result != null) |
120 | | - break; |
121 | 89 | } |
122 | | - if (result != null) |
123 | | - break; |
124 | 90 | } |
125 | 91 | return result; |
126 | 92 | } |
|
0 commit comments