Skip to content

Commit 56c9c65

Browse files
replacing items based on ItemButtons
1 parent 027476f commit 56c9c65

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

core/src/main/java/com/wizardlybump17/wlib/inventory/paginated/PaginatedInventoryBuilder.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,36 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map<Character, ItemB
170170
return this;
171171
}
172172

173+
//ItemButton
174+
175+
public @NotNull PaginatedInventoryBuilder setReplacementItemButtonByCustomData(@NotNull Object key, @Nullable Object value, @NotNull Supplier<ItemButton> itemSupplier) {
176+
ItemButton newButton = itemSupplier.get();
177+
for (Map.Entry<Character, ItemButton> entry : shapeReplacements.entrySet()) {
178+
ItemButton button = entry.getValue();
179+
if (Objects.equals(button.getCustomData().get(key), value))
180+
entry.setValue(newButton);
181+
}
182+
return this;
183+
}
184+
185+
public @NotNull PaginatedInventoryBuilder setReplacementItemButtonByCustomData(@NotNull Object key, @Nullable Object value, @NotNull ItemButton item) {
186+
for (Map.Entry<Character, ItemButton> entry : shapeReplacements.entrySet()) {
187+
ItemButton button = entry.getValue();
188+
if (Objects.equals(button.getCustomData().get(key), value))
189+
entry.setValue(item);
190+
}
191+
return this;
192+
}
193+
194+
public @NotNull PaginatedInventoryBuilder setReplacementItemButtonByCustomData(@NotNull Object key, @Nullable Object value, @NotNull Function<ItemButton, ItemButton> replacer) {
195+
for (Map.Entry<Character, ItemButton> entry : shapeReplacements.entrySet()) {
196+
ItemButton button = entry.getValue();
197+
if (Objects.equals(button.getCustomData().get(key), value))
198+
entry.setValue(replacer.apply(button));
199+
}
200+
return this;
201+
}
202+
173203
//rest of the code
174204

175205
public PaginatedInventoryBuilder content(@Nullable List<ItemButton> content) {

0 commit comments

Comments
 (0)