mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Create global and sub setting recipe config gui.
This commit is contained in:
parent
0004f2426f
commit
e440d05bb9
13 changed files with 613 additions and 180 deletions
|
|
@ -0,0 +1,86 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.CustomRecipeSubSettingGui;
|
||||||
|
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe;
|
||||||
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CustomRecipeConfigGui extends MappedElementListConfigGui<AnvilCustomRecipe, CustomRecipeSubSettingGui> {
|
||||||
|
|
||||||
|
|
||||||
|
public final static CustomRecipeConfigGui INSTANCE = new CustomRecipeConfigGui();
|
||||||
|
|
||||||
|
static {
|
||||||
|
INSTANCE.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomRecipeConfigGui() {
|
||||||
|
super("title");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ItemStack createItemForGeneric(AnvilCustomRecipe recipe) {
|
||||||
|
// Get base item to display
|
||||||
|
ItemStack craftResultItem = recipe.getResultItem();
|
||||||
|
ItemStack displaydItem;
|
||||||
|
if(craftResultItem == null){
|
||||||
|
displaydItem = new ItemStack(Material.BARRIER);
|
||||||
|
}else{
|
||||||
|
displaydItem = craftResultItem.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
// edit displayed item
|
||||||
|
ItemMeta meta = displaydItem.getItemMeta();
|
||||||
|
|
||||||
|
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.getName()) + " \u00A7fCustom recipe");
|
||||||
|
meta.setLore(Arrays.asList(
|
||||||
|
"TODO"
|
||||||
|
));
|
||||||
|
|
||||||
|
displaydItem.setItemMeta(meta);
|
||||||
|
return displaydItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CustomRecipeSubSettingGui newInstanceOfGui(AnvilCustomRecipe generic, GuiItem item) {
|
||||||
|
return new CustomRecipeSubSettingGui(this, generic, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String genericDisplayedName() {
|
||||||
|
return "custom recipe";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AnvilCustomRecipe createAndSaveNewEmptyGeneric(String name) {
|
||||||
|
// Create new empty conflict and display it to the admin
|
||||||
|
AnvilCustomRecipe recipe = new AnvilCustomRecipe(
|
||||||
|
name,
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_EXACT_COUNT_CONFIG(),
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(),
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG(),
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG(),
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());
|
||||||
|
|
||||||
|
ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanAddNew(recipe);
|
||||||
|
|
||||||
|
// Save recipe to file
|
||||||
|
recipe.saveToFile();
|
||||||
|
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<AnvilCustomRecipe> getEveryDisplayableInstanceOfGeneric() {
|
||||||
|
return ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().getRecipeList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,8 +25,8 @@ import java.util.UUID;
|
||||||
public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui {
|
public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui {
|
||||||
|
|
||||||
|
|
||||||
public ElementListGlobalConfigGui(int rows, @NotNull String title) {
|
public ElementListGlobalConfigGui(@NotNull String title) {
|
||||||
super(rows, title, CustomAnvil.instance);
|
super(6, title, CustomAnvil.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -265,7 +265,7 @@ public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeConflict(T generic) {
|
public void removeGeneric(T generic) {
|
||||||
GuiItem item = findGuiItemForRemoval(generic);
|
GuiItem item = findGuiItemForRemoval(generic);
|
||||||
if(item == null) return;
|
if(item == null) return;
|
||||||
removeFromPage(item);
|
removeFromPage(item);
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,20 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import io.delilaheve.CustomAnvil;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
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 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.settings.subsetting.EnchantConflictSubSettingGui;
|
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
|
||||||
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;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class EnchantConflictGui extends ElementListGlobalConfigGui<EnchantConflictGroup> {
|
public class EnchantConflictGui extends MappedElementListConfigGui<EnchantConflictGroup, EnchantConflictSubSettingGui> {
|
||||||
|
|
||||||
public final static EnchantConflictGui INSTANCE = new EnchantConflictGui();
|
public final static EnchantConflictGui INSTANCE = new EnchantConflictGui();
|
||||||
|
|
||||||
|
|
@ -30,115 +22,33 @@ public class EnchantConflictGui extends ElementListGlobalConfigGui<EnchantConfli
|
||||||
INSTANCE.init();
|
INSTANCE.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final HashMap<EnchantConflictGroup, EnchantConflictSubSettingGui> conflictGuiMap;
|
|
||||||
|
|
||||||
private EnchantConflictGui() {
|
private EnchantConflictGui() {
|
||||||
super(6, "Conflict Config");
|
super( "Conflict Config");
|
||||||
this.conflictGuiMap = new HashMap<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem prepareCreateNewItem(){
|
protected EnchantConflictGroup createAndSaveNewEmptyGeneric(String name){
|
||||||
// Create new conflict item
|
|
||||||
ItemStack createItem = new ItemStack(Material.PAPER);
|
|
||||||
ItemMeta createMeta = createItem.getItemMeta();
|
|
||||||
|
|
||||||
createMeta.setDisplayName("\u00A7aCreate new conflict");
|
|
||||||
createMeta.setLore(Arrays.asList(
|
|
||||||
"\u00A77Create a new anvil restriction.",
|
|
||||||
"\u00A77You will be asked to name the conflict in chat.",
|
|
||||||
"\u00A77Then, you should edit the conflict config as you need"
|
|
||||||
));
|
|
||||||
|
|
||||||
createItem.setItemMeta(createMeta);
|
|
||||||
|
|
||||||
return new GuiItem(createItem, (clickEvent) -> {
|
|
||||||
clickEvent.setCancelled(true);
|
|
||||||
HumanEntity player = clickEvent.getWhoClicked();
|
|
||||||
|
|
||||||
// check permission
|
|
||||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
|
||||||
player.closeInventory();
|
|
||||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
player.closeInventory();
|
|
||||||
|
|
||||||
player.sendMessage("\u00A7eWrite the conflict you want to create in the chat.\n" +
|
|
||||||
"\u00A7eOr write \u00A7ccancel \u00A7eto go back to conflict config menu");
|
|
||||||
|
|
||||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player));
|
|
||||||
|
|
||||||
}, CustomAnvil.instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Consumer<String> prepareCreateItemConsumer(HumanEntity player) {
|
|
||||||
AtomicReference<Consumer<String>> selfRef = new AtomicReference<>();
|
|
||||||
Consumer<String> selfCallback = (message) -> {
|
|
||||||
if (message == null) return;
|
|
||||||
|
|
||||||
// check permission
|
|
||||||
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
|
||||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
message = message.toLowerCase(Locale.ROOT);
|
|
||||||
if ("cancel".equalsIgnoreCase(message)) {
|
|
||||||
player.sendMessage("conflict creation cancelled...");
|
|
||||||
show(player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
message = message.replace(' ', '_');
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
for (EnchantConflictGroup conflict : ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList()) {
|
|
||||||
if (conflict.getName().equalsIgnoreCase(message)) {
|
|
||||||
player.sendMessage("\u00A7cPlease enter a conflict name that do not already exist...");
|
|
||||||
// wait next message.
|
|
||||||
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new empty conflict and display it to the admin
|
// Create new empty conflict and display it to the admin
|
||||||
EnchantConflictGroup conflict = new EnchantConflictGroup(
|
EnchantConflictGroup conflict = new EnchantConflictGroup(
|
||||||
message,
|
name,
|
||||||
new IncludeGroup("new_group"),
|
new IncludeGroup("new_group"),
|
||||||
0);
|
0);
|
||||||
|
|
||||||
ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList().add(conflict);
|
ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList().add(conflict);
|
||||||
updateValueForGeneric(conflict, true);
|
|
||||||
|
|
||||||
// save empty conflict in config
|
// save empty conflict in config
|
||||||
String[] emptyStringArray = new String[0];
|
String[] emptyStringArray = new String[0];
|
||||||
|
|
||||||
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||||
config.set(message + ".enchantments", emptyStringArray);
|
config.set(name + ".enchantments", emptyStringArray);
|
||||||
config.set(message + ".notAffectedGroups", emptyStringArray);
|
config.set(name + ".notAffectedGroups", emptyStringArray);
|
||||||
config.set(message + ".maxEnchantmentBeforeConflict", 0);
|
config.set(name + ".maxEnchantmentBeforeConflict", 0);
|
||||||
|
|
||||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the new conflict config to the player
|
return conflict;
|
||||||
this.conflictGuiMap.get(conflict).show(player);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
selfRef.set(selfCallback);
|
|
||||||
return selfCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reloadValues() {
|
|
||||||
this.conflictGuiMap.forEach((conflict, gui) -> gui.cleanUnused());
|
|
||||||
this.conflictGuiMap.clear();
|
|
||||||
|
|
||||||
super.reloadValues();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -159,35 +69,13 @@ public class EnchantConflictGui extends ElementListGlobalConfigGui<EnchantConfli
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateGeneric(EnchantConflictGroup conflict, ItemStack usedItem) {
|
protected EnchantConflictSubSettingGui newInstanceOfGui(EnchantConflictGroup conflict, GuiItem item) {
|
||||||
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
return new EnchantConflictSubSettingGui(this, conflict, item);
|
||||||
|
|
||||||
GuiItem guiItem;
|
|
||||||
if (gui == null) {
|
|
||||||
// Create new sub setting gui
|
|
||||||
guiItem = new GuiItem(usedItem, CustomAnvil.instance);
|
|
||||||
gui = new EnchantConflictSubSettingGui(this, conflict, guiItem);
|
|
||||||
|
|
||||||
guiItem.setAction(GuiGlobalActions.openGuiAction(gui));
|
|
||||||
|
|
||||||
this.conflictGuiMap.put(conflict, gui);
|
|
||||||
addToPage(guiItem);
|
|
||||||
} else {
|
|
||||||
// Replace item with the updated one
|
|
||||||
guiItem = gui.getParentItemForThisGui();
|
|
||||||
guiItem.setItem(usedItem);
|
|
||||||
}
|
|
||||||
gui.updateLocal();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem findGuiItemForRemoval(EnchantConflictGroup conflict) {
|
protected String genericDisplayedName() {
|
||||||
EnchantConflictSubSettingGui gui = this.conflictGuiMap.get(conflict);
|
return "conflict";
|
||||||
if (gui == null) return null;
|
|
||||||
|
|
||||||
this.conflictGuiMap.remove(conflict);
|
|
||||||
return gui.getParentItemForThisGui();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
private void init() {
|
private void init() {
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
"I00000000",
|
"I00000000",
|
||||||
"012304560",
|
"012304567",
|
||||||
"Q00000000"
|
"Q00000000"
|
||||||
);
|
);
|
||||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
|
|
@ -70,7 +70,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, EnchantCostConfigGui.INSTANCE);
|
GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, EnchantCostConfigGui.INSTANCE);
|
||||||
pane.bindItem('3', enchantCostItem);
|
pane.bindItem('3', enchantCostItem);
|
||||||
|
|
||||||
// Enchantment Conflicts
|
// Enchantment Conflicts item
|
||||||
ItemStack EnchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
ItemStack EnchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
||||||
ItemMeta enchantConflictMeta = EnchantConflictItemstack.getItemMeta();
|
ItemMeta enchantConflictMeta = EnchantConflictItemstack.getItemMeta();
|
||||||
|
|
||||||
|
|
@ -93,6 +93,17 @@ public class MainConfigGui extends ChestGui {
|
||||||
pane.bindItem('5', wip5);
|
pane.bindItem('5', wip5);
|
||||||
pane.bindItem('6', wip6);
|
pane.bindItem('6', wip6);
|
||||||
|
|
||||||
|
// Custom recipe item
|
||||||
|
ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE);
|
||||||
|
ItemMeta customRecipeMeta = EnchantConflictItemstack.getItemMeta();
|
||||||
|
|
||||||
|
customRecipeMeta.setDisplayName("\u00A7aCustom recipes");
|
||||||
|
customRecipeMeta.setLore(Collections.singletonList("\u00A77Click here to open anvil custom recipe menu"));
|
||||||
|
customRecipeItemstack.setItemMeta(customRecipeMeta);
|
||||||
|
|
||||||
|
GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, CustomRecipeConfigGui.INSTANCE);
|
||||||
|
pane.bindItem('7', customRecipeItem);
|
||||||
|
|
||||||
// quit item
|
// quit item
|
||||||
ItemStack quitItemstack = new ItemStack(Material.BARRIER);
|
ItemStack quitItemstack = new ItemStack(Material.BARRIER);
|
||||||
ItemMeta quitMeta = quitItemstack.getItemMeta();
|
ItemMeta quitMeta = quitItemstack.getItemMeta();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,156 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
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.interfaces.Named;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public abstract class MappedElementListConfigGui< T extends Named, S extends MappedToListSubSettingGui> extends ElementListGlobalConfigGui< T > {
|
||||||
|
|
||||||
|
|
||||||
|
protected final HashMap<T, S> elementGuiMap;
|
||||||
|
public MappedElementListConfigGui(@NotNull String title) {
|
||||||
|
super(title);
|
||||||
|
this.elementGuiMap = new HashMap<>();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiItem prepareCreateNewItem(){
|
||||||
|
// Create new conflict item
|
||||||
|
ItemStack createItem = new ItemStack(Material.PAPER);
|
||||||
|
ItemMeta createMeta = createItem.getItemMeta();
|
||||||
|
|
||||||
|
createMeta.setDisplayName("\u00A7aCreate new "+genericDisplayedName());
|
||||||
|
createMeta.setLore(Arrays.asList(
|
||||||
|
"\u00A77Create a new "+genericDisplayedName()+".",
|
||||||
|
"\u00A77You will be asked to name the "+genericDisplayedName()+" in chat.",
|
||||||
|
"\u00A77Then, you should edit the "+genericDisplayedName()+" config as you need"
|
||||||
|
));
|
||||||
|
|
||||||
|
createItem.setItemMeta(createMeta);
|
||||||
|
|
||||||
|
return new GuiItem(createItem, (clickEvent) -> {
|
||||||
|
clickEvent.setCancelled(true);
|
||||||
|
HumanEntity player = clickEvent.getWhoClicked();
|
||||||
|
|
||||||
|
// check permission
|
||||||
|
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||||
|
player.closeInventory();
|
||||||
|
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
player.closeInventory();
|
||||||
|
|
||||||
|
player.sendMessage("\u00A7eWrite the "+genericDisplayedName()+" name you want to create in the chat.\n" +
|
||||||
|
"\u00A7eOr write \u00A7ccancel \u00A7eto go back to "+genericDisplayedName()+" config menu");
|
||||||
|
|
||||||
|
CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player));
|
||||||
|
|
||||||
|
}, CustomAnvil.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadValues() {
|
||||||
|
this.elementGuiMap.forEach((conflict, gui) -> gui.cleanUnused());
|
||||||
|
this.elementGuiMap.clear();
|
||||||
|
|
||||||
|
super.reloadValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateGeneric(T generic, ItemStack usedItem) {
|
||||||
|
S gui = this.elementGuiMap.get(generic);
|
||||||
|
|
||||||
|
GuiItem guiItem;
|
||||||
|
if (gui == null) {
|
||||||
|
// Create new sub setting gui
|
||||||
|
guiItem = new GuiItem(usedItem, CustomAnvil.instance);
|
||||||
|
gui = newInstanceOfGui(generic, guiItem);
|
||||||
|
|
||||||
|
guiItem.setAction(GuiGlobalActions.openGuiAction(gui));
|
||||||
|
|
||||||
|
this.elementGuiMap.put(generic, gui);
|
||||||
|
addToPage(guiItem);
|
||||||
|
} else {
|
||||||
|
// Replace item with the updated one
|
||||||
|
guiItem = gui.getParentItemForThisGui();
|
||||||
|
guiItem.setItem(usedItem);
|
||||||
|
}
|
||||||
|
gui.updateLocal();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiItem findGuiItemForRemoval(T generic) {
|
||||||
|
S gui = this.elementGuiMap.get(generic);
|
||||||
|
if (gui == null) return null;
|
||||||
|
|
||||||
|
this.elementGuiMap.remove(generic);
|
||||||
|
return gui.getParentItemForThisGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Consumer<String> prepareCreateItemConsumer(HumanEntity player){
|
||||||
|
AtomicReference<Consumer<String>> selfRef = new AtomicReference<>();
|
||||||
|
Consumer<String> selfCallback = (message) -> {
|
||||||
|
if (message == null) return;
|
||||||
|
|
||||||
|
// check permission
|
||||||
|
if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
|
||||||
|
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
message = message.toLowerCase(Locale.ROOT);
|
||||||
|
if ("cancel".equalsIgnoreCase(message)) {
|
||||||
|
player.sendMessage(genericDisplayedName()+" creation cancelled...");
|
||||||
|
show(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
message = message.replace(' ', '_');
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
for (T generic : getEveryDisplayableInstanceOfGeneric()) {
|
||||||
|
if (generic.getName().equalsIgnoreCase(message)) {
|
||||||
|
player.sendMessage("\u00A7cPlease enter a "+genericDisplayedName()+" name that do not already exist...");
|
||||||
|
// wait next message.
|
||||||
|
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T generic = createAndSaveNewEmptyGeneric(message);
|
||||||
|
|
||||||
|
updateValueForGeneric(generic, true);
|
||||||
|
|
||||||
|
// show the new conflict config to the player
|
||||||
|
this.elementGuiMap.get(generic).show(player);
|
||||||
|
|
||||||
|
update();
|
||||||
|
};
|
||||||
|
|
||||||
|
selfRef.set(selfCallback);
|
||||||
|
return selfCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract S newInstanceOfGui(T generic, GuiItem item);
|
||||||
|
|
||||||
|
protected abstract String genericDisplayedName();
|
||||||
|
|
||||||
|
protected abstract T createAndSaveNewEmptyGeneric(String name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,241 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config.settings.subsetting;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||||
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import kotlin.ranges.IntRange;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.ConfirmActionGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.global.CustomRecipeConfigGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.settings.ItemSettingGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe;
|
||||||
|
import xyz.alexcrea.cuanvil.recipe.CustomAnvilRecipeManager;
|
||||||
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
||||||
|
|
||||||
|
private final CustomRecipeConfigGui parent;
|
||||||
|
private final AnvilCustomRecipe anvilRecipe;
|
||||||
|
private final PatternPane pane;
|
||||||
|
private boolean shouldWork = true;
|
||||||
|
|
||||||
|
public CustomRecipeSubSettingGui(
|
||||||
|
@NotNull CustomRecipeConfigGui parent,
|
||||||
|
@NotNull AnvilCustomRecipe anvilRecipe,
|
||||||
|
@NotNull GuiItem parentItemForThisGui) {
|
||||||
|
super(parentItemForThisGui, 3, "title");
|
||||||
|
this.parent = parent;
|
||||||
|
this.anvilRecipe = anvilRecipe;
|
||||||
|
|
||||||
|
Pattern pattern = new Pattern(
|
||||||
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
|
"01230450D",
|
||||||
|
"B00000000"
|
||||||
|
);
|
||||||
|
this.pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||||
|
addPane(this.pane);
|
||||||
|
|
||||||
|
prepareStaticValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
BoolSettingsGui.BoolSettingFactory exactCountFactory;
|
||||||
|
IntSettingsGui.IntSettingFactory xpCostFactory;
|
||||||
|
ItemSettingGui.ItemSettingFactory leftItemFactory;
|
||||||
|
ItemSettingGui.ItemSettingFactory rightItemFactory;
|
||||||
|
ItemSettingGui.ItemSettingFactory resultItemFactory;
|
||||||
|
|
||||||
|
private void prepareStaticValues() {
|
||||||
|
|
||||||
|
GuiGlobalItems.addBackItem(this.pane, this.parent);
|
||||||
|
GuiGlobalItems.addBackgroundItem(this.pane);
|
||||||
|
|
||||||
|
// Delete item
|
||||||
|
ItemStack deleteItem = new ItemStack(Material.RED_TERRACOTTA);
|
||||||
|
ItemMeta deleteMeta = deleteItem.getItemMeta();
|
||||||
|
|
||||||
|
deleteMeta.setDisplayName("\u00A74DELETE RECIPE");
|
||||||
|
deleteMeta.setLore(Collections.singletonList("\u00A7cCaution with this button !"));
|
||||||
|
|
||||||
|
deleteItem.setItemMeta(deleteMeta);
|
||||||
|
this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance));
|
||||||
|
|
||||||
|
// Displayed item will be updated later
|
||||||
|
|
||||||
|
IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE();
|
||||||
|
exactCountFactory = BoolSettingsGui.boolFactory("title", this,
|
||||||
|
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_EXACT_COUNT_CONFIG());
|
||||||
|
|
||||||
|
xpCostFactory = IntSettingsGui.intFactory("title", 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.anvilRecipe.getName()+"."+AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG());
|
||||||
|
|
||||||
|
rightItemFactory = ItemSettingGui.itemFactory("title", this,
|
||||||
|
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG());
|
||||||
|
|
||||||
|
resultItemFactory = ItemSettingGui.itemFactory("title", this,
|
||||||
|
this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||||
|
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConfirmActionGui createDeleteGui() {
|
||||||
|
Supplier<Boolean> deleteSupplier = () -> {
|
||||||
|
CustomAnvilRecipeManager manager = ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager();
|
||||||
|
|
||||||
|
// Remove from manager
|
||||||
|
manager.cleanRemove(this.anvilRecipe);
|
||||||
|
|
||||||
|
// Remove from parent
|
||||||
|
this.parent.removeGeneric(this.anvilRecipe);
|
||||||
|
|
||||||
|
// Remove self
|
||||||
|
cleanUnused();
|
||||||
|
|
||||||
|
// Update config file storage
|
||||||
|
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(this.anvilRecipe.getName(), null);
|
||||||
|
|
||||||
|
// Save
|
||||||
|
boolean success = true;
|
||||||
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
|
success = ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
};
|
||||||
|
|
||||||
|
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.anvilRecipe.getName()) + "\u00A7c?",
|
||||||
|
"\u00A77Confirm that you want to delete this conflict.",
|
||||||
|
this, this.parent, deleteSupplier
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateGuiValues() {
|
||||||
|
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();
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
this.pane.bindItem('M', GuiGlobalItems.intSettingGuiItem(this.minBeforeActiveSettingFactory, Material.COMMAND_BLOCK));*/
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cleanUnused() {
|
||||||
|
for (HumanEntity viewer : getViewers()) {
|
||||||
|
this.parent.show(viewer);
|
||||||
|
}
|
||||||
|
this.shouldWork = false;
|
||||||
|
|
||||||
|
// Just in case something is extremely wrong
|
||||||
|
GuiItem background = GuiGlobalItems.backgroundItem();
|
||||||
|
this.pane.bindItem('1', background);
|
||||||
|
this.pane.bindItem('2', background);
|
||||||
|
this.pane.bindItem('3', background);
|
||||||
|
this.pane.bindItem('4', background);
|
||||||
|
this.pane.bindItem('5', background);
|
||||||
|
|
||||||
|
this.pane.bindItem('D', background);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(@NotNull HumanEntity humanEntity) {
|
||||||
|
if (this.shouldWork) {
|
||||||
|
super.show(humanEntity);
|
||||||
|
} else {
|
||||||
|
this.parent.show(humanEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,6 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
|
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
||||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
|
||||||
import xyz.alexcrea.cuanvil.gui.config.ConfirmActionGui;
|
import xyz.alexcrea.cuanvil.gui.config.ConfirmActionGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
|
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
||||||
|
|
@ -34,24 +33,22 @@ import java.util.Set;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements SelectEnchantmentContainer, SelectGroupContainer {
|
public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui implements SelectEnchantmentContainer, SelectGroupContainer {
|
||||||
|
|
||||||
private final EnchantConflictGui parent;
|
private final EnchantConflictGui parent;
|
||||||
private final EnchantConflictGroup enchantConflict;
|
private final EnchantConflictGroup enchantConflict;
|
||||||
private final GuiItem parentItemForThisGui;
|
|
||||||
private final PatternPane pane;
|
private final PatternPane pane;
|
||||||
private boolean shouldWorld = true;
|
private boolean shouldWork = true;
|
||||||
|
|
||||||
public EnchantConflictSubSettingGui(
|
public EnchantConflictSubSettingGui(
|
||||||
@NotNull EnchantConflictGui parent,
|
@NotNull EnchantConflictGui parent,
|
||||||
@NotNull EnchantConflictGroup enchantConflict,
|
@NotNull EnchantConflictGroup enchantConflict,
|
||||||
@NotNull GuiItem parentItemForThisGui) {
|
@NotNull GuiItem parentItemForThisGui) {
|
||||||
super(3,
|
super(parentItemForThisGui,
|
||||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()) + " \u00A78Config",
|
3,
|
||||||
CustomAnvil.instance);
|
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()) + " \u00A78Config");
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.enchantConflict = enchantConflict;
|
this.enchantConflict = enchantConflict;
|
||||||
this.parentItemForThisGui = parentItemForThisGui;
|
|
||||||
|
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
|
|
@ -126,7 +123,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
manager.conflictList.remove(this.enchantConflict);
|
manager.conflictList.remove(this.enchantConflict);
|
||||||
|
|
||||||
// Remove from parent
|
// Remove from parent
|
||||||
this.parent.removeConflict(this.enchantConflict);
|
this.parent.removeGeneric(this.enchantConflict);
|
||||||
|
|
||||||
// Remove self
|
// Remove self
|
||||||
cleanUnused();
|
cleanUnused();
|
||||||
|
|
@ -143,7 +140,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
return success;
|
return success;
|
||||||
};
|
};
|
||||||
|
|
||||||
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.getName()) + "\u00A7c?",
|
return new ConfirmActionGui("\u00A7cDelete \u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.getName()) + "\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
|
||||||
);
|
);
|
||||||
|
|
@ -155,8 +152,9 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
// Parent should call updateLocal
|
// Parent should call updateLocal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void updateLocal() {
|
public void updateLocal() {
|
||||||
if (!this.shouldWorld) return;
|
if (!this.shouldWork) return;
|
||||||
|
|
||||||
// Prepare enchantment lore
|
// Prepare enchantment lore
|
||||||
ArrayList<String> enchantLore = new ArrayList<>();
|
ArrayList<String> enchantLore = new ArrayList<>();
|
||||||
|
|
@ -231,11 +229,12 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void cleanUnused() {
|
public void cleanUnused() {
|
||||||
for (HumanEntity viewer : getViewers()) {
|
for (HumanEntity viewer : getViewers()) {
|
||||||
this.parent.show(viewer);
|
this.parent.show(viewer);
|
||||||
}
|
}
|
||||||
this.shouldWorld = false;
|
this.shouldWork = false;
|
||||||
|
|
||||||
// Just in case something is extremely wrong
|
// Just in case something is extremely wrong
|
||||||
GuiItem background = GuiGlobalItems.backgroundItem();
|
GuiItem background = GuiGlobalItems.backgroundItem();
|
||||||
|
|
@ -247,17 +246,13 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(@NotNull HumanEntity humanEntity) {
|
public void show(@NotNull HumanEntity humanEntity) {
|
||||||
if (this.shouldWorld) {
|
if (this.shouldWork) {
|
||||||
super.show(humanEntity);
|
super.show(humanEntity);
|
||||||
} else {
|
} else {
|
||||||
this.parent.show(humanEntity);
|
this.parent.show(humanEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiItem getParentItemForThisGui() {
|
|
||||||
return parentItemForThisGui;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select enchantment container methods
|
// Select enchantment container methods
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -267,7 +262,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setSelectedEnchantments(Set<Enchantment> enchantments) {
|
public boolean setSelectedEnchantments(Set<Enchantment> enchantments) {
|
||||||
if (!this.shouldWorld) {
|
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.getName() + " enchants but sub config is destroyed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -312,7 +307,7 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) {
|
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) {
|
||||||
if (!this.shouldWorld) {
|
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.getName() + " groups but sub config is destroyed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -347,4 +342,5 @@ public class EnchantConflictSubSettingGui extends ValueUpdatableGui implements S
|
||||||
|
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package xyz.alexcrea.cuanvil.gui.config.settings.subsetting;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
|
|
||||||
|
public abstract class MappedToListSubSettingGui extends ValueUpdatableGui {
|
||||||
|
|
||||||
|
private final GuiItem item;
|
||||||
|
public MappedToListSubSettingGui(
|
||||||
|
GuiItem item,
|
||||||
|
int rows,
|
||||||
|
@NotNull String title) {
|
||||||
|
super(rows, title, CustomAnvil.instance);
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public GuiItem getParentItemForThisGui() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract void updateLocal(); // TODO
|
||||||
|
|
||||||
|
public abstract void cleanUnused(); // TODO
|
||||||
|
}
|
||||||
|
|
@ -3,12 +3,13 @@ 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(
|
||||||
val name: String,
|
private val name: String,
|
||||||
private val cantConflict: AbstractMaterialGroup,
|
private val cantConflict: AbstractMaterialGroup,
|
||||||
val minBeforeBlock: Int
|
val minBeforeBlock: Int
|
||||||
) {
|
): Named {
|
||||||
|
|
||||||
private val enchantments = HashSet<Enchantment>()
|
private val enchantments = HashSet<Enchantment>()
|
||||||
|
|
||||||
|
|
@ -62,4 +63,8 @@ class EnchantConflictGroup(
|
||||||
return Material.ENCHANTED_BOOK
|
return Material.ENCHANTED_BOOK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getName(): String {
|
||||||
|
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.name}")
|
CustomAnvil.verboseLog("Is against ${conflict.getName()}")
|
||||||
val conflicting = conflict.allowed(base, mat)
|
val conflicting = conflict.allowed(base, mat)
|
||||||
CustomAnvil.verboseLog("Was against ${conflict.name} and conflicting: $conflicting ")
|
CustomAnvil.verboseLog("Was against ${conflict.getName()} 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
|
||||||
|
|
|
||||||
7
src/main/kotlin/xyz/alexcrea/cuanvil/interfaces/Named.kt
Normal file
7
src/main/kotlin/xyz/alexcrea/cuanvil/interfaces/Named.kt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
package xyz.alexcrea.cuanvil.interfaces
|
||||||
|
|
||||||
|
interface Named {
|
||||||
|
|
||||||
|
fun getName(): String
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -4,9 +4,10 @@ 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(
|
||||||
val name: String,
|
private val name: String,
|
||||||
var exactCount: Boolean,
|
var exactCount: Boolean,
|
||||||
//var exactLeft: Boolean,
|
//var exactLeft: Boolean,
|
||||||
//var exactRight: Boolean,
|
//var exactRight: Boolean,
|
||||||
|
|
@ -16,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 {
|
||||||
|
|
@ -37,9 +38,9 @@ class AnvilCustomRecipe(
|
||||||
|
|
||||||
val DEFAULT_XP_COST_CONFIG = 1
|
val DEFAULT_XP_COST_CONFIG = 1
|
||||||
|
|
||||||
val DEFAULT_LEFT_ITEM_CONFIG = null
|
val DEFAULT_LEFT_ITEM_CONFIG: ItemStack? = null
|
||||||
val DEFAULT_RIGHT_ITEM_CONFIG = null
|
val DEFAULT_RIGHT_ITEM_CONFIG: ItemStack? = null
|
||||||
val DEFAULT_RESULT_ITEM_CONFIG = null
|
val DEFAULT_RESULT_ITEM_CONFIG: ItemStack? = null;
|
||||||
|
|
||||||
val XP_COST_CONFIG_RANGE = 0..255
|
val XP_COST_CONFIG_RANGE = 0..255
|
||||||
|
|
||||||
|
|
@ -115,5 +116,9 @@ class AnvilCustomRecipe(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getName(): String {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,34 +4,37 @@ import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.configuration.file.FileConfiguration
|
import org.bukkit.configuration.file.FileConfiguration
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import java.util.LinkedHashMap
|
|
||||||
|
|
||||||
class CustomAnvilRecipeManager {
|
class CustomAnvilRecipeManager {
|
||||||
|
|
||||||
lateinit var recipeMap: LinkedHashMap<String, AnvilCustomRecipe>
|
lateinit var recipeList: ArrayList<AnvilCustomRecipe>
|
||||||
|
|
||||||
lateinit var recipeByMat: LinkedHashMap<Material, ArrayList<AnvilCustomRecipe>>
|
lateinit var recipeByMat: LinkedHashMap<Material, ArrayList<AnvilCustomRecipe>>
|
||||||
|
|
||||||
fun prepareRecipes(config: FileConfiguration) {
|
fun prepareRecipes(config: FileConfiguration) {
|
||||||
recipeMap = LinkedHashMap()
|
recipeList = ArrayList()
|
||||||
recipeByMat = LinkedHashMap()
|
recipeByMat = LinkedHashMap()
|
||||||
|
|
||||||
// read all configs
|
// read all configs
|
||||||
val keys = config.getKeys(false)
|
val keys = config.getKeys(false)
|
||||||
for (key in keys) {
|
for (key in keys) {
|
||||||
if (recipeMap.containsKey(key))
|
|
||||||
continue
|
|
||||||
val recipe = AnvilCustomRecipe.getFromConfig(key)
|
val recipe = AnvilCustomRecipe.getFromConfig(key)
|
||||||
if(recipe == null){
|
if(recipe == null){
|
||||||
CustomAnvil.log("Can't load recipe $key")
|
CustomAnvil.log("Can't load recipe $key")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeMap[key] = recipe
|
cleanAddNew(recipe)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun cleanAddNew(recipe: AnvilCustomRecipe){
|
||||||
|
recipeList.add(recipe)
|
||||||
val leftItem = recipe.leftItem
|
val leftItem = recipe.leftItem
|
||||||
if(leftItem != null){
|
if(leftItem != null){
|
||||||
addToMap(recipe, leftItem)
|
addToMatMap(recipe, leftItem)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -46,13 +49,13 @@ class CustomAnvilRecipeManager {
|
||||||
test!!.remove(recipe)
|
test!!.remove(recipe)
|
||||||
}
|
}
|
||||||
if(leftItem != null){
|
if(leftItem != null){
|
||||||
addToMap(recipe, leftItem)
|
addToMatMap(recipe, leftItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
recipe.leftItem = leftItem
|
recipe.leftItem = leftItem
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addToMap(recipe: AnvilCustomRecipe, leftItem: ItemStack){
|
private fun addToMatMap(recipe: AnvilCustomRecipe, leftItem: ItemStack){
|
||||||
var recipeList = recipeByMat[leftItem.type]
|
var recipeList = recipeByMat[leftItem.type]
|
||||||
if(recipeList == null){
|
if(recipeList == null){
|
||||||
recipeList = ArrayList()
|
recipeList = ArrayList()
|
||||||
|
|
@ -62,4 +65,11 @@ class CustomAnvilRecipeManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun cleanRemove(recipe: AnvilCustomRecipe) {
|
||||||
|
|
||||||
|
recipeList.remove(recipe)
|
||||||
|
cleanSetLeftItem(recipe, null)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue