mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
create interface SettingGui and used it insted of AstractSettingGui.
This commit is contained in:
parent
db1dfdf144
commit
33fac3eed4
11 changed files with 58 additions and 39 deletions
|
|
@ -6,7 +6,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
|
||||
import java.util.Collections;
|
||||
|
|
@ -18,7 +18,7 @@ import java.util.function.Consumer;
|
|||
*
|
||||
* @param <T> Type of the factory of the type of setting the gui should edit.
|
||||
*/
|
||||
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends SettingGuiListConfigGui<WrappedEnchantment, T> implements ValueUpdatableGui {
|
||||
public abstract class AbstractEnchantConfigGui<T extends SettingGui.SettingGuiFactory> extends SettingGuiListConfigGui<WrappedEnchantment, T> implements ValueUpdatableGui {
|
||||
|
||||
/**
|
||||
* Constructor for a gui displaying available enchantment to edit a enchantment setting.
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.SettingGuiFactory> extends ElementListConfigGui< T >{
|
||||
public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGuiFactory> extends ElementListConfigGui< T >{
|
||||
|
||||
protected HashMap<T, GuiItem> guiItemMap;
|
||||
protected HashMap<T, S> factoryMap;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
|||
/**
|
||||
* An instance gui used to edit a setting.
|
||||
*/
|
||||
public abstract class AbstractSettingGui extends ChestGui {
|
||||
public abstract class AbstractSettingGui extends ChestGui implements SettingGui {
|
||||
|
||||
protected static final String CLICK_LORE = "\u00A77Click Here to change the value";
|
||||
|
||||
|
|
@ -95,27 +95,12 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
*/
|
||||
protected abstract Pattern getGuiPattern();
|
||||
|
||||
/**
|
||||
* Called when the associated setting need to be saved.
|
||||
*
|
||||
* @return true if the save was successful. false otherwise
|
||||
*/
|
||||
public abstract boolean onSave();
|
||||
|
||||
/**
|
||||
* If this function return true
|
||||
* the gui assume the associated setting can be saved.
|
||||
*
|
||||
* @return true if there is a change to the setting. false otherwise
|
||||
*/
|
||||
public abstract boolean hadChange();
|
||||
|
||||
/**
|
||||
* Most of the time a setting gui will be called from a global gui.
|
||||
* <p>
|
||||
* It is better to keep a factory that hold setting data than find what parameters to use every time.
|
||||
*/
|
||||
public abstract static class SettingGuiFactory {
|
||||
public abstract static class SettingGuiFactory implements SettingGui.SettingGuiFactory {
|
||||
@NotNull
|
||||
protected String configPath;
|
||||
@NotNull
|
||||
|
|
@ -148,11 +133,5 @@ public abstract class AbstractSettingGui extends ChestGui {
|
|||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a gui using setting parameters and current setting value.
|
||||
*
|
||||
* @return A new instance of the implemented setting gui.
|
||||
*/
|
||||
public abstract AbstractSettingGui create();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||
|
||||
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.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
|
|
@ -233,7 +234,7 @@ public class BoolSettingsGui extends AbstractSettingGui {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingGui create() {
|
||||
public Gui create() {
|
||||
// Get current value or default
|
||||
boolean now = getConfiguredValue();
|
||||
// create new gui
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||
|
||||
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.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
|
|
@ -471,7 +472,7 @@ public class DoubleSettingGui extends AbstractSettingGui {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingGui create() {
|
||||
public Gui create() {
|
||||
// Get value or default
|
||||
BigDecimal now = getConfiguredValue();
|
||||
// create new gui
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||
|
||||
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.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
|
|
@ -321,7 +322,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingGui create() {
|
||||
public Gui create() {
|
||||
// Get value or default
|
||||
int nowItem = getConfiguredValue();
|
||||
// create new gui
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||
|
||||
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.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
|
|
@ -370,7 +371,7 @@ public class IntSettingsGui extends AbstractSettingGui {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingGui create() {
|
||||
public Gui create() {
|
||||
// Get value or default
|
||||
int now = getConfiguredValue();
|
||||
// create new gui
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||
|
||||
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.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
|
|
@ -240,7 +241,7 @@ public class ItemSettingGui extends AbstractSettingGui {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingGui create() {
|
||||
public Gui create() {
|
||||
// Get current value or default
|
||||
ItemStack now = getConfiguredValue();
|
||||
// create new gui
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
|
||||
public interface SettingGui {
|
||||
|
||||
/**
|
||||
* Called when the associated setting need to be saved.
|
||||
*
|
||||
* @return true if the save was successful. false otherwise
|
||||
*/
|
||||
boolean onSave();
|
||||
|
||||
/**
|
||||
* If this function return true
|
||||
* the gui assume the associated setting can be saved.
|
||||
*
|
||||
* @return true if there is a change to the setting. false otherwise
|
||||
*/
|
||||
boolean hadChange();
|
||||
|
||||
interface SettingGuiFactory {
|
||||
|
||||
/**
|
||||
* Create a gui using setting parameters and current setting value.
|
||||
*
|
||||
* @return A new instance of the implemented setting gui.
|
||||
*/
|
||||
Gui create();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||
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.SettingGui;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
|
@ -17,12 +18,12 @@ import java.util.function.Consumer;
|
|||
*/
|
||||
public class GuiGlobalActions {
|
||||
|
||||
public final static String NO_EDIT_PERM = "§cYou do not have permission to edit the config";
|
||||
public static final String NO_EDIT_PERM = "§cYou do not have permission to edit the config";
|
||||
|
||||
/**
|
||||
* A Consumer that should be used if the item goal is to do nothing on click.
|
||||
*/
|
||||
public final static Consumer<InventoryClickEvent> stayInPlace = (event) -> event.setCancelled(true);
|
||||
public static final Consumer<InventoryClickEvent> stayInPlace = event -> event.setCancelled(true);
|
||||
|
||||
/**
|
||||
* Create a consumer to create and open a new GUI.
|
||||
|
|
@ -80,7 +81,7 @@ public class GuiGlobalActions {
|
|||
* @param factory The setting gui factory.
|
||||
* @return A consumer to create and open a new setting GUI.
|
||||
*/
|
||||
public static @NotNull Consumer<InventoryClickEvent> openSettingGuiAction(AbstractSettingGui.SettingGuiFactory factory) {
|
||||
public static @NotNull Consumer<InventoryClickEvent> openSettingGuiAction(SettingGui.SettingGuiFactory factory) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
Gui gui = factory.create();
|
||||
|
|
@ -119,7 +120,7 @@ public class GuiGlobalActions {
|
|||
* @return A consumer to open a global GUI.
|
||||
*/
|
||||
public static @NotNull Consumer<InventoryClickEvent> saveSettingAction(
|
||||
@NotNull AbstractSettingGui setting,
|
||||
@NotNull SettingGui setting,
|
||||
@NotNull ValueUpdatableGui goal) {
|
||||
return event -> {
|
||||
event.setCancelled(true);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
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.SettingGui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -132,7 +133,7 @@ public class GuiGlobalItems {
|
|||
* @return A save setting item.
|
||||
*/
|
||||
public static GuiItem saveItem(
|
||||
@NotNull AbstractSettingGui setting,
|
||||
@NotNull SettingGui setting,
|
||||
@NotNull ValueUpdatableGui goal) {
|
||||
|
||||
ItemStack item = new ItemStack(DEFAULT_SAVE_ITEM);
|
||||
|
|
@ -179,7 +180,7 @@ public class GuiGlobalItems {
|
|||
*/
|
||||
public static GuiItem openSettingGuiItem(
|
||||
@NotNull ItemStack item,
|
||||
@NotNull AbstractSettingGui.SettingGuiFactory factory
|
||||
@NotNull SettingGui.SettingGuiFactory factory
|
||||
) {
|
||||
return new GuiItem(item, GuiGlobalActions.openSettingGuiAction(factory), CustomAnvil.instance);
|
||||
}
|
||||
|
|
@ -199,7 +200,7 @@ public class GuiGlobalItems {
|
|||
* @return A formatted GuiItem that will create and open a GUI for the setting.
|
||||
*/
|
||||
public static GuiItem createGuiItemFromProperties(
|
||||
@NotNull AbstractSettingGui.SettingGuiFactory factory,
|
||||
@NotNull SettingGui.SettingGuiFactory factory,
|
||||
@NotNull Material itemMat,
|
||||
@NotNull StringBuilder itemName,
|
||||
@NotNull Object value,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue