progress on unit repair config.

This commit is contained in:
alexcrea 2024-04-09 17:53:27 +02:00
parent 52bb0785e7
commit 6ea9494afd
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
4 changed files with 182 additions and 5 deletions

View file

@ -88,11 +88,20 @@ public class MainConfigGui extends ChestGui {
wipMeta.setDisplayName("\u00A7cWIP"); wipMeta.setDisplayName("\u00A7cWIP");
wipItemstack.setItemMeta(wipMeta); wipItemstack.setItemMeta(wipMeta);
GuiItem wip5 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance); GuiItem wip = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
GuiItem wip6 = new GuiItem(wipItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
pane.bindItem('5', wip5); pane.bindItem('5', wip);
pane.bindItem('6', wip6);
// Unit repair item
ItemStack unirRepairItemstack = new ItemStack(Material.DIAMOND);
ItemMeta unitRepairMeta = unirRepairItemstack.getItemMeta();
unitRepairMeta.setDisplayName("\u00A7aUnit Repair");
unitRepairMeta.setLore(Collections.singletonList("\u00A77Click here to open anvil custom recipe menu"));
unirRepairItemstack.setItemMeta(unitRepairMeta);
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.INSTANCE);
pane.bindItem('6', unitRepairItem);
// Custom recipe item // Custom recipe item
ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE); ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE);

View file

@ -0,0 +1,62 @@
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {
public final static UnitRepairConfigGui INSTANCE = new UnitRepairConfigGui();
static {
INSTANCE.init();
}
private UnitRepairConfigGui() {
super("Unit Repair Config");
}
@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());
}
@Override
protected ItemStack createItemForGeneric(Material material) {
return new ItemStack(material); //TODO proper item
}
@Override
protected List<Material> getEveryDisplayableInstanceOfGeneric() {
ArrayList<Material> materials = new ArrayList<>();
for (String matName : ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getKeys(false)) {
Material mat = Material.getMaterial(matName.toUpperCase());
if(mat != null){
materials.add(mat);
}
}
return materials;
}
}

View file

@ -12,7 +12,6 @@ import java.util.function.Consumer;
public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGui> extends MappedElementListConfigGui< T, S > { public abstract class MappedGuiListConfigGui< T, S extends ElementMappedToListGui> extends MappedElementListConfigGui< T, S > {
public MappedGuiListConfigGui(@NotNull String title) { public MappedGuiListConfigGui(@NotNull String title) {
super(title); super(title);

View file

@ -0,0 +1,107 @@
package xyz.alexcrea.cuanvil.gui.config.list;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import io.delilaheve.CustomAnvil;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
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.settings.DoubleSettingGui;
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 {
private final GuiItem parentItem;
private final Material material;
private final String materialName;
public UnitRepairElementListGui(@NotNull Material material, 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());
}
// SettingGuiListConfigGui methods
@Override
protected List<String> getCreateItemLore() {
return Arrays.asList(
"a",
"b",
"c"
);
}
@Override
protected Consumer<InventoryClickEvent> getCreateClickConsumer() {
return event -> {
event.setCancelled(true);
event.getWhoClicked().sendMessage("todo");
};
}
@Override
protected String genericDisplayedName() {
return this.materialName+"`s Unit Repair Item";
}
@Override
protected DoubleSettingGui.DoubleSettingFactory createFactory(String generic) {
return null; //TODO
}
@Override
protected GuiItem itemFromFactory(DoubleSettingGui.DoubleSettingFactory factory) {
return new GuiItem(new ItemStack(Material.STONE), CustomAnvil.instance); //TODO correct item
}
@Override
protected List<String> getEveryDisplayableInstanceOfGeneric() {
ArrayList<String> keys = new ArrayList<>();
ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(material.name().toLowerCase());
if(materialSection == null){
return keys;
}
keys.addAll(materialSection.getKeys(false));
return keys;
}
// ElementMappedToListGui methods
@Override
public GuiItem getParentItemForThisGui() {
return this.parentItem;
}
@Override
public void updateLocal() {
}
@Override
public void cleanAndBeUnusable() {
}
@Override
public Gui getMappedGui() {
return this;
}
}