mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Progress on unit repair list gui.
This commit is contained in:
parent
abc9dc89d3
commit
cb934e8a89
3 changed files with 37 additions and 25 deletions
|
|
@ -28,7 +28,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
|
|||
ItemStack createItem = new ItemStack(Material.PAPER);
|
||||
ItemMeta createMeta = createItem.getItemMeta();
|
||||
|
||||
createMeta.setDisplayName("\u00A7aCreate new " + genericDisplayedName());
|
||||
createMeta.setDisplayName(createItemName());
|
||||
createMeta.setLore(getCreateItemLore());
|
||||
|
||||
createItem.setItemMeta(createMeta);
|
||||
|
|
@ -41,7 +41,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
|
|||
if(factory == null){
|
||||
// Create new item & factory
|
||||
factory = createFactory(generic);
|
||||
GuiItem newItem = itemFromFactory(factory);
|
||||
GuiItem newItem = itemFromFactory(generic, factory);
|
||||
|
||||
addToPage(newItem);
|
||||
this.guiItemMap.put(generic, newItem);
|
||||
|
|
@ -50,7 +50,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
|
|||
// Update old item
|
||||
GuiItem oldItem = this.guiItemMap.get(generic);
|
||||
|
||||
GuiItem newItem = itemFromFactory(factory);
|
||||
GuiItem newItem = itemFromFactory(generic, factory);
|
||||
updateGuiItem(oldItem, newItem);
|
||||
}
|
||||
|
||||
|
|
@ -86,10 +86,10 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
|
|||
|
||||
protected abstract List<String> getCreateItemLore();
|
||||
protected abstract Consumer<InventoryClickEvent> getCreateClickConsumer();
|
||||
protected abstract String genericDisplayedName();
|
||||
protected abstract String createItemName();
|
||||
|
||||
protected abstract S createFactory(T generic);
|
||||
protected abstract GuiItem itemFromFactory(S factory);
|
||||
protected abstract GuiItem itemFromFactory(T generic, S factory);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,11 @@ 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.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
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 {
|
||||
|
||||
|
||||
|
||||
|
||||
private final GuiItem parentItem;
|
||||
private final Material material;
|
||||
private final String materialName;
|
||||
|
|
@ -31,7 +25,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
public UnitRepairElementListGui(@NotNull Material material,
|
||||
@NotNull Gui parentGui,
|
||||
@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.material = material;
|
||||
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase());
|
||||
|
|
@ -40,7 +34,6 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
}
|
||||
|
||||
// SettingGuiListConfigGui methods
|
||||
|
||||
@Override
|
||||
protected List<String> getCreateItemLore() {
|
||||
return Arrays.asList(
|
||||
|
|
@ -60,18 +53,31 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
}
|
||||
|
||||
@Override
|
||||
protected String genericDisplayedName() {
|
||||
return this.materialName+"`s Unit Repair Item";
|
||||
protected String createItemName() {
|
||||
return "\u00A7aAdd a new item reparable by " + this.materialName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DoubleSettingGui.DoubleSettingFactory createFactory(String generic) {
|
||||
return null; //TODO
|
||||
protected DoubleSettingGui.DoubleSettingFactory createFactory(String materialName) {
|
||||
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
|
||||
protected GuiItem itemFromFactory(DoubleSettingGui.DoubleSettingFactory factory) {
|
||||
return new GuiItem(new ItemStack(Material.STONE), CustomAnvil.instance); //TODO correct item
|
||||
protected GuiItem itemFromFactory(String materialName, DoubleSettingGui.DoubleSettingFactory factory) {
|
||||
return factory.getItem(materialFromName(materialName),
|
||||
"\u00A77%\u00A7a" + CasedStringUtil.snakeToUpperSpacedCase(materialName)+ " \u00A7erepaired by \u00A7a" + this.materialName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -86,6 +92,12 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
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
|
||||
|
||||
@Override
|
||||
|
|
@ -93,18 +105,17 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
return this.parentItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocal() {
|
||||
|
||||
}
|
||||
@Override // Not used in this implementation
|
||||
public void updateLocal() {}
|
||||
|
||||
@Override
|
||||
public void cleanAndBeUnusable() {
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public Gui getMappedGui() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
|||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
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.util.CasedStringUtil;
|
||||
|
||||
import java.nio.charset.MalformedInputException;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
|
|
@ -331,6 +331,7 @@ public class GuiGlobalItems {
|
|||
|
||||
itemMeta.setDisplayName(itemName.toString());
|
||||
itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX + value));
|
||||
itemMeta.addItemFlags(ItemFlag.values());
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
// Create GuiItem
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue