Merge pull request #20 from JEFF-Media-GbR/fixk-sticky2

5.0.1
This commit is contained in:
JEFF 2019-05-03 17:51:17 +02:00 committed by GitHub
commit f78fe6e817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 8 deletions

View File

@ -6,7 +6,7 @@
<groupId>de.jeffclan</groupId>
<artifactId>JeffChestSort</artifactId>
<version>4.3.1-dev</version>
<version>5.0.1</version>
<packaging>jar</packaging>
<name>JeffChestSort</name>

View File

@ -13,12 +13,22 @@ public class JeffChestSortCategory implements Comparable<JeffChestSortCategory>{
// "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) {

View File

@ -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;

View File

@ -44,6 +44,7 @@ public class JeffChestSortOrganizer {
// We store a list of all Category objects
ArrayList<JeffChestSortCategory> categories = new ArrayList<JeffChestSortCategory>();
ArrayList<String> stickyCategoryNames = new ArrayList<String>();
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);

View File

@ -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