mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add enchant limit config gui.
also fixed some style & grammar issue
This commit is contained in:
parent
3abb1129ee
commit
c0762d862e
10 changed files with 200 additions and 38 deletions
|
|
@ -9,8 +9,9 @@ import org.bukkit.Material;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xyz.alexcrea.cuanvil.gui.config.BasicConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.config.EnchantLimitConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
|
@ -45,8 +46,19 @@ public class MainConfigGui extends ChestGui {
|
|||
basicConfigMeta.setLore(Collections.singletonList("\u00A77Click here to open basic config menu"));
|
||||
basicConfigItemstack.setItemMeta(basicConfigMeta);
|
||||
|
||||
GuiItem placeholder1 = GuiGlobalItems.goToGuiItem(basicConfigItemstack, BasicConfigGui.INSTANCE);
|
||||
pane.bindItem('1', placeholder1);
|
||||
GuiItem basicConfigItem = GuiGlobalItems.goToGuiItem(basicConfigItemstack, BasicConfigGui.INSTANCE);
|
||||
pane.bindItem('1', basicConfigItem);
|
||||
|
||||
// enchant level limit item
|
||||
ItemStack enchantLimitItemstack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
ItemMeta enchantLimitMeta = enchantLimitItemstack.getItemMeta();
|
||||
|
||||
enchantLimitMeta.setDisplayName("\u00A7aEnchantment Level Limit");
|
||||
enchantLimitMeta.setLore(Collections.singletonList("\u00A77Click here to open enchantment level limit menu"));
|
||||
enchantLimitItemstack.setItemMeta(enchantLimitMeta);
|
||||
|
||||
GuiItem enchantLimitItem = GuiGlobalItems.goToGuiItem(enchantLimitItemstack, EnchantLimitConfigGui.INSTANCE);
|
||||
pane.bindItem('2', enchantLimitItem);
|
||||
|
||||
// WIP configuration items
|
||||
ItemStack wipItemstack = new ItemStack(Material.BARRIER);
|
||||
|
|
@ -54,14 +66,11 @@ public class MainConfigGui extends ChestGui {
|
|||
wipMeta.setDisplayName("\u00A7cWIP");
|
||||
wipItemstack.setItemMeta(wipMeta);
|
||||
|
||||
GuiItem wip2 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
GuiItem wip3 = 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 wip6 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||
|
||||
|
||||
pane.bindItem('2', wip2);
|
||||
pane.bindItem('3', wip3);
|
||||
pane.bindItem('4', wip4);
|
||||
pane.bindItem('5', wip5);
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ import xyz.alexcrea.cuanvil.gui.MainConfigGui;
|
|||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
}
|
||||
|
||||
private BasicConfigGui(){
|
||||
super(3, "\u00A78Basic Config GUI", CustomAnvil.instance);
|
||||
super(3, "\u00A78Basic Config", CustomAnvil.instance);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -85,13 +85,13 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
|
||||
// item repair cost
|
||||
range = ConfigOptions.REPAIR_COST_RANGE;
|
||||
this.itemRepairCost = IntSettingsGui.factory("\u00A78Item repair cost", this,
|
||||
this.itemRepairCost = IntSettingsGui.factory("\u00A78Item Repair Cost", this,
|
||||
ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.DEFAULT_ITEM_REPAIR_COST,
|
||||
1, 5, 10, 50, 100);
|
||||
|
||||
// unit repair cost
|
||||
this.unitRepairCost = IntSettingsGui.factory("\u00A78Unit repair cost", this,
|
||||
this.unitRepairCost = IntSettingsGui.factory("\u00A78Unit Repair Cost", this,
|
||||
ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.DEFAULT_UNIT_REPAIR_COST,
|
||||
1, 5, 10, 50, 100);
|
||||
|
|
@ -105,12 +105,11 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
|
||||
// sacrifice illegal enchant cost
|
||||
range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE;
|
||||
this.sacrificeIllegalEnchantCost = IntSettingsGui.factory("\u00A78Sacrifice Illegal enchant Cost", this,
|
||||
this.sacrificeIllegalEnchantCost = IntSettingsGui.factory("\u00A78Sacrifice Illegal Enchant Cost", this,
|
||||
ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, range.getFirst(),range.getLast(),
|
||||
ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST,
|
||||
1, 5, 10, 50, 100);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
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.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.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class EnchantLimitConfigGui extends ValueUpdatableGui {
|
||||
|
||||
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();
|
||||
|
||||
static {
|
||||
INSTANCE.init();
|
||||
}
|
||||
|
||||
private EnchantLimitConfigGui(){
|
||||
super(6, "\u00A78Enchantment Level Limit", CustomAnvil.instance);
|
||||
|
||||
}
|
||||
|
||||
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<>();
|
||||
|
||||
for (Enchantment enchant : Enchantment.values()) {
|
||||
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
|
||||
public void updateGuiValues() {
|
||||
// probably not the most efficient but hey ! it do the work
|
||||
// TODO optimise one day.. maybe
|
||||
|
||||
this.filledEnchant.clear();
|
||||
|
||||
for (IntSettingsGui.IntSettingFactory inventoryFactory : this.bookItemFactoryList) {
|
||||
|
||||
GuiItem item = GuiGlobalItems.intSettingGuiItem(inventoryFactory,
|
||||
Material.ENCHANTED_BOOK,
|
||||
inventoryFactory.getTitle());
|
||||
this.filledEnchant.addItem(item);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ import io.delilaheve.CustomAnvil;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -139,6 +139,11 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
|||
this.defaultVal = defaultVal;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public boolean getConfiguredValue(){
|
||||
return this.config.getConfig().getBoolean(this.configPath, this.defaultVal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -168,12 +168,12 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
if(stepValue == step){
|
||||
stepMat = Material.GREEN_STAINED_GLASS_PANE;
|
||||
stepName.append('a');
|
||||
stepLore = Collections.singletonList("\u00A77Value is changing by a step of "+stepValue);
|
||||
stepLore = Collections.singletonList("\u00A77Value is changing by "+stepValue);
|
||||
clickEvent = GuiGlobalActions.stayInPlace;
|
||||
}else{
|
||||
stepMat = Material.RED_STAINED_GLASS_PANE;
|
||||
stepName.append('c');
|
||||
stepLore = Collections.singletonList("\u00A77Click here to change the value of a step by "+stepValue);
|
||||
stepLore = Collections.singletonList("\u00A77Click here to change the value by "+stepValue);
|
||||
clickEvent = updateStepValue(stepValue);
|
||||
}
|
||||
stepName.append("Step of: ").append(stepValue);
|
||||
|
|
@ -239,6 +239,11 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
this.steps = steps;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public int getConfiguredValue(){
|
||||
return this.config.getConfig().getInt(this.configPath, this.defaultVal);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.alexcrea.cuanvil.gui.utils;
|
||||
package xyz.alexcrea.cuanvil.gui.util;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.alexcrea.cuanvil.gui.utils;
|
||||
package xyz.alexcrea.cuanvil.gui.util;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
|
|
@ -12,6 +12,7 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
|||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.util.StringUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
|
@ -97,21 +98,44 @@ public class GuiGlobalItems {
|
|||
private static final String SETTING_ITEM_LORE_PREFIX = "\u00A77value: ";
|
||||
|
||||
public static GuiItem boolSettingGuiItem(
|
||||
@NotNull BoolSettingsGui.BoolSettingFactory factory
|
||||
@NotNull BoolSettingsGui.BoolSettingFactory factory,
|
||||
@NotNull String name
|
||||
){
|
||||
// Get item properties
|
||||
boolean value = factory.getConfiguredValue();
|
||||
|
||||
Material itemMat;
|
||||
StringBuilder partOfItemName = new StringBuilder("\u00A7");
|
||||
StringBuilder itemName = new StringBuilder("\u00A7");
|
||||
if(value){
|
||||
itemMat = Material.GREEN_TERRACOTTA;
|
||||
partOfItemName.append("a");
|
||||
itemName.append("a");
|
||||
}else{
|
||||
itemMat = Material.RED_TERRACOTTA;
|
||||
partOfItemName.append("c");
|
||||
itemName.append("c");
|
||||
}
|
||||
return createGuiItemFromProperties(factory, itemMat, partOfItemName, value);
|
||||
itemName.append(name);
|
||||
|
||||
return createGuiItemFromProperties(factory, itemMat, itemName, value);
|
||||
}
|
||||
|
||||
public static GuiItem boolSettingGuiItem(
|
||||
@NotNull BoolSettingsGui.BoolSettingFactory factory
|
||||
){
|
||||
String configPath = getConfigNameFromPath(factory.getConfigPath());
|
||||
return boolSettingGuiItem(factory, StringUtil.snakeToUpperSpacedCase(configPath));
|
||||
}
|
||||
|
||||
|
||||
public static GuiItem intSettingGuiItem(
|
||||
@NotNull IntSettingsGui.IntSettingFactory factory,
|
||||
@NotNull Material itemMat,
|
||||
@NotNull String name
|
||||
){
|
||||
// Get item properties
|
||||
int value = factory.getConfiguredValue();
|
||||
StringBuilder itemName = new StringBuilder("\u00A7a").append(name);
|
||||
|
||||
return createGuiItemFromProperties(factory, itemMat, itemName, value);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -119,26 +143,20 @@ public class GuiGlobalItems {
|
|||
@NotNull IntSettingsGui.IntSettingFactory factory,
|
||||
@NotNull Material itemMat
|
||||
){
|
||||
// Get item properties
|
||||
int value = factory.getConfiguredValue();
|
||||
StringBuilder partOfItemName = new StringBuilder("\u00A7a");
|
||||
|
||||
return createGuiItemFromProperties(factory, itemMat, partOfItemName, value);
|
||||
String configPath = getConfigNameFromPath(factory.getConfigPath());
|
||||
return intSettingGuiItem(factory, itemMat, StringUtil.snakeToUpperSpacedCase(configPath));
|
||||
}
|
||||
|
||||
private static GuiItem createGuiItemFromProperties(
|
||||
@NotNull AbstractSettingGui.SettingGuiFactory factory,
|
||||
@NotNull Material itemMat,
|
||||
@NotNull StringBuilder partOfItemName,
|
||||
@NotNull StringBuilder itemName,
|
||||
@NotNull Object value
|
||||
){
|
||||
partOfItemName.append(getConfigNameFromPath(factory.getConfigPath()));
|
||||
|
||||
// Create item
|
||||
ItemStack item = new ItemStack(itemMat);
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
itemMeta.setDisplayName(partOfItemName.toString());
|
||||
itemMeta.setDisplayName(itemName.toString());
|
||||
itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX+value));
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
|
|
@ -151,4 +169,5 @@ public class GuiGlobalItems {
|
|||
// indexOfDot == -1 (not fond) imply indexOfDot+1 = 0. substring will keep the full path as expected
|
||||
return path.substring(indexOfDot+1);
|
||||
}
|
||||
|
||||
}
|
||||
21
src/main/java/xyz/alexcrea/cuanvil/util/StringUtil.java
Normal file
21
src/main/java/xyz/alexcrea/cuanvil/util/StringUtil.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package xyz.alexcrea.cuanvil.util;
|
||||
|
||||
public class StringUtil {
|
||||
|
||||
//we assume snake_cased_string is in snake case
|
||||
public static String snakeToUpperSpacedCase(String snake_cased_string){
|
||||
if(snake_cased_string.contentEquals("")) return "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (String word : snake_cased_string.split("_")) {
|
||||
result.append(" ");
|
||||
if(word.isEmpty()) continue;
|
||||
char firstChar = word.charAt(0);
|
||||
|
||||
result.append(Character.toUpperCase(firstChar));
|
||||
result.append(word.substring(1));
|
||||
}
|
||||
return result.substring(1);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue