Work on the displayed items

This commit is contained in:
alexcrea 2024-03-29 00:07:12 +01:00
parent a30f471c6a
commit bf320e1ffc
5 changed files with 60 additions and 16 deletions

View file

@ -20,8 +20,10 @@ import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.EnchantConflictSubSet
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.util.CasedStringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
@ -54,21 +56,21 @@ public class EnchantConflictGui extends ChestGui {
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"B11L1R11C"
);
backgroundPane = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
this.backgroundPane = new PatternPane(0, 0, 9, 6, Pane.Priority.LOW, pattern);
GuiGlobalItems.addBackItem(backgroundPane, MainConfigGui.INSTANCE);
GuiGlobalItems.addBackItem(this.backgroundPane, MainConfigGui.INSTANCE);
GuiGlobalItems.addBackgroundItem(backgroundPane);
backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
backgroundPane.bindItem('C', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
addPane(backgroundPane);
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
this.backgroundPane.bindItem('C', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
addPane(this.backgroundPane);
// Page init
this.pages = new ArrayList<>();
this.pageMap = new HashMap<>();
// enchant item panel
this.firstPage = creatEmptyPage();
this.firstPage = createEmptyPage();
this.pages.add(this.firstPage);
prepareOtherValues();
@ -112,7 +114,7 @@ public class EnchantConflictGui extends ChestGui {
}
private OutlinePane creatEmptyPage(){
private OutlinePane createEmptyPage(){
OutlinePane page = new OutlinePane(0, 0, 9, 5);
page.align(OutlinePane.Alignment.BEGIN);
page.setOrientation(Orientable.Orientation.HORIZONTAL);
@ -135,11 +137,16 @@ public class EnchantConflictGui extends ChestGui {
}
public ItemStack createItemForConflict(EnchantConflictGroup conflict){
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
//TODO item
ItemStack item = new ItemStack(conflict.getRepresentativeMaterial());
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(conflict.getName());
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(conflict.getName()) + " \u00A7rConflict");
meta.setLore(Arrays.asList(
"\u00A77Enchantment count: \u00A7e"+conflict.getEnchants().size(),
"\u00A77Group count: \u00A7e"+conflict.getCantConflictGroup().getGroups().size(),
"\u00A77Min enchantments count: \u00A7e"+conflict.getMinBeforeBlock()
));
item.setItemMeta(meta);
return item;
@ -186,7 +193,7 @@ public class EnchantConflictGui extends ChestGui {
// Get first available page or create one
OutlinePane page = this.pages.get(this.pages.size()-1);
if(page.getItems().size() >= 5*9){
page = creatEmptyPage();
page = createEmptyPage();
this.pages.add(page);
}

View file

@ -70,7 +70,7 @@ public class MainConfigGui extends ChestGui {
pane.bindItem('3', enchantCostItem);
// Enchantment Conflicts
ItemStack EnchantConflictItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE);
ItemStack EnchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
ItemMeta enchantConflictMeta = EnchantConflictItemstack.getItemMeta();
enchantConflictMeta.setDisplayName("\u00A7aEnchantment Conflict");

View file

@ -244,7 +244,7 @@ public class GuiGlobalItems {
@NotNull Material itemMat
){
String configPath = getConfigNameFromPath(factory.getConfigPath());
return intSettingGuiItem(factory, itemMat, CasedStringUtil.snakeToUpperSpacedCase(configPath));
return intSettingGuiItem(factory, itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath));
}
/**

View file

@ -28,4 +28,30 @@ public class CasedStringUtil {
return result.substring(1);
}
public static String camelCaseToUpperSpaceCase(String camelCasedString){
if(camelCasedString.isEmpty()) return camelCasedString;
StringBuilder stb = new StringBuilder();
char[] chars = camelCasedString.toCharArray();
stb.append(chars[0]);
for (int i = 1; i < chars.length; i++) {
char chr = chars[i];
if(Character.isUpperCase(chr)){
stb.append(" ");
}
stb.append(chr);
}
return stb.toString();
}
public static String detectToUpperSpacedCase(String toDetect){
//not advanced detection
if(toDetect.contains("_")){
return snakeToUpperSpacedCase(toDetect);
}else{
return camelCaseToUpperSpaceCase(toDetect);
}
}
}

View file

@ -7,7 +7,7 @@ import org.bukkit.enchantments.Enchantment
class EnchantConflictGroup(
val name: String,
private val cantConflict: AbstractMaterialGroup,
private val minBeforeBlock: Int){
val minBeforeBlock: Int){
private val enchantments = HashSet<Enchantment>()
@ -50,4 +50,15 @@ class EnchantConflictGroup(
enchantments.addAll(enchants)
}
fun getRepresentativeMaterial(): Material {
val groups = getCantConflictGroup().getGroups()
val groupIterator = groups.iterator()
while (groupIterator.hasNext()){
val mat = groupIterator.next().getRepresentativeMaterial()
if(mat != Material.ENCHANTED_BOOK) return mat
}
return Material.ENCHANTED_BOOK
}
}