Abstracted away ValueUpdatableGui.

This commit is contained in:
alexcrea 2024-06-17 16:21:26 +02:00
parent fc033460b4
commit 502aa64f50
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
8 changed files with 42 additions and 27 deletions

View file

@ -1,20 +1,11 @@
package xyz.alexcrea.cuanvil.gui; package xyz.alexcrea.cuanvil.gui;
import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
public abstract class ValueUpdatableGui extends ChestGui { public interface ValueUpdatableGui {
public ValueUpdatableGui(int rows, @NotNull String title, @NotNull Plugin plugin) { void updateGuiValues();
super(rows, title, plugin);
}
public ValueUpdatableGui(int rows, @NotNull TextHolder title, @NotNull Plugin plugin) { Gui getConnectedGui();
super(rows, title, plugin);
}
public abstract void updateGuiValues();
} }

View file

@ -1,6 +1,8 @@
package xyz.alexcrea.cuanvil.gui.config.global; package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.Orientable; import com.github.stefvanschie.inventoryframework.pane.Orientable;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane; import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import io.delilaheve.CustomAnvil; import io.delilaheve.CustomAnvil;
@ -17,7 +19,7 @@ import java.util.List;
* *
* @param <T> Type of the factory of the type of setting the gui should edit. * @param <T> Type of the factory of the type of setting the gui should edit.
*/ */
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends ValueUpdatableGui { public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends ChestGui implements ValueUpdatableGui {
/** /**
* Constructor for a gui displaying available enchantment to edit a enchantment setting. * Constructor for a gui displaying available enchantment to edit a enchantment setting.
@ -78,7 +80,10 @@ public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.Sett
update(); update();
} }
@Override
public Gui getConnectedGui() {
return this;
}
public abstract T getFactoryFromEnchant(WrappedEnchantment enchant); public abstract T getFactoryFromEnchant(WrappedEnchantment enchant);

View file

@ -1,6 +1,8 @@
package xyz.alexcrea.cuanvil.gui.config.global; package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.PatternPane; import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import io.delilaheve.CustomAnvil; import io.delilaheve.CustomAnvil;
@ -27,7 +29,7 @@ import java.util.Collections;
/** /**
* Global config to edit basic basic settings. * Global config to edit basic basic settings.
*/ */
public class BasicConfigGui extends ValueUpdatableGui { public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
private static BasicConfigGui INSTANCE; private static BasicConfigGui INSTANCE;
@ -253,4 +255,9 @@ public class BasicConfigGui extends ValueUpdatableGui {
update(); update();
} }
@Override
public Gui getConnectedGui() {
return this;
}
} }

View file

@ -22,9 +22,9 @@ import java.util.Locale;
*/ */
public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSettingsGui.EnchantCostSettingFactory> { public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSettingsGui.EnchantCostSettingFactory> {
private final static String SECTION_NAME = "enchant_values"; private static final String SECTION_NAME = "enchant_values";
public final static EnchantCostConfigGui INSTANCE = new EnchantCostConfigGui(); public static final EnchantCostConfigGui INSTANCE = new EnchantCostConfigGui();
static { static {
INSTANCE.init(); INSTANCE.init();

View file

@ -1,6 +1,8 @@
package xyz.alexcrea.cuanvil.gui.config.list; package xyz.alexcrea.cuanvil.gui.config.list;
import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.Orientable; import com.github.stefvanschie.inventoryframework.pane.Orientable;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane; import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import com.github.stefvanschie.inventoryframework.pane.Pane; import com.github.stefvanschie.inventoryframework.pane.Pane;
@ -23,13 +25,13 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
public abstract class ElementListConfigGui< T > extends ValueUpdatableGui { public abstract class ElementListConfigGui< T > extends ChestGui implements ValueUpdatableGui {
private final String namePrefix; private final String namePrefix;
protected PatternPane backgroundPane; protected PatternPane backgroundPane;
public ElementListConfigGui(@NotNull String title) { protected ElementListConfigGui(@NotNull String title) {
super(6, title, CustomAnvil.instance); super(6, title, CustomAnvil.instance);
this.namePrefix = title; this.namePrefix = title;
@ -304,4 +306,9 @@ public abstract class ElementListConfigGui< T > extends ValueUpdatableGui {
reloadValues(); reloadValues();
} }
@Override
public Gui getConnectedGui() {
return this;
}
} }

View file

@ -1,15 +1,16 @@
package xyz.alexcrea.cuanvil.gui.config.list.elements; package xyz.alexcrea.cuanvil.gui.config.list.elements;
import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import io.delilaheve.CustomAnvil; import io.delilaheve.CustomAnvil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
public abstract class MappedToListSubSettingGui extends ValueUpdatableGui implements ElementMappedToListGui { public abstract class MappedToListSubSettingGui extends ChestGui implements ValueUpdatableGui, ElementMappedToListGui {
private final GuiItem item; private final GuiItem item;
public MappedToListSubSettingGui( protected MappedToListSubSettingGui(
GuiItem item, GuiItem item,
int rows, int rows,
@NotNull String title) { @NotNull String title) {
@ -27,5 +28,9 @@ public abstract class MappedToListSubSettingGui extends ValueUpdatableGui implem
return this; return this;
} }
@Override
public Gui getConnectedGui() {
return this;
}
} }

View file

@ -17,7 +17,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
*/ */
public abstract class AbstractSettingGui extends ChestGui { public abstract class AbstractSettingGui extends ChestGui {
protected final static String CLICK_LORE = "\u00A77Click Here to change the value"; protected static final String CLICK_LORE = "\u00A77Click Here to change the value";
private PatternPane pane; private PatternPane pane;
@ -28,7 +28,7 @@ public abstract class AbstractSettingGui extends ChestGui {
* @param title Title of this gui. * @param title Title of this gui.
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
*/ */
public AbstractSettingGui(int rows, @NotNull TextHolder title, ValueUpdatableGui parent) { protected AbstractSettingGui(int rows, @NotNull TextHolder title, ValueUpdatableGui parent) {
super(rows, title, CustomAnvil.instance); super(rows, title, CustomAnvil.instance);
initBase(parent); initBase(parent);
} }
@ -40,7 +40,7 @@ public abstract class AbstractSettingGui extends ChestGui {
* @param title Title of this gui. * @param title Title of this gui.
* @param parent Parent gui to go back when completed. * @param parent Parent gui to go back when completed.
*/ */
public AbstractSettingGui(int rows, @NotNull String title, ValueUpdatableGui parent) { protected AbstractSettingGui(int rows, @NotNull String title, ValueUpdatableGui parent) {
this(rows, StringHolder.of(title), parent); this(rows, StringHolder.of(title), parent);
} }
@ -57,7 +57,7 @@ public abstract class AbstractSettingGui extends ChestGui {
pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern); pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
addPane(pane); addPane(pane);
GuiGlobalItems.addBackItem(pane, parent); GuiGlobalItems.addBackItem(pane, parent.getConnectedGui());
GuiGlobalItems.addBackgroundItem(pane); GuiGlobalItems.addBackgroundItem(pane);
saveItem = GuiGlobalItems.saveItem(this, parent); saveItem = GuiGlobalItems.saveItem(this, parent);

View file

@ -138,7 +138,7 @@ public class GuiGlobalActions {
// Update gui for those who have it open. // Update gui for those who have it open.
goal.updateGuiValues(); goal.updateGuiValues();
// Then show // Then show
goal.show(player); goal.getConnectedGui().show(player);
}; };
} }