mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
update globaly visible menu on value update
This commit is contained in:
parent
0b11f5b66f
commit
3afe786b38
9 changed files with 59 additions and 31 deletions
|
|
@ -9,6 +9,7 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.BasicConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.BasicConfigGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||||
|
|
||||||
public class MainConfigGui extends ChestGui {
|
public class MainConfigGui extends ChestGui {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.gui;
|
|
||||||
|
|
||||||
public interface UpdatableGlobalGui {
|
|
||||||
|
|
||||||
void updateGuiForAll();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder;
|
||||||
|
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 ValueUpdatableGui(int rows, @NotNull String title, @NotNull Plugin plugin) {
|
||||||
|
super(rows, title, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValueUpdatableGui(int rows, @NotNull TextHolder title, @NotNull Plugin plugin) {
|
||||||
|
super(rows, title, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void updateGuiValues();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config;
|
package xyz.alexcrea.cuanvil.gui.config;
|
||||||
|
|
||||||
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.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;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import xyz.alexcrea.cuanvil.gui.GuiGlobalItems;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
|
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||||
|
|
||||||
public class BasicConfigGui extends ChestGui {
|
public class BasicConfigGui extends ValueUpdatableGui {
|
||||||
|
|
||||||
public final static BasicConfigGui INSTANCE = new BasicConfigGui();
|
public final static BasicConfigGui INSTANCE = new BasicConfigGui();
|
||||||
|
|
||||||
|
|
@ -26,18 +26,25 @@ public class BasicConfigGui extends ChestGui {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PatternPane pane;
|
||||||
private void init(){
|
private void init(){
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
"000000000",
|
"000000000",
|
||||||
"012000000",
|
"012000000",
|
||||||
"B00000000"
|
"B00000000"
|
||||||
);
|
);
|
||||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
addPane(pane);
|
addPane(pane);
|
||||||
|
|
||||||
GuiGlobalItems.addBackItem(pane, MainConfigGui.INSTANCE);
|
GuiGlobalItems.addBackItem(pane, MainConfigGui.INSTANCE);
|
||||||
GuiGlobalItems.addBackgroundItem(pane);
|
GuiGlobalItems.addBackgroundItem(pane);
|
||||||
|
|
||||||
|
updateGuiValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateGuiValues() {
|
||||||
|
// Update item with value
|
||||||
ItemStack setting1Item = new ItemStack(Material.STONE);
|
ItemStack setting1Item = new ItemStack(Material.STONE);
|
||||||
AbstractSettingGui.SettingGuiFactory factory1 = IntSettingsGui.factory( "Test GUI", this, "test", CustomAnvil.instance.getConfig(), 0,42,2,1);
|
AbstractSettingGui.SettingGuiFactory factory1 = IntSettingsGui.factory( "Test GUI", this, "test", CustomAnvil.instance.getConfig(), 0,42,2,1);
|
||||||
GuiItem setting1 = GuiGlobalItems.openSettingGuiItem(setting1Item, factory1);
|
GuiItem setting1 = GuiGlobalItems.openSettingGuiItem(setting1Item, factory1);
|
||||||
|
|
@ -46,6 +53,8 @@ public class BasicConfigGui extends ChestGui {
|
||||||
BoolSettingsGui.BoolSettingFactory factory2 = BoolSettingsGui.factory("Test Gui bool",this, "test2", CustomAnvil.instance.getConfig(), false);
|
BoolSettingsGui.BoolSettingFactory factory2 = BoolSettingsGui.factory("Test Gui bool",this, "test2", CustomAnvil.instance.getConfig(), false);
|
||||||
GuiItem setting2 = GuiGlobalItems.boolSettingGuiItem(factory2);
|
GuiItem setting2 = GuiGlobalItems.boolSettingGuiItem(factory2);
|
||||||
pane.bindItem('2', setting2);
|
pane.bindItem('2', setting2);
|
||||||
|
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||||
import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder;
|
import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder;
|
||||||
import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder;
|
import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder;
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
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;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.gui.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -18,17 +18,18 @@ public abstract class AbstractSettingGui extends ChestGui {
|
||||||
|
|
||||||
protected final static List<String> CLICK_LORE = Collections.singletonList("\u00A77Click Here to change the value");
|
protected final static List<String> CLICK_LORE = Collections.singletonList("\u00A77Click Here to change the value");
|
||||||
|
|
||||||
public AbstractSettingGui(int rows, @NotNull TextHolder title, Gui parent) {
|
private PatternPane pane;
|
||||||
|
|
||||||
|
public AbstractSettingGui(int rows, @NotNull TextHolder title, ValueUpdatableGui parent) {
|
||||||
super(rows, title, CustomAnvil.instance);
|
super(rows, title, CustomAnvil.instance);
|
||||||
initBase(parent);
|
initBase(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractSettingGui(int rows, @NotNull String title, Gui parent) {
|
public AbstractSettingGui(int rows, @NotNull String title, ValueUpdatableGui parent) {
|
||||||
this(rows, StringHolder.of(title), parent);
|
this(rows, StringHolder.of(title), parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PatternPane pane;
|
private void initBase(ValueUpdatableGui parent){
|
||||||
private void initBase(Gui parent){
|
|
||||||
Pattern pattern = getGuiPattern();
|
Pattern pattern = getGuiPattern();
|
||||||
pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
|
pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
|
||||||
addPane(pane);
|
addPane(pane);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
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;
|
||||||
|
|
@ -11,6 +10,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BoolSettingFactory factory(@NotNull String title, Gui parent,
|
public static BoolSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigurationSection section,
|
String configPath, ConfigurationSection section,
|
||||||
boolean defaultVal){
|
boolean defaultVal){
|
||||||
return new BoolSettingFactory(
|
return new BoolSettingFactory(
|
||||||
|
|
@ -90,10 +90,10 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
|
|
||||||
public static class BoolSettingFactory extends SettingGuiFactory{
|
public static class BoolSettingFactory extends SettingGuiFactory{
|
||||||
@NotNull String title; Gui parent;
|
@NotNull String title; ValueUpdatableGui parent;
|
||||||
boolean defaultVal;
|
boolean defaultVal;
|
||||||
|
|
||||||
private BoolSettingFactory(@NotNull String title, Gui parent,
|
private BoolSettingFactory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigurationSection section,
|
String configPath, ConfigurationSection section,
|
||||||
boolean defaultVal){
|
boolean defaultVal){
|
||||||
super(configPath, section);
|
super(configPath, section);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
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;
|
||||||
|
|
@ -11,8 +10,9 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.gui.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SettingGuiFactory factory(@NotNull String title, Gui parent,
|
public static SettingGuiFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigurationSection section,
|
String configPath, ConfigurationSection section,
|
||||||
int min, int max, int defaultVal, int... steps){
|
int min, int max, int defaultVal, int... steps){
|
||||||
return new IntSettingFactory(
|
return new IntSettingFactory(
|
||||||
|
|
@ -117,10 +117,10 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
|
|
||||||
public static class IntSettingFactory extends SettingGuiFactory{
|
public static class IntSettingFactory extends SettingGuiFactory{
|
||||||
@NotNull String title; Gui parent;
|
@NotNull String title; ValueUpdatableGui parent;
|
||||||
int min; int max; int defaultVal; int[] steps;
|
int min; int max; int defaultVal; int[] steps;
|
||||||
|
|
||||||
private IntSettingFactory(@NotNull String title, Gui parent,
|
private IntSettingFactory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigurationSection section,
|
String configPath, ConfigurationSection section,
|
||||||
int min, int max, int defaultVal, int... steps){
|
int min, int max, int defaultVal, int... steps){
|
||||||
super(configPath, section);
|
super(configPath, section);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package xyz.alexcrea.cuanvil.gui;
|
package xyz.alexcrea.cuanvil.gui.utils;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
@ -55,11 +56,13 @@ public class GuiGlobalActions {
|
||||||
|
|
||||||
public static @NotNull Consumer<InventoryClickEvent> saveSettingAction(
|
public static @NotNull Consumer<InventoryClickEvent> saveSettingAction(
|
||||||
@NotNull AbstractSettingGui setting,
|
@NotNull AbstractSettingGui setting,
|
||||||
@NotNull Gui goal) {
|
@NotNull ValueUpdatableGui goal) {
|
||||||
return event -> {
|
return event -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
// Save setting
|
// Save setting
|
||||||
setting.onSave();
|
setting.onSave();
|
||||||
|
// Update gui for the one who have it open
|
||||||
|
goal.updateGuiValues();
|
||||||
// Then show
|
// Then show
|
||||||
goal.show(event.getWhoClicked());
|
goal.show(event.getWhoClicked());
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package xyz.alexcrea.cuanvil.gui;
|
package xyz.alexcrea.cuanvil.gui.utils;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
|
|
@ -8,6 +8,7 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||||
|
|
||||||
|
|
@ -60,7 +61,7 @@ public class GuiGlobalItems {
|
||||||
private static final Material DEFAULT_SAVE_ITEM = Material.LIME_TERRACOTTA;
|
private static final Material DEFAULT_SAVE_ITEM = Material.LIME_TERRACOTTA;
|
||||||
public static GuiItem saveItem(
|
public static GuiItem saveItem(
|
||||||
@NotNull AbstractSettingGui setting,
|
@NotNull AbstractSettingGui setting,
|
||||||
@NotNull Gui goal){
|
@NotNull ValueUpdatableGui goal){
|
||||||
|
|
||||||
ItemStack item = new ItemStack(DEFAULT_SAVE_ITEM);
|
ItemStack item = new ItemStack(DEFAULT_SAVE_ITEM);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue