mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Global unit repair config gui should be finished and work properly.
This commit is contained in:
parent
050c40bd2a
commit
9ea7624bff
4 changed files with 90 additions and 27 deletions
|
|
@ -1,17 +1,20 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import jdk.nashorn.internal.runtime.regexp.joni.Config;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.config.ask.SelectItemTypeGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {
|
||||
|
||||
|
|
@ -27,22 +30,34 @@ public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRe
|
|||
|
||||
@Override
|
||||
protected UnitRepairElementListGui newInstanceOfGui(Material material, GuiItem item) {
|
||||
return new UnitRepairElementListGui(material, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String genericDisplayedName() {
|
||||
return "item to be repaired";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Material createAndSaveNewEmptyGeneric(String name) {
|
||||
return Material.getMaterial(name.toUpperCase());
|
||||
UnitRepairElementListGui element = new UnitRepairElementListGui(material, this, item);
|
||||
element.init();
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack createItemForGeneric(Material material) {
|
||||
return new ItemStack(material); //TODO proper item
|
||||
ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(material.name().toLowerCase());
|
||||
String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase());
|
||||
|
||||
if(material.isAir()){
|
||||
material = Material.BARRIER;
|
||||
}
|
||||
|
||||
int reparableItemCount = materialSection == null ? 0 : materialSection.getKeys(false).size(); // Probably an expensive call but... why not
|
||||
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setDisplayName("\u00A7eRepaired by " +materialName);
|
||||
meta.setLore(Arrays.asList(
|
||||
"\u00A77There is currently \u00A7e" +reparableItemCount+ " \u00A77reparable item with "+materialName,
|
||||
"\u00A77Click here to open the menu to edit reparable item by " + materialName
|
||||
));
|
||||
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -58,5 +73,47 @@ public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRe
|
|||
return materials;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem prepareCreateNewItem() {
|
||||
// Create new conflict item
|
||||
ItemStack createItem = new ItemStack(Material.PAPER);
|
||||
ItemMeta createMeta = createItem.getItemMeta();
|
||||
|
||||
createMeta.setDisplayName("\u00A7aSelect a new unit material");
|
||||
createMeta.setLore(Arrays.asList(
|
||||
"\u00A77Select a new unit material to be used.",
|
||||
"\u00A77You will be asked the material to use."
|
||||
));
|
||||
|
||||
createItem.setItemMeta(createMeta);
|
||||
|
||||
return new GuiItem(createItem, (clickEvent) -> {
|
||||
clickEvent.setCancelled(true);
|
||||
|
||||
new SelectItemTypeGui(
|
||||
"Select unit repair item.",
|
||||
"\u00A77Click here with an item to set the item\n" +
|
||||
"\u00A77You like to be an unit repair item",
|
||||
this,
|
||||
(itemStack, player) -> {
|
||||
Material type = itemStack.getType();
|
||||
// Add new material
|
||||
updateValueForGeneric(type, true);
|
||||
|
||||
// Display material edit setting
|
||||
this.elementGuiMap.get(type).getMappedGui().show(player);
|
||||
},
|
||||
true
|
||||
).show(clickEvent.getWhoClicked());
|
||||
}, CustomAnvil.instance);
|
||||
}
|
||||
|
||||
@Override // Not used in this implementation.
|
||||
protected String genericDisplayedName() {
|
||||
return "this function Should not be used.";
|
||||
}
|
||||
@Override // Not used in this implementation.
|
||||
protected Material createAndSaveNewEmptyGeneric(String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,18 +27,12 @@ public abstract class ElementListConfigGui< T > extends ValueUpdatableGui {
|
|||
|
||||
private final String namePrefix;
|
||||
|
||||
protected PatternPane backgroundPane;
|
||||
|
||||
public ElementListConfigGui(@NotNull String title) {
|
||||
super(6, title, CustomAnvil.instance);
|
||||
this.namePrefix = title;
|
||||
}
|
||||
|
||||
|
||||
protected OutlinePane firstPage;
|
||||
protected ArrayList<OutlinePane> pages;
|
||||
protected HashMap<UUID, Integer> pageMap;
|
||||
protected PatternPane backgroundPane;
|
||||
|
||||
public void init() {
|
||||
// Back item panel
|
||||
Pattern pattern = new Pattern(
|
||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||
|
|
@ -49,9 +43,16 @@ public abstract class ElementListConfigGui< T > extends ValueUpdatableGui {
|
|||
"B11L1R11C"
|
||||
);
|
||||
this.backgroundPane = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
|
||||
|
||||
GuiGlobalItems.addBackItem(this.backgroundPane, MainConfigGui.INSTANCE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected OutlinePane firstPage;
|
||||
protected ArrayList<OutlinePane> pages;
|
||||
protected HashMap<UUID, Integer> pageMap;
|
||||
|
||||
public void init() { // Why I'm using an init function ?
|
||||
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
|
||||
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||
addPane(this.backgroundPane);
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantCostConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, DoubleSettingGui.DoubleSettingFactory> implements ElementMappedToListGui {
|
||||
|
|
@ -28,12 +28,15 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
private final Material material;
|
||||
private final String materialName;
|
||||
|
||||
public UnitRepairElementListGui(@NotNull Material material, GuiItem parentItem) {
|
||||
public UnitRepairElementListGui(@NotNull Material material,
|
||||
@NotNull Gui parentGui,
|
||||
@NotNull GuiItem parentItem) {
|
||||
super("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase()) + " \u00A7rUnit repair config");
|
||||
this.parentItem = parentItem;
|
||||
this.material = material;
|
||||
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase());
|
||||
|
||||
GuiGlobalItems.addBackItem(this.backgroundPane, parentGui);
|
||||
}
|
||||
|
||||
// SettingGuiListConfigGui methods
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import xyz.alexcrea.cuanvil.gui.config.global.BasicConfigGui
|
|||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantCostConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantLimitConfigGui
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||
|
||||
class ReloadExecutor : CommandExecutor {
|
||||
|
|
@ -43,6 +44,7 @@ class ReloadExecutor : CommandExecutor {
|
|||
EnchantCostConfigGui.INSTANCE.updateGuiValues()
|
||||
EnchantLimitConfigGui.INSTANCE.updateGuiValues()
|
||||
EnchantConflictGui.INSTANCE.reloadValues()
|
||||
UnitRepairConfigGui.INSTANCE.reloadValues()
|
||||
|
||||
// & update metric
|
||||
MetricsUtil.testIfConfigIsDefault()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue