From 433c6a9bbdecf5d704b2079e947cf6cb63ec89d3 Mon Sep 17 00:00:00 2001 From: mfnalex <1122571+mfnalex@users.noreply.github.com> Date: Fri, 3 May 2019 03:38:08 +0200 Subject: [PATCH] save category files readme --- .../JeffChestSort/JeffChestSortOrganizer.java | 14 +++++++- .../JeffChestSort/JeffChestSortPlugin.java | 35 ++++++++++++++++++- ...t => _ReadMe - Category files.default.txt} | 7 ++++ src/main/resources/config.yml | 2 ++ 4 files changed, 56 insertions(+), 2 deletions(-) rename src/main/resources/categories/{_ReadMe - Category files.txt => _ReadMe - Category files.default.txt} (91%) diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java index c800847..4a01c48 100644 --- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java +++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java @@ -2,6 +2,7 @@ package de.jeffclan.JeffChestSort; import java.io.File; import java.io.FileNotFoundException; +import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -47,7 +48,18 @@ public class JeffChestSortOrganizer { // Load Categories File categoriesFolder = new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator); - File[] listOfCategoryFiles = categoriesFolder.listFiles(); + File[] listOfCategoryFiles = categoriesFolder.listFiles(new FilenameFilter() { + public boolean accept(File directory, String fileName) { + if (!fileName.endsWith(".txt")) { + return false; + } + if (fileName.matches("(?i)^\\d\\d\\d.*\\.txt$")) // Category between 900 and 999-... are default categories + { + return true; + } + return false; + } + }); for (File file : listOfCategoryFiles) { if (file.isFile()) { // Category name is the filename without .txt diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java index c89137e..e86a638 100644 --- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java +++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java @@ -32,6 +32,7 @@ package de.jeffclan.JeffChestSort; import java.io.File; import java.io.FileOutputStream; +import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -299,7 +300,39 @@ public class JeffChestSortPlugin extends JavaPlugin { // Isn't there a smarter way to find all the 9** files in the .jar? String[] defaultCategories = { "900-tools", "910-valuables", "920-combat", "930-brewing", "940-food", - "950-redstone", "960-wood", "970-stone", "980-plants", "981-corals" }; + "950-redstone", "960-wood", "970-stone", "980-plants", "981-corals","_ReadMe - Category files" }; + + // Delete all files starting with 9.. + for (File file : new File(getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator) + .listFiles(new FilenameFilter() { + public boolean accept(File directory, String fileName) { + if (!fileName.endsWith(".txt")) { + return false; + } + if (fileName.matches("(?i)9\\d\\d.*\\.txt$")) // Category between 900 and 999-... are default + // categories + { + return true; + } + return false; + } + })) { + + boolean delete = true; + + for (String name : defaultCategories) { + name=name+".txt"; + if (name.equalsIgnoreCase(file.getName())) { + delete = false; + break; + } + } + if (delete) { + file.delete(); + getLogger().warning("Deleting deprecated default category file " + file.getName()); + } + + } for (String category : defaultCategories) { diff --git a/src/main/resources/categories/_ReadMe - Category files.txt b/src/main/resources/categories/_ReadMe - Category files.default.txt similarity index 91% rename from src/main/resources/categories/_ReadMe - Category files.txt rename to src/main/resources/categories/_ReadMe - Category files.default.txt index 0699329..3448dc5 100644 --- a/src/main/resources/categories/_ReadMe - Category files.txt +++ b/src/main/resources/categories/_ReadMe - Category files.default.txt @@ -3,14 +3,21 @@ ############# You can define custom category files for ChestSort using simple .txt files. + If you have {category} in your sorting-method, it will get replaced with the category name. + Category names are determined by the file names. The name must start with a number ranging from 000 to 899 and end with .txt + Default categories are prefixed with 900 to 999. Please do not edit the default categories. You can instead copy or rename the default files and edit those instead. +WARNING: All files with names starting between 900 and 999 will be deleted on start. + If you put {keepCategoryOrder} behind {category} in the sorting-method, the items will be ordered exactly as listed in the category files. Otherwise, they will be grouped by category and then sorted according to the remaining variables in your sorting-method. + Category files can contain asterisks (*) as wildcard character at the beginning and/or end of an expression, but not in the middle. + Category files can also contain comments using the hashtag (#) symbol \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b47a757..3f5c9db 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -39,6 +39,8 @@ show-message-again-after-logout: true # If you wish to edit those, you can disable the generation of these # files, because otherwise all your changes in the pregenerated # files will be overwritten on each server startup. +# However, a much smarter option is to copy the default files +# and rename them to from 900... to 800... and edit those instead. auto-generate-category-files: true # you can choose when ChestSort should sort chests.