mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Work on the displayed items
This commit is contained in:
parent
a30f471c6a
commit
bf320e1ffc
5 changed files with 60 additions and 16 deletions
|
|
@ -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.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -54,21 +56,21 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
|
||||||
"B11L1R11C"
|
"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);
|
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
|
||||||
backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||||
backgroundPane.bindItem('C', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
this.backgroundPane.bindItem('C', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||||
addPane(backgroundPane);
|
addPane(this.backgroundPane);
|
||||||
|
|
||||||
// Page init
|
// Page init
|
||||||
this.pages = new ArrayList<>();
|
this.pages = new ArrayList<>();
|
||||||
this.pageMap = new HashMap<>();
|
this.pageMap = new HashMap<>();
|
||||||
|
|
||||||
// enchant item panel
|
// enchant item panel
|
||||||
this.firstPage = creatEmptyPage();
|
this.firstPage = createEmptyPage();
|
||||||
this.pages.add(this.firstPage);
|
this.pages.add(this.firstPage);
|
||||||
|
|
||||||
prepareOtherValues();
|
prepareOtherValues();
|
||||||
|
|
@ -112,7 +114,7 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OutlinePane creatEmptyPage(){
|
private OutlinePane createEmptyPage(){
|
||||||
OutlinePane page = new OutlinePane(0, 0, 9, 5);
|
OutlinePane page = new OutlinePane(0, 0, 9, 5);
|
||||||
page.align(OutlinePane.Alignment.BEGIN);
|
page.align(OutlinePane.Alignment.BEGIN);
|
||||||
page.setOrientation(Orientable.Orientation.HORIZONTAL);
|
page.setOrientation(Orientable.Orientation.HORIZONTAL);
|
||||||
|
|
@ -135,11 +137,16 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createItemForConflict(EnchantConflictGroup conflict){
|
public ItemStack createItemForConflict(EnchantConflictGroup conflict){
|
||||||
ItemStack item = new ItemStack(Material.ENCHANTED_BOOK);
|
ItemStack item = new ItemStack(conflict.getRepresentativeMaterial());
|
||||||
//TODO item
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
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);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
|
|
@ -186,7 +193,7 @@ public class EnchantConflictGui extends ChestGui {
|
||||||
// Get first available page or create one
|
// Get first available page or create one
|
||||||
OutlinePane page = this.pages.get(this.pages.size()-1);
|
OutlinePane page = this.pages.get(this.pages.size()-1);
|
||||||
if(page.getItems().size() >= 5*9){
|
if(page.getItems().size() >= 5*9){
|
||||||
page = creatEmptyPage();
|
page = createEmptyPage();
|
||||||
this.pages.add(page);
|
this.pages.add(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ public class MainConfigGui extends ChestGui {
|
||||||
pane.bindItem('3', enchantCostItem);
|
pane.bindItem('3', enchantCostItem);
|
||||||
|
|
||||||
// Enchantment Conflicts
|
// Enchantment Conflicts
|
||||||
ItemStack EnchantConflictItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE);
|
ItemStack EnchantConflictItemstack = new ItemStack(Material.OAK_FENCE);
|
||||||
ItemMeta enchantConflictMeta = EnchantConflictItemstack.getItemMeta();
|
ItemMeta enchantConflictMeta = EnchantConflictItemstack.getItemMeta();
|
||||||
|
|
||||||
enchantConflictMeta.setDisplayName("\u00A7aEnchantment Conflict");
|
enchantConflictMeta.setDisplayName("\u00A7aEnchantment Conflict");
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@ public class GuiGlobalItems {
|
||||||
@NotNull Material itemMat
|
@NotNull Material itemMat
|
||||||
){
|
){
|
||||||
String configPath = getConfigNameFromPath(factory.getConfigPath());
|
String configPath = getConfigNameFromPath(factory.getConfigPath());
|
||||||
return intSettingGuiItem(factory, itemMat, CasedStringUtil.snakeToUpperSpacedCase(configPath));
|
return intSettingGuiItem(factory, itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,30 @@ public class CasedStringUtil {
|
||||||
return result.substring(1);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import org.bukkit.enchantments.Enchantment
|
||||||
class EnchantConflictGroup(
|
class EnchantConflictGroup(
|
||||||
val name: String,
|
val name: String,
|
||||||
private val cantConflict: AbstractMaterialGroup,
|
private val cantConflict: AbstractMaterialGroup,
|
||||||
private val minBeforeBlock: Int){
|
val minBeforeBlock: Int){
|
||||||
|
|
||||||
private val enchantments = HashSet<Enchantment>()
|
private val enchantments = HashSet<Enchantment>()
|
||||||
|
|
||||||
|
|
@ -50,4 +50,15 @@ class EnchantConflictGroup(
|
||||||
enchantments.addAll(enchants)
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue