diff --git a/config.yml b/config.yml index 2290fe7..4af47b4 100644 --- a/config.yml +++ b/config.yml @@ -35,6 +35,14 @@ show-message-again-after-logout: true # join the server check-for-updates: true +# to sort by category, we need category files. ChestSort comes +# with a number of pregenerated category files, named +# 900-valuables.txt, 910-tools.txt, 920-combat.txt, ... +# 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. +auto-generate-category-files: true + ########################## ##### Sorting Method ##### ########################## diff --git a/plugin.yml b/plugin.yml index 79325a4..d2238b4 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ main: de.jeffclan.JeffChestSort.JeffChestSortPlugin name: ChestSort -version: 2.0-pre1 +version: 2.0.0 api-version: 1.13 description: Allows automatic chest sorting author: mfnalex diff --git a/src/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java b/src/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java index 7495805..4d2e52c 100644 --- a/src/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java +++ b/src/de/jeffclan/JeffChestSort/JeffChestSortOrganizer.java @@ -110,6 +110,20 @@ public class JeffChestSortOrganizer { typeName = "egg_" + typeName; } + // polished_andesite -> andesite_polished + if(typeName.startsWith("polished_")) { + typeName = typeName.replaceFirst("polished_", ""); + typeName = typeName + "_polished"; + } + + if(typeName.equalsIgnoreCase("wet_sponge")) { + typeName = "sponge_wet"; + } + + if(typeName.equalsIgnoreCase("carved_pumpkin")) { + typeName = "pumpkin_carved"; + } + // Sort armor: helmet, chestplate, leggings, boots if(typeName.endsWith("helmet")) { typeName = typeName.replaceFirst("helmet", "1_helmet"); diff --git a/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java b/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java index 353d3fc..e77f331 100644 --- a/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java +++ b/src/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java @@ -10,6 +10,7 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -32,43 +33,29 @@ public class JeffChestSortPlugin extends JavaPlugin { @Override public void onEnable() { - if(debug) { + /*if(debug) { System.out.println("======= ALL MATERIALS ======"); for(Material mat : Material.values()) { System.out.println(mat.name().toLowerCase()); } System.out.println("============================"); - } + }*/ createConfig(); saveDefaultCategories(); messages = new JeffChestSortMessages(this); organizer = new JeffChestSortOrganizer(this); updateChecker = new JeffChestSortUpdateChecker(this); - sortingMethod = getConfig().getString("sorting-method", "{itemsFirst},{name},{color}"); + sortingMethod = getConfig().getString("sorting-method"); getServer().getPluginManager().registerEvents(new JeffChestSortListener(this), this); JeffChestSortCommandExecutor commandExecutor = new JeffChestSortCommandExecutor(this); this.getCommand("chestsort").setExecutor(commandExecutor); - - - - getLogger().info("Current sorting method: " + sortingMethod); - - if (getConfig().getInt("config-version", 0) != currentConfigVersion) { - getLogger().warning("========================================================"); - getLogger().warning("YOU ARE USING AN OLD CONFIG FILE!"); - getLogger().warning("This is not a problem, as ChestSort will just use the"); - getLogger().warning("default settings for unset values. However, if you want"); - getLogger().warning("to configure the new options, please go to"); - getLogger().warning("https://www.spigotmc.org/resources/1-13-chestsort.59773/"); - getLogger().warning("and replace your config.yml with the new one. You can"); - getLogger().warning("then insert your old changes into the new file."); - getLogger().warning("========================================================"); - usingMatchingConfig = false; - } + getLogger().info("Sorting enabled by default: " + getConfig().getBoolean("sorting-enabled-by-default")); + getLogger().info("Auto generate category files: "+getConfig().getBoolean("auto-generate-category-files")); + getLogger().info("Check for updates: "+getConfig().getBoolean("check-for-updates")); Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { public void run() { @@ -104,9 +91,15 @@ public class JeffChestSortPlugin extends JavaPlugin { private void saveDefaultCategories() { String[] defaultCategories = { "900-valuables","910-tools","920-combat","930-brewing","940-food","950-redstone","960-wood","970-stone","980-plants","981-corals" }; + + if(getConfig().getBoolean("auto-generate-category-files",true) != true) { + + return; + } + for (String category : defaultCategories) { - if(debug) getLogger().info("Trying to save default category file: " + category); + //getLogger().info("Saving default category file: " + category); FileOutputStream fopDefault = null; File fileDefault; @@ -160,12 +153,52 @@ public class JeffChestSortPlugin extends JavaPlugin { void createConfig() { this.saveDefaultConfig(); + + if (getConfig().getInt("config-version", 0) < 5) { + getLogger().warning("========================================================"); + getLogger().warning("You are using a config file that has been generated"); + getLogger().warning("prior to ChestSort version 2.0.0."); + getLogger().warning("To allow everyone to use the new features, your config"); + getLogger().warning("has been renamed to config.old.yml and a new one has"); + getLogger().warning("been generated. Please examine the new config file to"); + getLogger().warning("see the new possibilities and adjust your settings."); + getLogger().warning("========================================================"); + + + File configFile = new File(getDataFolder().getAbsolutePath()+File.separator+"config.yml"); + File oldConfigFile = new File(getDataFolder().getAbsolutePath()+File.separator+"config.old.yml"); + if(oldConfigFile.getAbsoluteFile().exists()) { + oldConfigFile.getAbsoluteFile().delete(); + } + configFile.getAbsoluteFile().renameTo(oldConfigFile.getAbsoluteFile()); + saveDefaultConfig(); + try { + getConfig().load(configFile.getAbsoluteFile()); + } catch (IOException | InvalidConfigurationException e) { + getLogger().warning("Could not load freshly generated config file!"); + e.printStackTrace(); + } + } else if (getConfig().getInt("config-version", 0) != currentConfigVersion) { + getLogger().warning("========================================================"); + getLogger().warning("YOU ARE USING AN OLD CONFIG FILE!"); + getLogger().warning("This is not a problem, as ChestSort will just use the"); + getLogger().warning("default settings for unset values. However, if you want"); + getLogger().warning("to configure the new options, please go to"); + getLogger().warning("https://www.spigotmc.org/resources/1-13-chestsort.59773/"); + getLogger().warning("and replace your config.yml with the new one. You can"); + getLogger().warning("then insert your old changes into the new file."); + getLogger().warning("========================================================"); + usingMatchingConfig = false; + } + File playerDataFolder = new File(getDataFolder().getPath() + File.separator + "playerdata"); - if (!playerDataFolder.exists()) { + if (!playerDataFolder.getAbsoluteFile().exists()) { + getLogger().info("playerdata directory does not exist, creating..."); playerDataFolder.mkdir(); } File categoriesFolder = new File(getDataFolder().getPath() + File.separator + "categories"); - if (!categoriesFolder.exists()) { + if (!categoriesFolder.getAbsoluteFile().exists()) { + getLogger().info("categories directory does not exist, creating..."); categoriesFolder.mkdir(); } @@ -175,6 +208,7 @@ public class JeffChestSortPlugin extends JavaPlugin { getConfig().addDefault("show-message-again-after-logout", true); getConfig().addDefault("sorting-method", "{category},{itemsFirst},{name},{color}"); getConfig().addDefault("check-for-updates", true); + getConfig().addDefault("auto-generate-category-files", true); } void unregisterPlayer(Player p) { diff --git a/src/de/jeffclan/utils/categories/950-redstone.default.txt b/src/de/jeffclan/utils/categories/950-redstone.default.txt index c9c75e5..29c2e9b 100644 --- a/src/de/jeffclan/utils/categories/950-redstone.default.txt +++ b/src/de/jeffclan/utils/categories/950-redstone.default.txt @@ -13,6 +13,7 @@ tripwire_hook trapped_chest daylight_detector redstone_block +redstone_ore hopper dropper iron_trapdoor diff --git a/src/de/jeffclan/utils/categories/970-stone.default.txt b/src/de/jeffclan/utils/categories/970-stone.default.txt index b099260..cdfd40b 100644 --- a/src/de/jeffclan/utils/categories/970-stone.default.txt +++ b/src/de/jeffclan/utils/categories/970-stone.default.txt @@ -1,6 +1,22 @@ stone cobblestone granite +polished_granite diorite +polished_diorite andesite -*stone_bricks \ No newline at end of file +polished_andesite +*stone_bricks +stone_slab +cobblestone_slab +stone_brick_slab +smooth_stone +mossy_cobblestone +cobblestone_stairs +*_stone_bricks +stone_brick_stairs +cobblestone_wall +mossy_cobblestone_wall +brick_stairs +bricks +brick_slab \ No newline at end of file diff --git a/src/de/jeffclan/utils/categories/980-plants.default.txt b/src/de/jeffclan/utils/categories/980-plants.default.txt index aec52b3..d9a1543 100644 --- a/src/de/jeffclan/utils/categories/980-plants.default.txt +++ b/src/de/jeffclan/utils/categories/980-plants.default.txt @@ -25,4 +25,7 @@ lilac rose_bush peony tall_grass -large_fern \ No newline at end of file +large_fern +pumpkin +carved_pumpkin +melon \ No newline at end of file