mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Moved some class. Abstracted gui list elements.
This commit is contained in:
parent
57cd58657d
commit
479bd03e83
16 changed files with 79 additions and 65 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
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.gui.type.ChestGui;
|
||||||
|
|
@ -8,6 +8,7 @@ import io.delilaheve.CustomAnvil;
|
||||||
import org.bukkit.Material;
|
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.global.*;
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||||
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.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ 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 xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.list.MappedElementListConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.CustomRecipeSubSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.CustomRecipeSubSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe;
|
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
@ -41,7 +42,7 @@ public class CustomRecipeConfigGui extends MappedElementListConfigGui<AnvilCusto
|
||||||
// edit displayed item
|
// edit displayed item
|
||||||
ItemMeta meta = displaydItem.getItemMeta();
|
ItemMeta meta = displaydItem.getItemMeta();
|
||||||
|
|
||||||
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.getName()) + " \u00A7fCustom recipe");
|
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.toString()) + " \u00A7fCustom recipe");
|
||||||
meta.addItemFlags(ItemFlag.values());
|
meta.addItemFlags(ItemFlag.values());
|
||||||
|
|
||||||
boolean shouldWork = recipe.validate();
|
boolean shouldWork = recipe.validate();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.list.MappedElementListConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
@ -57,7 +58,7 @@ public class EnchantConflictGui extends MappedElementListConfigGui<EnchantConfli
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(conflict.getName()) + " \u00A7fConflict");
|
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(conflict.toString()) + " \u00A7fConflict");
|
||||||
meta.setLore(Arrays.asList(
|
meta.setLore(Arrays.asList(
|
||||||
"\u00A77Enchantment count: \u00A7e" + conflict.getEnchants().size(),
|
"\u00A77Enchantment count: \u00A7e" + conflict.getEnchants().size(),
|
||||||
"\u00A77Group count: \u00A7e" + conflict.getCantConflictGroup().getGroups().size(),
|
"\u00A77Group count: \u00A7e" + conflict.getCantConflictGroup().getGroups().size(),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
package xyz.alexcrea.cuanvil.gui.config.list;
|
||||||
|
|
||||||
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.Orientable;
|
||||||
|
|
@ -14,6 +14,7 @@ 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.ValueUpdatableGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
|
||||||
|
|
@ -22,11 +23,11 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui {
|
public abstract class ElementListConfigGui< T > extends ValueUpdatableGui {
|
||||||
|
|
||||||
private final String namePrefix;
|
private final String namePrefix;
|
||||||
|
|
||||||
public ElementListGlobalConfigGui(@NotNull String title) {
|
public ElementListConfigGui(@NotNull String title) {
|
||||||
super(6, title, CustomAnvil.instance);
|
super(6, title, CustomAnvil.instance);
|
||||||
this.namePrefix = title;
|
this.namePrefix = title;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config.list;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
|
|
||||||
|
public interface ElementMappedToListGui {
|
||||||
|
|
||||||
|
GuiItem getParentItemForThisGui();
|
||||||
|
|
||||||
|
void updateLocal();
|
||||||
|
|
||||||
|
void cleanUnused();
|
||||||
|
|
||||||
|
Gui getMappedGui();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
package xyz.alexcrea.cuanvil.gui.config.list;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
|
|
@ -7,9 +7,7 @@ import org.bukkit.entity.HumanEntity;
|
||||||
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.config.settings.subsetting.MappedToListSubSettingGui;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.interfaces.Named;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -17,7 +15,7 @@ import java.util.Locale;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public abstract class MappedElementListConfigGui< T extends Named, S extends MappedToListSubSettingGui> extends ElementListGlobalConfigGui< T > {
|
public abstract class MappedElementListConfigGui< T, S extends ElementMappedToListGui> extends ElementListConfigGui< T > {
|
||||||
|
|
||||||
|
|
||||||
protected final HashMap<T, S> elementGuiMap;
|
protected final HashMap<T, S> elementGuiMap;
|
||||||
|
|
@ -72,34 +70,34 @@ public abstract class MappedElementListConfigGui< T extends Named, S extends Map
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateGeneric(T generic, ItemStack usedItem) {
|
protected void updateGeneric(T generic, ItemStack usedItem) {
|
||||||
S gui = this.elementGuiMap.get(generic);
|
S mapElement = this.elementGuiMap.get(generic);
|
||||||
|
|
||||||
GuiItem guiItem;
|
GuiItem guiItem;
|
||||||
if (gui == null) {
|
if (mapElement == null) {
|
||||||
// Create new sub setting gui
|
// Create new sub setting mapElement
|
||||||
guiItem = new GuiItem(usedItem, CustomAnvil.instance);
|
guiItem = new GuiItem(usedItem, CustomAnvil.instance);
|
||||||
gui = newInstanceOfGui(generic, guiItem);
|
mapElement = newInstanceOfGui(generic, guiItem);
|
||||||
|
|
||||||
guiItem.setAction(GuiGlobalActions.openGuiAction(gui));
|
guiItem.setAction(GuiGlobalActions.openGuiAction(mapElement.getMappedGui()));
|
||||||
|
|
||||||
this.elementGuiMap.put(generic, gui);
|
this.elementGuiMap.put(generic, mapElement);
|
||||||
addToPage(guiItem);
|
addToPage(guiItem);
|
||||||
} else {
|
} else {
|
||||||
// Replace item with the updated one
|
// Replace item with the updated one
|
||||||
guiItem = gui.getParentItemForThisGui();
|
guiItem = mapElement.getParentItemForThisGui();
|
||||||
guiItem.setItem(usedItem);
|
guiItem.setItem(usedItem);
|
||||||
}
|
}
|
||||||
gui.updateLocal();
|
mapElement.updateLocal();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem findGuiItemForRemoval(T generic) {
|
protected GuiItem findGuiItemForRemoval(T generic) {
|
||||||
S gui = this.elementGuiMap.get(generic);
|
S mapElement = this.elementGuiMap.get(generic);
|
||||||
if (gui == null) return null;
|
if (mapElement == null) return null;
|
||||||
|
|
||||||
this.elementGuiMap.remove(generic);
|
this.elementGuiMap.remove(generic);
|
||||||
return gui.getParentItemForThisGui();
|
return mapElement.getParentItemForThisGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Consumer<String> prepareCreateItemConsumer(HumanEntity player){
|
protected Consumer<String> prepareCreateItemConsumer(HumanEntity player){
|
||||||
|
|
@ -125,7 +123,7 @@ public abstract class MappedElementListConfigGui< T extends Named, S extends Map
|
||||||
// Try to find if it already exists in a for loop
|
// Try to find if it already exists in a for loop
|
||||||
// Not the most efficient on large number of conflict, but it should not run often.
|
// Not the most efficient on large number of conflict, but it should not run often.
|
||||||
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
|
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
|
||||||
if (generic.getName().equalsIgnoreCase(message)) {
|
if (generic.toString().equalsIgnoreCase(message)) {
|
||||||
player.sendMessage("\u00A7cPlease enter a "+genericDisplayedName()+" name that do not already exist...");
|
player.sendMessage("\u00A7cPlease enter a "+genericDisplayedName()+" name that do not already exist...");
|
||||||
// wait next message.
|
// wait next message.
|
||||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
|
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
|
||||||
|
|
@ -138,7 +136,7 @@ public abstract class MappedElementListConfigGui< T extends Named, S extends Map
|
||||||
updateValueForGeneric(generic, true);
|
updateValueForGeneric(generic, true);
|
||||||
|
|
||||||
// show the new conflict config to the player
|
// show the new conflict config to the player
|
||||||
this.elementGuiMap.get(generic).show(player);
|
this.elementGuiMap.get(generic).getMappedGui().show(player);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
};
|
};
|
||||||
|
|
@ -37,7 +37,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
@NotNull CustomRecipeConfigGui parent,
|
@NotNull CustomRecipeConfigGui parent,
|
||||||
@NotNull AnvilCustomRecipe anvilRecipe,
|
@NotNull AnvilCustomRecipe anvilRecipe,
|
||||||
@NotNull GuiItem parentItemForThisGui) {
|
@NotNull GuiItem parentItemForThisGui) {
|
||||||
super(parentItemForThisGui, 3, "\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.getName()) + " \u00A78Config");
|
super(parentItemForThisGui, 3, "\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.toString()) + " \u00A78Config");
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.anvilRecipe = anvilRecipe;
|
this.anvilRecipe = anvilRecipe;
|
||||||
|
|
||||||
|
|
@ -77,24 +77,24 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
|
|
||||||
IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE();
|
IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE();
|
||||||
this.exactCountFactory = BoolSettingsGui.boolFactory("\u00A78Exact count ?", this,
|
this.exactCountFactory = BoolSettingsGui.boolFactory("\u00A78Exact count ?", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe + "." + AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
AnvilCustomRecipe.Companion.getDEFAULT_EXACT_COUNT_CONFIG());
|
AnvilCustomRecipe.Companion.getDEFAULT_EXACT_COUNT_CONFIG());
|
||||||
|
|
||||||
this.xpCostFactory = IntSettingsGui.intFactory("\u00A78Recipe Xp Cost", this,
|
this.xpCostFactory = IntSettingsGui.intFactory("\u00A78Recipe Xp Cost", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.XP_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe +"."+AnvilCustomRecipe.XP_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10);
|
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10);
|
||||||
|
|
||||||
|
|
||||||
this.leftItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Left \u00A78Item", this,
|
this.leftItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Left \u00A78Item", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe + "." + AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG());
|
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG());
|
||||||
|
|
||||||
this.rightItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Right \u00A78Item", this,
|
this.rightItemFactory = ItemSettingGui.itemFactory("\u00A7eRecipe Right \u00A78Item", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.RIGHT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe + "." + AnvilCustomRecipe.RIGHT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG());
|
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG());
|
||||||
|
|
||||||
this.resultItemFactory = ItemSettingGui.itemFactory("\u00A7aRecipe Result \u00A78Item", this,
|
this.resultItemFactory = ItemSettingGui.itemFactory("\u00A7aRecipe Result \u00A78Item", this,
|
||||||
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.RESULT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
this.anvilRecipe + "." + AnvilCustomRecipe.RESULT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());
|
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
cleanUnused();
|
cleanUnused();
|
||||||
|
|
||||||
// Update config file storage
|
// Update config file storage
|
||||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(this.anvilRecipe.getName(), null);
|
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(this.anvilRecipe.toString(), null);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
|
|
@ -123,7 +123,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
return success;
|
return success;
|
||||||
};
|
};
|
||||||
|
|
||||||
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.anvilRecipe.getName()) + "\u00A7c?",
|
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.anvilRecipe.toString()) + "\u00A7c?",
|
||||||
"\u00A77Confirm that you want to delete this conflict.",
|
"\u00A77Confirm that you want to delete this conflict.",
|
||||||
this, this.parent, deleteSupplier
|
this, this.parent, deleteSupplier
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
@NotNull GuiItem parentItemForThisGui) {
|
@NotNull GuiItem parentItemForThisGui) {
|
||||||
super(parentItemForThisGui,
|
super(parentItemForThisGui,
|
||||||
3,
|
3,
|
||||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()) + " \u00A78Config");
|
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + " \u00A78Config");
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.enchantConflict = enchantConflict;
|
this.enchantConflict = enchantConflict;
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), (event) -> {
|
this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), (event) -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
EnchantSelectSettingGui enchantGui = new EnchantSelectSettingGui(
|
EnchantSelectSettingGui enchantGui = new EnchantSelectSettingGui(
|
||||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()) + " \u00A75Enchantments",
|
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + " \u00A75Enchantments",
|
||||||
this, this, 0);
|
this, this, 0);
|
||||||
enchantGui.show(event.getWhoClicked());
|
enchantGui.show(event.getWhoClicked());
|
||||||
}, CustomAnvil.instance);
|
}, CustomAnvil.instance);
|
||||||
|
|
@ -93,14 +93,14 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), (event) -> {
|
this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), (event) -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
GroupSelectSettingGui enchantGui = new GroupSelectSettingGui(
|
GroupSelectSettingGui enchantGui = new GroupSelectSettingGui(
|
||||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.getName()) + " \u00A73Groups",
|
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()) + " \u00A73Groups",
|
||||||
this, this, 0);
|
this, this, 0);
|
||||||
enchantGui.show(event.getWhoClicked());
|
enchantGui.show(event.getWhoClicked());
|
||||||
}, CustomAnvil.instance);
|
}, CustomAnvil.instance);
|
||||||
|
|
||||||
this.minBeforeActiveSettingFactory = IntSettingsGui.intFactory(
|
this.minBeforeActiveSettingFactory = IntSettingsGui.intFactory(
|
||||||
"\u00A78Minimum enchantment count",
|
"\u00A78Minimum enchantment count",
|
||||||
this, this.enchantConflict.getName() + ".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER,
|
this, this.enchantConflict + ".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER,
|
||||||
0, 255, 0, 1
|
0, 255, 0, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
cleanUnused();
|
cleanUnused();
|
||||||
|
|
||||||
// Update config file storage
|
// Update config file storage
|
||||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict.getName(), null);
|
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict.toString(), null);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
boolean success = true;
|
boolean success = true;
|
||||||
|
|
@ -140,7 +140,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
return success;
|
return success;
|
||||||
};
|
};
|
||||||
|
|
||||||
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.getName()) + "\u00A7c?",
|
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()) + "\u00A7c?",
|
||||||
"\u00A77Confirm that you want to delete this conflict.",
|
"\u00A77Confirm that you want to delete this conflict.",
|
||||||
this, this.parent, deleteSupplier
|
this, this.parent, deleteSupplier
|
||||||
);
|
);
|
||||||
|
|
@ -149,7 +149,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
@Override
|
@Override
|
||||||
public void updateGuiValues() {
|
public void updateGuiValues() {
|
||||||
// update value from config to conflict
|
// update value from config to conflict
|
||||||
int minBeforeBlock = ConfigHolder.CONFLICT_HOLDER.getConfig().getInt(this.enchantConflict.getName()+'.'+EnchantConflictManager.ENCH_MAX_PATH, 0);
|
int minBeforeBlock = ConfigHolder.CONFLICT_HOLDER.getConfig().getInt(this.enchantConflict.toString()+'.'+EnchantConflictManager.ENCH_MAX_PATH, 0);
|
||||||
this.enchantConflict.setMinBeforeBlock(minBeforeBlock);
|
this.enchantConflict.setMinBeforeBlock(minBeforeBlock);
|
||||||
|
|
||||||
// Parent should call updateLocal with this call
|
// Parent should call updateLocal with this call
|
||||||
|
|
@ -267,7 +267,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
@Override
|
@Override
|
||||||
public boolean setSelectedEnchantments(Set<Enchantment> enchantments) {
|
public boolean setSelectedEnchantments(Set<Enchantment> enchantments) {
|
||||||
if (!this.shouldWork) {
|
if (!this.shouldWork) {
|
||||||
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.getName() + " enchants but sub config is destroyed");
|
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict + " enchants but sub config is destroyed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -280,12 +280,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
for (Enchantment enchantment : enchantments) {
|
for (Enchantment enchantment : enchantments) {
|
||||||
enchantKeys[index++] = enchantment.getKey().getKey();
|
enchantKeys[index++] = enchantment.getKey().getKey();
|
||||||
}
|
}
|
||||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict.getName() + ".enchantments", enchantKeys);
|
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict + ".enchantments", enchantKeys);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
updateGuiValues();
|
updateGuiValues();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for " + this.enchantConflict.getName(), e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating enchants for " + this.enchantConflict, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -312,7 +312,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
@Override
|
@Override
|
||||||
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) {
|
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) {
|
||||||
if (!this.shouldWork) {
|
if (!this.shouldWork) {
|
||||||
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.getName() + " groups but sub config is destroyed");
|
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.toString() + " groups but sub config is destroyed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -325,12 +325,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
for (AbstractMaterialGroup group : groups) {
|
for (AbstractMaterialGroup group : groups) {
|
||||||
groupsNames[index++] = group.getName();
|
groupsNames[index++] = group.getName();
|
||||||
}
|
}
|
||||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict.getName() + ".notAffectedGroups", groupsNames);
|
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict + ".notAffectedGroups", groupsNames);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
updateGuiValues();
|
updateGuiValues();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for " + this.enchantConflict.getName(), e);
|
CustomAnvil.instance.getLogger().log(Level.WARNING, "An error occurred while updating group for " + this.enchantConflict, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save file configuration to disk
|
// Save file configuration to disk
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.settings.subsetting;
|
package xyz.alexcrea.cuanvil.gui.config.settings.subsetting;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.list.ElementMappedToListGui;
|
||||||
|
|
||||||
public abstract class MappedToListSubSettingGui extends ValueUpdatableGui {
|
public abstract class MappedToListSubSettingGui extends ValueUpdatableGui implements ElementMappedToListGui {
|
||||||
|
|
||||||
private final GuiItem item;
|
private final GuiItem item;
|
||||||
public MappedToListSubSettingGui(
|
public MappedToListSubSettingGui(
|
||||||
|
|
@ -16,13 +18,15 @@ public abstract class MappedToListSubSettingGui extends ValueUpdatableGui {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public GuiItem getParentItemForThisGui() {
|
public GuiItem getParentItemForThisGui() {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Gui getMappedGui() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void updateLocal(); // TODO
|
|
||||||
|
|
||||||
public abstract void cleanUnused(); // TODO
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.MainConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.MainConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
||||||
|
|
||||||
class EditConfigExecutor : CommandExecutor {
|
class EditConfigExecutor : CommandExecutor {
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@ package xyz.alexcrea.cuanvil.group
|
||||||
import io.delilaheve.CustomAnvil
|
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.interfaces.Named
|
|
||||||
|
|
||||||
class EnchantConflictGroup(
|
class EnchantConflictGroup(
|
||||||
private val name: String,
|
private val name: String,
|
||||||
private val cantConflict: AbstractMaterialGroup,
|
private val cantConflict: AbstractMaterialGroup,
|
||||||
var minBeforeBlock: Int
|
var minBeforeBlock: Int
|
||||||
): Named {
|
) {
|
||||||
|
|
||||||
private val enchantments = HashSet<Enchantment>()
|
private val enchantments = HashSet<Enchantment>()
|
||||||
|
|
||||||
|
|
@ -63,7 +62,7 @@ class EnchantConflictGroup(
|
||||||
return Material.ENCHANTED_BOOK
|
return Material.ENCHANTED_BOOK
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(): String {
|
override fun toString(): String {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,9 +139,9 @@ class EnchantConflictManager {
|
||||||
|
|
||||||
var result = ConflictType.NO_CONFLICT
|
var result = ConflictType.NO_CONFLICT
|
||||||
for (conflict in conflictList) {
|
for (conflict in conflictList) {
|
||||||
CustomAnvil.verboseLog("Is against ${conflict.getName()}")
|
CustomAnvil.verboseLog("Is against $conflict")
|
||||||
val conflicting = conflict.allowed(base, mat)
|
val conflicting = conflict.allowed(base, mat)
|
||||||
CustomAnvil.verboseLog("Was against ${conflict.getName()} and conflicting: $conflicting ")
|
CustomAnvil.verboseLog("Was against $conflict and conflicting: $conflicting ")
|
||||||
if (!conflicting) {
|
if (!conflicting) {
|
||||||
if (conflict.getEnchants().size <= 1) {
|
if (conflict.getEnchants().size <= 1) {
|
||||||
result = ConflictType.SMALL_CONFLICT
|
result = ConflictType.SMALL_CONFLICT
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.interfaces
|
|
||||||
|
|
||||||
interface Named {
|
|
||||||
|
|
||||||
fun getName(): String
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -5,7 +5,6 @@ import org.bukkit.configuration.ConfigurationSection
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
||||||
import xyz.alexcrea.cuanvil.interfaces.Named
|
|
||||||
|
|
||||||
class AnvilCustomRecipe(
|
class AnvilCustomRecipe(
|
||||||
private val name: String,
|
private val name: String,
|
||||||
|
|
@ -18,7 +17,7 @@ class AnvilCustomRecipe(
|
||||||
var leftItem: ItemStack?,
|
var leftItem: ItemStack?,
|
||||||
var rightItem: ItemStack?,
|
var rightItem: ItemStack?,
|
||||||
var resultItem: ItemStack?,
|
var resultItem: ItemStack?,
|
||||||
): Named {
|
) {
|
||||||
|
|
||||||
// Static config name
|
// Static config name
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -162,7 +161,7 @@ class AnvilCustomRecipe(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getName(): String {
|
override fun toString(): String {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue