Skip to content

Commit aa73a22

Browse files
"Fix" State
if the key ever changed to the value, the value would never change, these changes will fix it and "somewhat" this code has optimizations
1 parent a0428a4 commit aa73a22

File tree

1 file changed

+7
-5
lines changed
  • core/src/main/java/me/flame/menus/items/states

1 file changed

+7
-5
lines changed

core/src/main/java/me/flame/menus/items/states/State.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
* @author FlameyosFlow
3232
* @since 2.0.0
3333
*/
34-
@ApiStatus.Experimental
3534
public class State {
3635
private final TextHolder key;
3736
private final MenuItem item;
3837
private final Supplier<TextHolder> value;
38+
private final Lore originalLore;
3939

4040
private State(TextHolder key, Supplier<TextHolder> value, @NotNull MenuItem item) {
4141
this.item = item;
@@ -50,6 +50,7 @@ private State(TextHolder key, Supplier<TextHolder> value, @NotNull MenuItem item
5050

5151
this.key = key;
5252
this.value = value;
53+
this.originalLore = new Lore(stack.getItemMeta());
5354
}
5455

5556
@Contract(value = "_, _, _ -> new", pure = true)
@@ -100,12 +101,13 @@ private State(TextHolder key, Supplier<TextHolder> value, @NotNull MenuItem item
100101
@Contract(pure = true)
101102
public void update() {
102103
ItemStack otherItem = item.getItemStack();
103-
ItemMeta meta = Preconditions.checkNotNull(otherItem.getItemMeta());
104-
Lore lore = new Lore(meta);
104+
Lore lore = new Lore(originalLore);
105105

106106
int size = lore.size();
107-
for (int stringIndex = 0; stringIndex < size; stringIndex++) replaceWithKey(stringIndex, lore, key, value);
108-
lore.toItemLore(item.getItemStack());
107+
for (int stringIndex = 0; stringIndex < size; stringIndex++) {
108+
replaceWithKey(stringIndex, lore, key, value);
109+
}
110+
lore.toItemLore(otherItem);
109111
}
110112

111113
private static void replaceWithKey(int stringIndex, @NotNull Lore list, TextHolder key, Supplier<TextHolder> value) {

0 commit comments

Comments
 (0)