mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
progress on enchantment cost config gui
This commit is contained in:
parent
f8b41dd86c
commit
f7841ce562
9 changed files with 248 additions and 103 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.config.EnchantCostConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.EnchantLimitConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.EnchantLimitConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
|
|
@ -60,18 +61,27 @@ public class MainConfigGui extends ChestGui {
|
||||||
GuiItem enchantLimitItem = GuiGlobalItems.goToGuiItem(enchantLimitItemstack, EnchantLimitConfigGui.INSTANCE);
|
GuiItem enchantLimitItem = GuiGlobalItems.goToGuiItem(enchantLimitItemstack, EnchantLimitConfigGui.INSTANCE);
|
||||||
pane.bindItem('2', enchantLimitItem);
|
pane.bindItem('2', enchantLimitItem);
|
||||||
|
|
||||||
|
// enchant cost item
|
||||||
|
ItemStack enchantCostItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
||||||
|
ItemMeta enchantCostMeta = enchantCostItemstack.getItemMeta();
|
||||||
|
|
||||||
|
enchantCostMeta.setDisplayName("\u00A7aEnchantment Cost");
|
||||||
|
enchantCostMeta.setLore(Collections.singletonList("\u00A77Click here to open enchantment costs menu"));
|
||||||
|
enchantCostItemstack.setItemMeta(enchantCostMeta);
|
||||||
|
|
||||||
|
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, EnchantCostConfigGui.INSTANCE);
|
||||||
|
pane.bindItem('3', enchantCostItem);
|
||||||
|
|
||||||
// WIP configuration items
|
// WIP configuration items
|
||||||
ItemStack wipItemstack = new ItemStack(Material.BARRIER);
|
ItemStack wipItemstack = new ItemStack(Material.BARRIER);
|
||||||
ItemMeta wipMeta = wipItemstack.getItemMeta();
|
ItemMeta wipMeta = wipItemstack.getItemMeta();
|
||||||
wipMeta.setDisplayName("\u00A7cWIP");
|
wipMeta.setDisplayName("\u00A7cWIP");
|
||||||
wipItemstack.setItemMeta(wipMeta);
|
wipItemstack.setItemMeta(wipMeta);
|
||||||
|
|
||||||
GuiItem wip3 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
|
||||||
GuiItem wip4 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
GuiItem wip4 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||||
GuiItem wip5 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
GuiItem wip5 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||||
GuiItem wip6 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
GuiItem wip6 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||||
|
|
||||||
pane.bindItem('3', wip3);
|
|
||||||
pane.bindItem('4', wip4);
|
pane.bindItem('4', wip4);
|
||||||
pane.bindItem('5', wip5);
|
pane.bindItem('5', wip5);
|
||||||
pane.bindItem('6', wip6);
|
pane.bindItem('6', wip6);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.Orientable;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.Pane;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
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.util.GuiGlobalItems;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends ValueUpdatableGui {
|
||||||
|
|
||||||
|
private final static Material SECONDARY_BACKGROUND_MATERIAL = Material.BLACK_STAINED_GLASS_PANE;
|
||||||
|
|
||||||
|
protected AbstractEnchantConfigGui(String title){
|
||||||
|
super(6, title, CustomAnvil.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
PatternPane backItems;
|
||||||
|
OutlinePane filledEnchant;
|
||||||
|
protected void init(){
|
||||||
|
// Back item panel
|
||||||
|
Pattern pattern = new Pattern(
|
||||||
|
"000000000",
|
||||||
|
"000000000",
|
||||||
|
"000000000",
|
||||||
|
"000000000",
|
||||||
|
"000000000",
|
||||||
|
"B11111111"
|
||||||
|
);
|
||||||
|
backItems = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
|
||||||
|
addPane(backItems);
|
||||||
|
|
||||||
|
GuiGlobalItems.addBackItem(backItems, MainConfigGui.INSTANCE);
|
||||||
|
|
||||||
|
GuiGlobalItems.addBackgroundItem(backItems);
|
||||||
|
backItems.bindItem('1', GuiGlobalItems.backgroundItem(SECONDARY_BACKGROUND_MATERIAL));
|
||||||
|
|
||||||
|
// enchant item panel
|
||||||
|
filledEnchant = new OutlinePane(0, 0, 9, 5);
|
||||||
|
filledEnchant.align(OutlinePane.Alignment.BEGIN);
|
||||||
|
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
|
||||||
|
addPane(filledEnchant);
|
||||||
|
|
||||||
|
prepareValues();
|
||||||
|
updateGuiValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<T> bookItemFactoryList;
|
||||||
|
protected void prepareValues(){
|
||||||
|
bookItemFactoryList = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Enchantment> enchantments = Arrays.asList(Enchantment.values());
|
||||||
|
enchantments.sort(Comparator.comparing(ench -> ench.getKey().getKey()));
|
||||||
|
|
||||||
|
for (Enchantment enchant : enchantments) {
|
||||||
|
//String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||||
|
//String prettyKey = StringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
|
T factory = getFactoryFromEnchant(enchant);
|
||||||
|
/*IntSettingsGui.factory(prettyKey, this,
|
||||||
|
SECTION_NAME+'.'+key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
||||||
|
enchant.getMaxLevel(),
|
||||||
|
1, 5, 10, 50, 100);*/
|
||||||
|
|
||||||
|
bookItemFactoryList.add(factory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateGuiValues() {
|
||||||
|
// probably not the most efficient but hey ! it do the work
|
||||||
|
// TODO optimise one day.. maybe
|
||||||
|
|
||||||
|
this.filledEnchant.clear();
|
||||||
|
|
||||||
|
for (T inventoryFactory : this.bookItemFactoryList) {
|
||||||
|
|
||||||
|
GuiItem item = getItemFromFactory(inventoryFactory);
|
||||||
|
/*GuiGlobalItems.intSettingGuiItem(inventoryFactory,
|
||||||
|
Material.ENCHANTED_BOOK,
|
||||||
|
inventoryFactory.getTitle());*/
|
||||||
|
this.filledEnchant.addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract T getFactoryFromEnchant(Enchantment enchant);
|
||||||
|
|
||||||
|
public abstract GuiItem getItemFromFactory(T inventoryFactory);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -60,12 +60,12 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
||||||
|
|
||||||
protected void prepareValues(){
|
protected void prepareValues(){
|
||||||
// limit repair item
|
// limit repair item
|
||||||
this.limitRepairFactory = BoolSettingsGui.factory("\u00A78Limit Repair Cost ?",this,
|
this.limitRepairFactory = BoolSettingsGui.boolFactory("\u00A78Limit Repair Cost ?",this,
|
||||||
ConfigOptions.LIMIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_LIMIT_REPAIR);
|
ConfigOptions.LIMIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_LIMIT_REPAIR);
|
||||||
|
|
||||||
// rename cost item
|
// rename cost item
|
||||||
IntRange range = ConfigOptions.REPAIR_LIMIT_RANGE;
|
IntRange range = ConfigOptions.REPAIR_LIMIT_RANGE;
|
||||||
this.repairCostFactory = IntSettingsGui.factory("\u00A78Repair Cost Limit", this,
|
this.repairCostFactory = IntSettingsGui.intFactory("\u00A78Repair Cost Limit", this,
|
||||||
ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||||
ConfigOptions.DEFAULT_LIMIT_REPAIR_VALUE,
|
ConfigOptions.DEFAULT_LIMIT_REPAIR_VALUE,
|
||||||
1, 5, 10);
|
1, 5, 10);
|
||||||
|
|
@ -80,32 +80,32 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
||||||
this.notNeededLimitValueItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
this.notNeededLimitValueItem = new GuiItem(item, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||||
|
|
||||||
// remove repair limit item
|
// remove repair limit item
|
||||||
this.removeRepairLimit = BoolSettingsGui.factory("\u00A78Remove Repair Limit ?",this,
|
this.removeRepairLimit = BoolSettingsGui.boolFactory("\u00A78Remove Repair Limit ?",this,
|
||||||
ConfigOptions.REMOVE_REPAIR_LIMIT, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_REMOVE_LIMIT);
|
ConfigOptions.REMOVE_REPAIR_LIMIT, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_REMOVE_LIMIT);
|
||||||
|
|
||||||
// item repair cost
|
// item repair cost
|
||||||
range = ConfigOptions.REPAIR_COST_RANGE;
|
range = ConfigOptions.REPAIR_COST_RANGE;
|
||||||
this.itemRepairCost = IntSettingsGui.factory("\u00A78Item Repair Cost", this,
|
this.itemRepairCost = IntSettingsGui.intFactory("\u00A78Item Repair Cost", this,
|
||||||
ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||||
ConfigOptions.DEFAULT_ITEM_REPAIR_COST,
|
ConfigOptions.DEFAULT_ITEM_REPAIR_COST,
|
||||||
1, 5, 10, 50, 100);
|
1, 5, 10, 50, 100);
|
||||||
|
|
||||||
// unit repair cost
|
// unit repair cost
|
||||||
this.unitRepairCost = IntSettingsGui.factory("\u00A78Unit Repair Cost", this,
|
this.unitRepairCost = IntSettingsGui.intFactory("\u00A78Unit Repair Cost", this,
|
||||||
ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||||
ConfigOptions.DEFAULT_UNIT_REPAIR_COST,
|
ConfigOptions.DEFAULT_UNIT_REPAIR_COST,
|
||||||
1, 5, 10, 50, 100);
|
1, 5, 10, 50, 100);
|
||||||
|
|
||||||
// item rename cost
|
// item rename cost
|
||||||
range = ConfigOptions.ITEM_RENAME_COST_RANGE;
|
range = ConfigOptions.ITEM_RENAME_COST_RANGE;
|
||||||
this.itemRenameCost = IntSettingsGui.factory("\u00A78Rename Cost", this,
|
this.itemRenameCost = IntSettingsGui.intFactory("\u00A78Rename Cost", this,
|
||||||
ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||||
ConfigOptions.DEFAULT_ITEM_RENAME_COST,
|
ConfigOptions.DEFAULT_ITEM_RENAME_COST,
|
||||||
1, 5, 10, 50, 100);
|
1, 5, 10, 50, 100);
|
||||||
|
|
||||||
// sacrifice illegal enchant cost
|
// sacrifice illegal enchant cost
|
||||||
range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE;
|
range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE;
|
||||||
this.sacrificeIllegalEnchantCost = IntSettingsGui.factory("\u00A78Sacrifice Illegal Enchant Cost", this,
|
this.sacrificeIllegalEnchantCost = IntSettingsGui.intFactory("\u00A78Sacrifice Illegal Enchant Cost", this,
|
||||||
ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||||
ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST,
|
ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST,
|
||||||
1, 5, 10, 50, 100);
|
1, 5, 10, 50, 100);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
|
import xyz.alexcrea.cuanvil.util.StringUtil;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSettingsGui.EnchantCostSettingFactory> {
|
||||||
|
|
||||||
|
private final static String SECTION_NAME = "enchant_values";
|
||||||
|
|
||||||
|
public final static EnchantCostConfigGui INSTANCE = new EnchantCostConfigGui();
|
||||||
|
|
||||||
|
static {
|
||||||
|
INSTANCE.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EnchantCostConfigGui() {
|
||||||
|
super("\u00A78Enchantment Level Limit");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnchantCostSettingsGui.EnchantCostSettingFactory getFactoryFromEnchant(Enchantment enchant) {
|
||||||
|
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||||
|
String prettyKey = StringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
|
return EnchantCostSettingsGui.enchFactory(prettyKey+" Level Cost", this,
|
||||||
|
SECTION_NAME+'.'+key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
||||||
|
enchant.getMaxLevel(),4,
|
||||||
|
1, 10, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuiItem getItemFromFactory(EnchantCostSettingsGui.EnchantCostSettingFactory factory) {
|
||||||
|
// Get item properties
|
||||||
|
int itemCost = factory.getConfiguredValue();
|
||||||
|
int bookCost = factory.getConfiguredBookValue();
|
||||||
|
StringBuilder itemName = new StringBuilder("\u00A7a").append(factory.getTitle());
|
||||||
|
// Create item
|
||||||
|
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
|
||||||
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
|
||||||
|
// Edit name and lore
|
||||||
|
itemMeta.setDisplayName(itemName.toString());
|
||||||
|
itemMeta.setLore(Arrays.asList(
|
||||||
|
"\u00A77Book Cost: " + bookCost,
|
||||||
|
"\u00A77Item Cost: " + itemCost));
|
||||||
|
|
||||||
|
item.setItemMeta(itemMeta);
|
||||||
|
|
||||||
|
return GuiGlobalItems.openSettingGuiItem(item, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,27 +1,18 @@
|
||||||
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.pane.Orientable;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.Pane;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
|
||||||
import io.delilaheve.CustomAnvil;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.util.StringUtil;
|
import xyz.alexcrea.cuanvil.util.StringUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class EnchantLimitConfigGui extends ValueUpdatableGui {
|
public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsGui.IntSettingFactory> {
|
||||||
|
|
||||||
private final static String SECTION_NAME = "enchant_limits";
|
private final static String SECTION_NAME = "enchant_limits";
|
||||||
private final static Material SECONDARY_BACKGROUND_MATERIAL = Material.BLACK_STAINED_GLASS_PANE;
|
|
||||||
|
|
||||||
public final static EnchantLimitConfigGui INSTANCE = new EnchantLimitConfigGui();
|
public final static EnchantLimitConfigGui INSTANCE = new EnchantLimitConfigGui();
|
||||||
|
|
||||||
|
|
@ -29,77 +20,27 @@ public class EnchantLimitConfigGui extends ValueUpdatableGui {
|
||||||
INSTANCE.init();
|
INSTANCE.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private EnchantLimitConfigGui(){
|
private EnchantLimitConfigGui() {
|
||||||
super(6, "\u00A78Enchantment Level Limit", CustomAnvil.instance);
|
super("\u00A78Enchantment Level Limit");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternPane backItems;
|
|
||||||
OutlinePane filledEnchant;
|
|
||||||
private void init(){
|
|
||||||
// Back item panel
|
|
||||||
Pattern pattern = new Pattern(
|
|
||||||
"000000000",
|
|
||||||
"000000000",
|
|
||||||
"000000000",
|
|
||||||
"000000000",
|
|
||||||
"000000000",
|
|
||||||
"B11111111"
|
|
||||||
);
|
|
||||||
backItems = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
|
|
||||||
addPane(backItems);
|
|
||||||
|
|
||||||
GuiGlobalItems.addBackItem(backItems, MainConfigGui.INSTANCE);
|
|
||||||
|
|
||||||
GuiGlobalItems.addBackgroundItem(backItems);
|
|
||||||
backItems.bindItem('1', GuiGlobalItems.backgroundItem(SECONDARY_BACKGROUND_MATERIAL));
|
|
||||||
|
|
||||||
// enchant item panel
|
|
||||||
filledEnchant = new OutlinePane(0, 0, 9, 5);
|
|
||||||
filledEnchant.align(OutlinePane.Alignment.BEGIN);
|
|
||||||
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
|
|
||||||
addPane(filledEnchant);
|
|
||||||
|
|
||||||
prepareValues();
|
|
||||||
updateGuiValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<IntSettingsGui.IntSettingFactory> bookItemFactoryList;
|
|
||||||
protected void prepareValues(){
|
|
||||||
bookItemFactoryList = new ArrayList<>();
|
|
||||||
|
|
||||||
List<Enchantment> enchantments = Arrays.asList(Enchantment.values());
|
|
||||||
enchantments.sort(Comparator.comparing(ench -> ench.getKey().getKey()));
|
|
||||||
|
|
||||||
for (Enchantment enchant : enchantments) {
|
|
||||||
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
|
||||||
String prettyKey = StringUtil.snakeToUpperSpacedCase(key);
|
|
||||||
|
|
||||||
IntSettingsGui.IntSettingFactory factory = IntSettingsGui.factory(prettyKey, this,
|
|
||||||
SECTION_NAME+'.'+key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
|
||||||
enchant.getMaxLevel(),
|
|
||||||
1, 5, 10, 50, 100);
|
|
||||||
|
|
||||||
bookItemFactoryList.add(factory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateGuiValues() {
|
public IntSettingsGui.IntSettingFactory getFactoryFromEnchant(Enchantment enchant) {
|
||||||
// probably not the most efficient but hey ! it do the work
|
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||||
// TODO optimise one day.. maybe
|
String prettyKey = StringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
this.filledEnchant.clear();
|
return IntSettingsGui.intFactory(prettyKey+" Level Limit", this,
|
||||||
|
SECTION_NAME+'.'+key, ConfigHolder.DEFAULT_CONFIG, 0, 255,
|
||||||
for (IntSettingsGui.IntSettingFactory inventoryFactory : this.bookItemFactoryList) {
|
enchant.getMaxLevel(),
|
||||||
|
1, 5, 10, 50, 100);
|
||||||
GuiItem item = GuiGlobalItems.intSettingGuiItem(inventoryFactory,
|
|
||||||
Material.ENCHANTED_BOOK,
|
|
||||||
inventoryFactory.getTitle());
|
|
||||||
this.filledEnchant.addItem(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
@Override
|
||||||
|
public GuiItem getItemFromFactory(IntSettingsGui.IntSettingFactory inventoryFactory) {
|
||||||
|
return GuiGlobalItems.intSettingGuiItem(inventoryFactory,
|
||||||
|
Material.ENCHANTED_BOOK,
|
||||||
|
inventoryFactory.getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
||||||
return now != before;
|
return now != before;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BoolSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
public static BoolSettingFactory boolFactory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigHolder config,
|
String configPath, ConfigHolder config,
|
||||||
boolean defaultVal){
|
boolean defaultVal){
|
||||||
return new BoolSettingFactory(
|
return new BoolSettingFactory(
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ 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.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
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;
|
||||||
|
|
@ -15,6 +16,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class EnchantCostSettingsGui extends IntSettingsGui {
|
public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
|
|
@ -33,20 +35,43 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
|
|
||||||
this.step = holder.steps[0];
|
this.step = holder.steps[0];
|
||||||
|
|
||||||
updateValueDisplay();
|
initStaticItem();
|
||||||
initStepsValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pattern getGuiPattern() {
|
public Pattern getGuiPattern() {
|
||||||
return new Pattern(
|
return new Pattern(
|
||||||
"abc1bMVP0",
|
"abc12MVP0",
|
||||||
"D001s-v+0",
|
"D0013-v+0",
|
||||||
"B0010000S"
|
"B0010000S"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initStaticItem() {
|
||||||
|
PatternPane pane = getPane();
|
||||||
|
|
||||||
|
// book display
|
||||||
|
ItemStack bookItemstack = new ItemStack(Material.BOOK);
|
||||||
|
ItemMeta bookMeta = bookItemstack.getItemMeta();
|
||||||
|
|
||||||
|
bookMeta.setDisplayName("\u00A7aEnchantment by Book Cost");
|
||||||
|
bookMeta.setLore(Collections.singletonList("\u00A77Value on the right represent cost of enchantment for every level if combined by a book"));
|
||||||
|
bookItemstack.setItemMeta(bookMeta);
|
||||||
|
|
||||||
|
// sword display
|
||||||
|
ItemStack swordItemstack = new ItemStack(Material.WOODEN_SWORD);
|
||||||
|
ItemMeta swordMeta = swordItemstack.getItemMeta();
|
||||||
|
swordMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||||
|
|
||||||
|
swordMeta.setDisplayName("\u00A7aEnchantment by Sword Cost");
|
||||||
|
swordMeta.setLore(Collections.singletonList("\u00A77Value on the right represent cost of enchantment for every level if combined by an item other than a book"));
|
||||||
|
swordItemstack.setItemMeta(swordMeta);
|
||||||
|
|
||||||
|
pane.bindItem('1', GuiGlobalItems.backgroundItem(Material.BLACK_STAINED_GLASS_PANE));
|
||||||
|
pane.bindItem('2', new GuiItem(bookItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||||
|
pane.bindItem('3', new GuiItem(swordItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void prepareReturnToDefault(){
|
protected void prepareReturnToDefault(){
|
||||||
ItemStack item = new ItemStack(Material.COMMAND_BLOCK);
|
ItemStack item = new ItemStack(Material.COMMAND_BLOCK);
|
||||||
|
|
@ -153,9 +178,10 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSave() {
|
public boolean onSave() {
|
||||||
|
System.out.println("ON SAVE");
|
||||||
if(TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
if(TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE){
|
||||||
holder.config.getConfig().set(holder.configPath+ITEM_PATH, now);
|
holder.config.getConfig().set(holder.configPath+ITEM_PATH, now);
|
||||||
holder.config.getConfig().set(holder.configPath+BOOK_PATH, now);
|
holder.config.getConfig().set(holder.configPath+BOOK_PATH, nowBook);
|
||||||
return holder.config.saveToDisk(TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
return holder.config.saveToDisk(TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -166,7 +192,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
return super.hadChange() || nowBook != beforeBook;
|
return super.hadChange() || nowBook != beforeBook;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnchantCostSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
public static EnchantCostSettingFactory enchFactory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigHolder config,
|
String configPath, ConfigHolder config,
|
||||||
int min, int max, int defaultItemVal, int defaultBookVal,
|
int min, int max, int defaultItemVal, int defaultBookVal,
|
||||||
int... steps){
|
int... steps){
|
||||||
|
|
@ -212,7 +238,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
// Get value or default
|
// Get value or default
|
||||||
int nowItem = getConfiguredValue();
|
int nowItem = getConfiguredValue();
|
||||||
// Get value or default
|
// Get value or default
|
||||||
int nowBook = getConfiguredValue();
|
int nowBook = getConfiguredBookValue();
|
||||||
// create new gui
|
// create new gui
|
||||||
return new EnchantCostSettingsGui(this, nowItem, nowBook);
|
return new EnchantCostSettingsGui(this, nowItem, nowBook);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
return now != before;
|
return now != before;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IntSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
public static IntSettingFactory intFactory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigHolder config,
|
String configPath, ConfigHolder config,
|
||||||
int min, int max, int defaultVal, int... steps){
|
int min, int max, int defaultVal, int... steps){
|
||||||
return new IntSettingFactory(
|
return new IntSettingFactory(
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ public class GuiGlobalItems {
|
||||||
return new GuiItem(item, GuiGlobalActions.openSettingGuiAction(factory), CustomAnvil.instance);
|
return new GuiItem(item, GuiGlobalActions.openSettingGuiAction(factory), CustomAnvil.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String SETTING_ITEM_LORE_PREFIX = "\u00A77value: ";
|
public static final String SETTING_ITEM_LORE_PREFIX = "\u00A77value: ";
|
||||||
|
|
||||||
public static GuiItem boolSettingGuiItem(
|
public static GuiItem boolSettingGuiItem(
|
||||||
@NotNull BoolSettingsGui.BoolSettingFactory factory,
|
@NotNull BoolSettingsGui.BoolSettingFactory factory,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue