diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java index 278eec3..c800847 100644 --- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java +++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java @@ -53,7 +53,7 @@ public class JeffChestSortOrganizer { // Category name is the filename without .txt String categoryName = file.getName().replaceFirst(".txt", ""); try { - categories.add(new JeffChestSortCategory(categoryName,getArrayFromCategoryFile(file))); + categories.add(new JeffChestSortCategory(categoryName,loadCategoryFile(file))); if(plugin.verbose) { plugin.getLogger().info("Loaded category file "+file.getName()); } @@ -67,7 +67,7 @@ public class JeffChestSortOrganizer { } // Returns an array with all typematches listed in the category file - TypeMatchPositionPair[] getArrayFromCategoryFile(File file) throws FileNotFoundException { + TypeMatchPositionPair[] loadCategoryFile(File file) throws FileNotFoundException { Scanner sc = new Scanner(file); List lines = new ArrayList(); short currentLine=1; @@ -173,7 +173,7 @@ public class JeffChestSortOrganizer { // This method takes a sortable item name and checks all categories for a match // If none, matches, return "" (it will be put behind all categorized items when sorting by category) - CategoryLinePair getCategory(String typeName) { + CategoryLinePair getCategoryLinePair(String typeName) { typeName = typeName.toLowerCase(); for (JeffChestSortCategory cat : categories) { short matchingLineNumber = cat.matches(typeName); @@ -200,7 +200,7 @@ public class JeffChestSortOrganizer { String[] typeAndColor = getTypeAndColor(item.getType().name()); String typeName = typeAndColor[0]; String color = typeAndColor[1]; - String category = getCategory(item.getType().name()).getCategoryName(); + String category = getCategoryLinePair(item.getType().name()).getCategoryName(); String customName = (plugin.debug) ? "~customName~" : emptyPlaceholderString; if(item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName()!=null) { customName=item.getItemMeta().getDisplayName(); @@ -210,7 +210,7 @@ public class JeffChestSortOrganizer { String[] loreArray=item.getItemMeta().getLore().toArray(new String[0]); lore = String.join(",", loreArray); } - short lineNumber = getCategory(item.getType().name()).getPosition(); + String lineNumber = getCategoryLinePair(item.getType().name()).getFormattedPosition(); // Generate the strings that finally are used for sorting. @@ -221,7 +221,7 @@ public class JeffChestSortOrganizer { sortableString = sortableString.replaceAll("\\{name\\}", typeName); sortableString = sortableString.replaceAll("\\{color\\}", color); sortableString = sortableString.replaceAll("\\{category\\}", category); - sortableString = sortableString.replaceAll("\\{line\\}", String.valueOf(lineNumber)); + sortableString = sortableString.replaceAll("\\{line\\}", lineNumber); sortableString = sortableString.replaceAll("\\{customName\\}", customName); sortableString = sortableString.replaceAll("\\{lore\\}", lore); diff --git a/src/main/java/de/jeffclan/utils/CategoryLinePair.java b/src/main/java/de/jeffclan/utils/CategoryLinePair.java index ca5758b..3c3c62f 100644 --- a/src/main/java/de/jeffclan/utils/CategoryLinePair.java +++ b/src/main/java/de/jeffclan/utils/CategoryLinePair.java @@ -3,10 +3,12 @@ package de.jeffclan.utils; public class CategoryLinePair { String categoryName; + String formattedPosition; short position; public CategoryLinePair(String categoryName,short position) { this.categoryName=categoryName; + this.formattedPosition=Utils.shortToStringWithLeadingZeroes(position); this.position=position; } @@ -14,7 +16,11 @@ public class CategoryLinePair { return categoryName; } - public short getPosition() { + public String getFormattedPosition() { + return formattedPosition; + } + + public int getPosition() { return position; } } diff --git a/src/main/java/de/jeffclan/utils/TypeMatchPositionPair.java b/src/main/java/de/jeffclan/utils/TypeMatchPositionPair.java index 8dbf4c9..afc9feb 100644 --- a/src/main/java/de/jeffclan/utils/TypeMatchPositionPair.java +++ b/src/main/java/de/jeffclan/utils/TypeMatchPositionPair.java @@ -3,6 +3,7 @@ package de.jeffclan.utils; public class TypeMatchPositionPair { String typeMatch; + String formattedPosition; public String getTypeMatch() { return typeMatch; } @@ -10,12 +11,17 @@ public class TypeMatchPositionPair { public short getPosition() { return position; } + + public String getFormattedPosition() { + return formattedPosition; + } short position; public TypeMatchPositionPair(String typeMatch,short position) { this.typeMatch=typeMatch; this.position=position; + this.formattedPosition=Utils.shortToStringWithLeadingZeroes(position); } } diff --git a/src/main/java/de/jeffclan/utils/Utils.java b/src/main/java/de/jeffclan/utils/Utils.java index dfdf98f..ec9b17e 100644 --- a/src/main/java/de/jeffclan/utils/Utils.java +++ b/src/main/java/de/jeffclan/utils/Utils.java @@ -28,4 +28,8 @@ public class Utils { } return buf; } + + public static String shortToStringWithLeadingZeroes(short number) { + return String.format("%05d", number); + } }