Skip to content

Commit 36f231c

Browse files
Merge branch 'inventory-builder-improvements' into new-command-system-1.20.6-2
2 parents 818e6ac + 1cc40fc commit 36f231c

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.wizardlybump17.wlib.inventory.item.InventoryNavigator;
77
import com.wizardlybump17.wlib.inventory.item.ItemButton;
88
import com.wizardlybump17.wlib.inventory.listener.InventoryListener;
9+
import com.wizardlybump17.wlib.item.ItemBuilder;
910
import com.wizardlybump17.wlib.util.MapUtils;
1011
import com.wizardlybump17.wlib.util.ObjectUtil;
1112
import lombok.AccessLevel;
@@ -105,14 +106,45 @@ public PaginatedInventoryBuilder shapeReplacements(@NonNull Map<Character, ItemB
105106
return this;
106107
}
107108

108-
public @NotNull PaginatedInventoryBuilder setReplacementActionByCustomData(@NotNull String key, @Nullable Object value, @NotNull ClickAction action) {
109+
public @NotNull PaginatedInventoryBuilder setReplacementActionByCustomData(@NotNull Object key, @Nullable Object value, @NotNull ClickAction action) {
109110
for (ItemButton button : shapeReplacements.values()) {
110111
if (Objects.equals(button.getCustomData().get(key), value))
111112
button.setClickAction(action);
112113
}
113114
return this;
114115
}
115116

117+
public @NotNull PaginatedInventoryBuilder setReplacementItemStackByCustomData(@NotNull Object key, @Nullable Object value, @NotNull Supplier<ItemStack> itemSupplier) {
118+
for (ItemButton button : shapeReplacements.values())
119+
if (Objects.equals(button.getCustomData().get(key), value))
120+
button.setItem(itemSupplier);
121+
return this;
122+
}
123+
124+
public @NotNull PaginatedInventoryBuilder setReplacementItemStackByCustomData(@NotNull Object key, @Nullable Object value, @NotNull ItemStack item) {
125+
Supplier<ItemStack> itemSupplier = () -> item;
126+
for (ItemButton button : shapeReplacements.values())
127+
if (Objects.equals(button.getCustomData().get(key), value))
128+
button.setItem(itemSupplier);
129+
return this;
130+
}
131+
132+
public @NotNull PaginatedInventoryBuilder setReplacementItemByCustomData(@NotNull Object key, @Nullable Object value, @NotNull Supplier<ItemBuilder> itemSupplier) {
133+
Supplier<ItemStack> itemStackSupplier = () -> itemSupplier.get().build();
134+
for (ItemButton button : shapeReplacements.values())
135+
if (Objects.equals(button.getCustomData().get(key), value))
136+
button.setItem(itemStackSupplier);
137+
return this;
138+
}
139+
140+
public @NotNull PaginatedInventoryBuilder setReplacementItemByCustomData(@NotNull Object key, @Nullable Object value, @NotNull ItemBuilder item) {
141+
Supplier<ItemStack> itemSupplier = item::build;
142+
for (ItemButton button : shapeReplacements.values())
143+
if (Objects.equals(button.getCustomData().get(key), value))
144+
button.setItem(itemSupplier);
145+
return this;
146+
}
147+
116148
public PaginatedInventoryBuilder content(@Nullable List<ItemButton> content) {
117149
this.content = content == null ? new ArrayList<>() : content;
118150
checkNullContent();

0 commit comments

Comments
 (0)