mirror of
https://github.com/JEFF-Media-GbR/ChestSort.git
synced 2024-11-26 20:48:12 +01:00
add leading zeroes to line numbers
This commit is contained in:
parent
37b540eeaa
commit
8931901e30
@ -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<TypeMatchPositionPair> lines = new ArrayList<TypeMatchPositionPair>();
|
||||
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 "<none>" (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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,4 +28,8 @@ public class Utils {
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
public static String shortToStringWithLeadingZeroes(short number) {
|
||||
return String.format("%05d", number);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user