Progress on unit repair list gui.

This commit is contained in:
alexcrea 2024-04-11 00:39:25 +02:00
parent abc9dc89d3
commit cb934e8a89
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
3 changed files with 37 additions and 25 deletions

View file

@ -28,7 +28,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
ItemStack createItem = new ItemStack(Material.PAPER); ItemStack createItem = new ItemStack(Material.PAPER);
ItemMeta createMeta = createItem.getItemMeta(); ItemMeta createMeta = createItem.getItemMeta();
createMeta.setDisplayName("\u00A7aCreate new " + genericDisplayedName()); createMeta.setDisplayName(createItemName());
createMeta.setLore(getCreateItemLore()); createMeta.setLore(getCreateItemLore());
createItem.setItemMeta(createMeta); createItem.setItemMeta(createMeta);
@ -41,7 +41,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
if(factory == null){ if(factory == null){
// Create new item & factory // Create new item & factory
factory = createFactory(generic); factory = createFactory(generic);
GuiItem newItem = itemFromFactory(factory); GuiItem newItem = itemFromFactory(generic, factory);
addToPage(newItem); addToPage(newItem);
this.guiItemMap.put(generic, newItem); this.guiItemMap.put(generic, newItem);
@ -50,7 +50,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
// Update old item // Update old item
GuiItem oldItem = this.guiItemMap.get(generic); GuiItem oldItem = this.guiItemMap.get(generic);
GuiItem newItem = itemFromFactory(factory); GuiItem newItem = itemFromFactory(generic, factory);
updateGuiItem(oldItem, newItem); updateGuiItem(oldItem, newItem);
} }
@ -86,10 +86,10 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
protected abstract List<String> getCreateItemLore(); protected abstract List<String> getCreateItemLore();
protected abstract Consumer<InventoryClickEvent> getCreateClickConsumer(); protected abstract Consumer<InventoryClickEvent> getCreateClickConsumer();
protected abstract String genericDisplayedName(); protected abstract String createItemName();
protected abstract S createFactory(T generic); protected abstract S createFactory(T generic);
protected abstract GuiItem itemFromFactory(S factory); protected abstract GuiItem itemFromFactory(T generic, S factory);
} }

View file

@ -2,14 +2,11 @@ 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.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import io.delilaheve.CustomAnvil;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.CasedStringUtil;
@ -21,9 +18,6 @@ import java.util.function.Consumer;
public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, DoubleSettingGui.DoubleSettingFactory> implements ElementMappedToListGui { public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, DoubleSettingGui.DoubleSettingFactory> implements ElementMappedToListGui {
private final GuiItem parentItem; private final GuiItem parentItem;
private final Material material; private final Material material;
private final String materialName; private final String materialName;
@ -31,7 +25,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
public UnitRepairElementListGui(@NotNull Material material, public UnitRepairElementListGui(@NotNull Material material,
@NotNull Gui parentGui, @NotNull Gui parentGui,
@NotNull GuiItem parentItem) { @NotNull GuiItem parentItem) {
super("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase()) + " \u00A7rUnit repair config"); super("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase()) + " \u00A7rUnit repair");
this.parentItem = parentItem; this.parentItem = parentItem;
this.material = material; this.material = material;
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase()); this.materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase());
@ -40,7 +34,6 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
} }
// SettingGuiListConfigGui methods // SettingGuiListConfigGui methods
@Override @Override
protected List<String> getCreateItemLore() { protected List<String> getCreateItemLore() {
return Arrays.asList( return Arrays.asList(
@ -60,18 +53,31 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
} }
@Override @Override
protected String genericDisplayedName() { protected String createItemName() {
return this.materialName+"`s Unit Repair Item"; return "\u00A7aAdd a new item reparable by " + this.materialName;
} }
@Override @Override
protected DoubleSettingGui.DoubleSettingFactory createFactory(String generic) { protected DoubleSettingGui.DoubleSettingFactory createFactory(String materialName) {
return null; //TODO return DoubleSettingGui.doubleFactory(
"\u00A70%\u00A78" +CasedStringUtil.snakeToUpperSpacedCase(materialName)+" Repair",
this,
material.name()+"."+materialName,
ConfigHolder.UNIT_REPAIR_HOLDER,
2,
true,
0,
1,
0.25,
0.01, 0.05, 0.25
);
} }
@Override @Override
protected GuiItem itemFromFactory(DoubleSettingGui.DoubleSettingFactory factory) { protected GuiItem itemFromFactory(String materialName, DoubleSettingGui.DoubleSettingFactory factory) {
return new GuiItem(new ItemStack(Material.STONE), CustomAnvil.instance); //TODO correct item return factory.getItem(materialFromName(materialName),
"\u00A77%\u00A7a" + CasedStringUtil.snakeToUpperSpacedCase(materialName)+ " \u00A7erepaired by \u00A7a" + this.materialName);
} }
@Override @Override
@ -86,6 +92,12 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
return keys; return keys;
} }
private Material materialFromName(String materialName){
Material mat = Material.getMaterial(materialName.toUpperCase());
if(mat == null || mat.isAir()) return Material.BARRIER;
return mat;
}
// ElementMappedToListGui methods // ElementMappedToListGui methods
@Override @Override
@ -93,18 +105,17 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
return this.parentItem; return this.parentItem;
} }
@Override @Override // Not used in this implementation
public void updateLocal() { public void updateLocal() {}
}
@Override @Override
public void cleanAndBeUnusable() { public void cleanAndBeUnusable() {
// TODO
} }
@Override @Override
public Gui getMappedGui() { public Gui getMappedGui() {
return this; return this;
} }
} }

View file

@ -6,6 +6,7 @@ import com.github.stefvanschie.inventoryframework.pane.PatternPane;
import io.delilaheve.CustomAnvil; import io.delilaheve.CustomAnvil;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
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 org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -16,7 +17,6 @@ import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
import xyz.alexcrea.cuanvil.gui.config.settings.ItemSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.ItemSettingGui;
import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.nio.charset.MalformedInputException;
import java.util.Collections; import java.util.Collections;
/** /**
@ -331,6 +331,7 @@ public class GuiGlobalItems {
itemMeta.setDisplayName(itemName.toString()); itemMeta.setDisplayName(itemName.toString());
itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX + value)); itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX + value));
itemMeta.addItemFlags(ItemFlag.values());
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
// Create GuiItem // Create GuiItem