diff --git a/pom.xml b/pom.xml
index b050587..91d55a9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
de.jeffclan
JeffChestSort
- 4.3.1-dev
+ 5.0.1
jar
JeffChestSort
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCategory.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCategory.java
index f2d5766..76157e2 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCategory.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCategory.java
@@ -13,12 +13,22 @@ public class JeffChestSortCategory implements Comparable{
// "COARSE_DIRT" will match the typeMatch "*dirt"
String name;
+ boolean sticky = false;
TypeMatchPositionPair[] typeMatches;
JeffChestSortCategory(String name, TypeMatchPositionPair[] typeMatchPositionPairs) {
this.name = name;
this.typeMatches = typeMatchPositionPairs;
}
+
+ void setSticky() {
+ this.sticky=true;
+ }
+
+ boolean isSticky() {
+ return this.sticky;
+ }
+
// Checks whether a the given itemname fits into this category and returns the line number. 0 means not found
short matches(String itemname) {
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortConfigUpdater.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortConfigUpdater.java
index 13f0a64..f27d807 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortConfigUpdater.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortConfigUpdater.java
@@ -1,9 +1,7 @@
package de.jeffclan.JeffChestSort;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java
index ae3f504..143f7e7 100644
--- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java
+++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java
@@ -44,6 +44,7 @@ public class JeffChestSortOrganizer {
// We store a list of all Category objects
ArrayList categories = new ArrayList();
+ ArrayList stickyCategoryNames = new ArrayList();
JeffChestSortOrganizer(JeffChestSortPlugin plugin) {
this.plugin = plugin;
@@ -85,6 +86,15 @@ public class JeffChestSortOrganizer {
}
}
}
+
+ // Make categories sticky
+ for(String catName : stickyCategoryNames) {
+ for(JeffChestSortCategory cat : categories) {
+ if(catName.equalsIgnoreCase(cat.name)) {
+ cat.setSticky();
+ }
+ }
+ }
}
@@ -118,6 +128,7 @@ public class JeffChestSortOrganizer {
if (currentLine.toLowerCase().endsWith("=true")) {
appendLineNumber = true;
+ makeCategoryStickyByFileName(file.getName());
if (plugin.debug)
plugin.getLogger().info("Sticky set to true in " + file.getName());
}
@@ -136,6 +147,14 @@ public class JeffChestSortOrganizer {
return result;
}
+ private void makeCategoryStickyByFileName(String name) {
+ String catName = name.replaceAll("\\.txt$", "");
+
+ stickyCategoryNames.add(catName);
+
+
+ }
+
// Convert the item name to what I call a "sortable item name".
// Sorry, the method name is a bit misleading.
// The array's [0] value contains the item name with a few fixes, see below
@@ -258,8 +277,13 @@ public class JeffChestSortOrganizer {
String typeName = typeAndColor[0];
String color = typeAndColor[1];
CategoryLinePair categoryLinePair = getCategoryLinePair(item.getType().name());
- // String categoryName = categoryLinePair.getCategoryName();
- String categorySticky = categoryLinePair.getCategoryNameSticky();
+ String categoryName = categoryLinePair.getCategoryName();
+ String categorySticky = categoryName;
+ String lineNumber = getCategoryLinePair(item.getType().name()).getFormattedPosition();
+ if(stickyCategoryNames.contains(categoryName)) {
+ categorySticky = categoryName+"~"+lineNumber;
+ }
+
String customName = (plugin.debug) ? "~customName~" : emptyPlaceholderString;
if (item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName() != null) {
customName = item.getItemMeta().getDisplayName();
@@ -270,7 +294,7 @@ public class JeffChestSortOrganizer {
String[] loreArray = item.getItemMeta().getLore().toArray(new String[0]);
lore = String.join(",", loreArray);
}
- String lineNumber = getCategoryLinePair(item.getType().name()).getFormattedPosition();
+
// Generate the strings that finally are used for sorting.
// They are generated according to the config.yml's sorting-method option
@@ -280,7 +304,7 @@ public class JeffChestSortOrganizer {
sortableString = sortableString.replaceAll("\\{name\\}", typeName);
sortableString = sortableString.replaceAll("\\{color\\}", color);
sortableString = sortableString.replaceAll("\\{category\\}", categorySticky);
- sortableString = sortableString.replaceAll("\\{line\\}", lineNumber);
+ sortableString = sortableString.replaceAll("\\{keepCategoryOrder\\}", lineNumber);
sortableString = sortableString.replaceAll("\\{customName\\}", customName);
sortableString = sortableString.replaceAll("\\{lore\\}", lore);
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index f920fee..0c86c0f 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
main: de.jeffclan.JeffChestSort.JeffChestSortPlugin
name: ChestSort
-version: 4.3.1-dev
+version: 5.0.1
api-version: 1.13
description: Allows automatic chest sorting
author: mfnalex