mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Update items and inventory names.
Fix some value not updating after config changed.
This commit is contained in:
parent
e440d05bb9
commit
c55c1c8c6a
7 changed files with 67 additions and 80 deletions
|
|
@ -89,6 +89,7 @@ public abstract class ConfigHolder {
|
|||
|
||||
// Save logic
|
||||
public boolean saveToDisk(boolean doBackup) {
|
||||
CustomAnvil.Companion.log("Saving "+getConfigFileName());
|
||||
if (doBackup) {
|
||||
if (!saveBackup()) {
|
||||
CustomAnvil.instance.getLogger().severe("Could not save backup. see above.");
|
||||
|
|
@ -110,6 +111,7 @@ public abstract class ConfigHolder {
|
|||
return false;
|
||||
}
|
||||
|
||||
CustomAnvil.Companion.log(getConfigFileName()+" saved successfully");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class CustomRecipeConfigGui extends MappedElementListConfigGui<AnvilCusto
|
|||
}
|
||||
|
||||
private CustomRecipeConfigGui() {
|
||||
super("title");
|
||||
super("Custom Recipe Config");
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +41,14 @@ public class CustomRecipeConfigGui extends MappedElementListConfigGui<AnvilCusto
|
|||
ItemMeta meta = displaydItem.getItemMeta();
|
||||
|
||||
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.getName()) + " \u00A7fCustom recipe");
|
||||
|
||||
boolean shouldWork = recipe.validate();
|
||||
|
||||
meta.setLore(Arrays.asList(
|
||||
"TODO"
|
||||
"\u00A77Should work: \u00A7"+(shouldWork ? "aYes" : "cNo"),
|
||||
"\u00A77Exact count: \u00A7"+(recipe.getExactCount() ? "aYes" : "cNo"),
|
||||
"\u00A77Recipe Xp Cost: \u00A7e"+recipe.getXpCostPerCraft()
|
||||
|
||||
));
|
||||
|
||||
displaydItem.setItemMeta(meta);
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@ import java.util.UUID;
|
|||
|
||||
public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui {
|
||||
|
||||
private final String namePrefix;
|
||||
|
||||
public ElementListGlobalConfigGui(@NotNull String title) {
|
||||
super(6, title, CustomAnvil.instance);
|
||||
this.namePrefix = title;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -229,7 +231,12 @@ public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui
|
|||
addPane(page);
|
||||
|
||||
// set title
|
||||
setTitle("Conflict Config (" + (pageID + 1) + "/" + (pages.size()) + ")");
|
||||
StringBuilder title = new StringBuilder(this.namePrefix);
|
||||
int pagesSize = this.pages.size();
|
||||
if(pagesSize > 1){
|
||||
title.append(" (").append(pageID + 1).append('/').append(pagesSize).append(')');
|
||||
}
|
||||
setTitle(title.toString());
|
||||
|
||||
super.show(humanEntity);
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
|||
@NotNull CustomRecipeConfigGui parent,
|
||||
@NotNull AnvilCustomRecipe anvilRecipe,
|
||||
@NotNull GuiItem parentItemForThisGui) {
|
||||
super(parentItemForThisGui, 3, "title");
|
||||
super(parentItemForThisGui, 3, "\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.getName()) + " \u00A78Config");
|
||||
this.parent = parent;
|
||||
this.anvilRecipe = anvilRecipe;
|
||||
|
||||
|
|
@ -76,24 +76,24 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
|||
// Displayed item will be updated later
|
||||
|
||||
IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE();
|
||||
exactCountFactory = BoolSettingsGui.boolFactory("title", this,
|
||||
this.exactCountFactory = BoolSettingsGui.boolFactory("\u00A78Exact count ?", this,
|
||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
AnvilCustomRecipe.Companion.getDEFAULT_EXACT_COUNT_CONFIG());
|
||||
|
||||
xpCostFactory = IntSettingsGui.intFactory("title", this,
|
||||
this.xpCostFactory = IntSettingsGui.intFactory("\u00A78Recipe Xp Cost", this,
|
||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.XP_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10);
|
||||
|
||||
|
||||
leftItemFactory = ItemSettingGui.itemFactory("title", this,
|
||||
this.leftItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7eLeft \u00A78Item", this,
|
||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG());
|
||||
|
||||
rightItemFactory = ItemSettingGui.itemFactory("title", this,
|
||||
this.rightItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7eLeft \u00A78Item", this,
|
||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG());
|
||||
|
||||
resultItemFactory = ItemSettingGui.itemFactory("title", this,
|
||||
this.resultItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7aResult \u00A78Item", this,
|
||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());
|
||||
}
|
||||
|
|
@ -131,83 +131,23 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
|||
|
||||
@Override
|
||||
public void updateGuiValues() {
|
||||
// update value from config to conflict
|
||||
this.anvilRecipe.updateFromFile();
|
||||
|
||||
// Parent should call updateLocal with this call
|
||||
this.parent.updateValueForGeneric(this.anvilRecipe, true);
|
||||
// Parent should call updateLocal
|
||||
}
|
||||
|
||||
public void updateLocal() {
|
||||
if (!this.shouldWork) return;
|
||||
|
||||
/*// Prepare enchantment lore
|
||||
ArrayList<String> enchantLore = new ArrayList<>();
|
||||
enchantLore.add("\u00A77Allow you to select a list of \u00A75Enchantments \u00A77that this conflict should include");
|
||||
Set<Enchantment> enchants = getSelectedEnchantments();
|
||||
if (enchants.isEmpty()) {
|
||||
enchantLore.add("\u00A77There is no included enchantment for this conflict.");
|
||||
} else {
|
||||
enchantLore.add("\u00A77List of included enchantment for this conflict:");
|
||||
Iterator<Enchantment> enchantIterator = enchants.iterator();
|
||||
GuiItem exactCountItem = GuiGlobalItems.boolSettingGuiItem(this.exactCountFactory);
|
||||
pane.bindItem('1', exactCountItem);
|
||||
|
||||
boolean greaterThanMax = enchants.size() > 5;
|
||||
int maxindex = (greaterThanMax ? 4 : enchants.size());
|
||||
for (int i = 0; i < maxindex; i++) {
|
||||
// format string like "- Fire Protection"
|
||||
String formattedName = CasedStringUtil.snakeToUpperSpacedCase(enchantIterator.next().getKey().getKey());
|
||||
enchantLore.add("\u00A77- \u00A75" + formattedName);
|
||||
}
|
||||
if (greaterThanMax) {
|
||||
enchantLore.add("\u00A77And " + (enchants.size() - 4) + " more...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Prepare group lore
|
||||
ArrayList<String> groupLore = new ArrayList<>();
|
||||
groupLore.add("\u00A77Allow you to select a list of \u00A73Groups \u00A77that this conflict should include");
|
||||
Set<AbstractMaterialGroup> grouos = getSelectedGroups();
|
||||
if (grouos.isEmpty()) {
|
||||
groupLore.add("\u00A77There is no excluded groups for this conflict.");
|
||||
} else {
|
||||
groupLore.add("\u00A77List of excluded groups for this conflict:");
|
||||
Iterator<AbstractMaterialGroup> groupIterator = grouos.iterator();
|
||||
|
||||
boolean greaterThanMax = grouos.size() > 5;
|
||||
int maxindex = (greaterThanMax ? 4 : grouos.size());
|
||||
for (int i = 0; i < maxindex; i++) {
|
||||
// format string like "- Melee Weapons"
|
||||
String formattedName = CasedStringUtil.snakeToUpperSpacedCase(groupIterator.next().getName());
|
||||
groupLore.add("\u00A77- \u00A73" + formattedName);
|
||||
|
||||
}
|
||||
if (greaterThanMax) {
|
||||
groupLore.add("\u00A77And " + (grouos.size() - 4) + " more...");
|
||||
}
|
||||
}
|
||||
|
||||
// Configure enchant setting item
|
||||
ItemStack enchantItem = this.enchantSettingItem.getItem();
|
||||
ItemMeta enchantMeta = enchantItem.getItemMeta();
|
||||
|
||||
enchantMeta.setDisplayName("\u00A7aSelect included \u00A75Enchantments \u00A7aSettings");
|
||||
enchantMeta.setLore(enchantLore);
|
||||
|
||||
enchantItem.setItemMeta(enchantMeta);
|
||||
|
||||
this.enchantSettingItem.setItem(enchantItem); // Just in case
|
||||
|
||||
// Configure group setting item
|
||||
ItemStack groupItem = this.groupSettingItem.getItem();
|
||||
ItemMeta groupMeta = groupItem.getItemMeta();
|
||||
|
||||
groupMeta.setDisplayName("\u00A7aSelect excluded \u00A73Groups \u00A7aSettings");
|
||||
groupMeta.setLore(groupLore);
|
||||
|
||||
groupItem.setItemMeta(groupMeta);
|
||||
|
||||
this.groupSettingItem.setItem(groupItem); // Just in case
|
||||
GuiItem xpCostItem = GuiGlobalItems.intSettingGuiItem(this.xpCostFactory, Material.EXPERIENCE_BOTTLE);
|
||||
pane.bindItem('2', xpCostItem);
|
||||
|
||||
|
||||
this.pane.bindItem('M', GuiGlobalItems.intSettingGuiItem(this.minBeforeActiveSettingFactory, Material.COMMAND_BLOCK));*/
|
||||
update();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,8 +148,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
|||
|
||||
@Override
|
||||
public void updateGuiValues() {
|
||||
// update value from config to conflict
|
||||
int minBeforeBlock = ConfigHolder.CONFLICT_HOLDER.getConfig().getInt(this.enchantConflict.getName()+'.'+EnchantConflictManager.ENCH_MAX_PATH, 0);
|
||||
this.enchantConflict.setMinBeforeBlock(minBeforeBlock);
|
||||
|
||||
// Parent should call updateLocal with this call
|
||||
this.parent.updateValueForGeneric(this.enchantConflict, true);
|
||||
// Parent should call updateLocal
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import xyz.alexcrea.cuanvil.interfaces.Named
|
|||
class EnchantConflictGroup(
|
||||
private val name: String,
|
||||
private val cantConflict: AbstractMaterialGroup,
|
||||
val minBeforeBlock: Int
|
||||
var minBeforeBlock: Int
|
||||
): Named {
|
||||
|
||||
private val enchantments = HashSet<Enchantment>()
|
||||
|
|
|
|||
|
|
@ -89,10 +89,38 @@ class AnvilCustomRecipe(
|
|||
|
||||
|
||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||
ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||
}
|
||||
}
|
||||
|
||||
fun updateFromFile(){
|
||||
this.exactCount = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getBoolean(
|
||||
"$name.$EXACT_COUNT_CONFIG",
|
||||
DEFAULT_EXACT_COUNT_CONFIG
|
||||
)
|
||||
|
||||
this.xpCostPerCraft = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getInt(
|
||||
"$name.$XP_COST_CONFIG",
|
||||
DEFAULT_XP_COST_CONFIG
|
||||
)
|
||||
|
||||
// Update items
|
||||
this.leftItem = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getItemStack(
|
||||
"$name.$LEFT_ITEM_CONFIG",
|
||||
DEFAULT_LEFT_ITEM_CONFIG
|
||||
)
|
||||
|
||||
this.rightItem = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getItemStack(
|
||||
"$name.$RIGHT_ITEM_CONFIG",
|
||||
DEFAULT_RIGHT_ITEM_CONFIG
|
||||
)
|
||||
|
||||
this.resultItem = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getItemStack(
|
||||
"$name.$RESULT_ITEM_CONFIG",
|
||||
DEFAULT_RESULT_ITEM_CONFIG
|
||||
)
|
||||
}
|
||||
|
||||
fun testItem(item1: ItemStack, item2: ItemStack?): Boolean {
|
||||
// We assume this function can be call only if leftItem != null
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue