diff --git a/CHANGELOG.md b/CHANGELOG.md index 472ef30..188704a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog -## 8.11.1-SNAPSHOT +## 8.12.0 +- Changed name of command /chestsort to /sort. You can still use /chestsort though. +- Fixed weird config updater problem on systems that don't properly support UTF-8 (like Windows) - Improved help messages - Huge code cleanup - Improved performance by caching Reflection checks in the Minepacks hook diff --git a/pom.xml b/pom.xml index bb11bda..1c5c4d4 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ JeffChestSort https://www.chestsort.de Automatically sorts your chests! - 8.11.1-SNAPSHOT + 8.12.0 jar @@ -132,7 +132,7 @@ de.jeff_media PluginUpdateChecker - [1.2, + 1.3.1 compile diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortChestSortCommand.java b/src/main/java/de/jeff_media/ChestSort/ChestSortChestSortCommand.java index ce79971..923dc67 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortChestSortCommand.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortChestSortCommand.java @@ -20,7 +20,7 @@ public class ChestSortChestSortCommand implements CommandExecutor { public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNull String label, String[] args) { // This command toggles automatic chest sorting for the player that runs the command - if (!command.getName().equalsIgnoreCase("chestsort")) { + if (!command.getName().equalsIgnoreCase("sort")) { return false; } diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortConfigUpdater.java b/src/main/java/de/jeff_media/ChestSort/ChestSortConfigUpdater.java index d50817a..b86a83b 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortConfigUpdater.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortConfigUpdater.java @@ -1,9 +1,8 @@ package de.jeff_media.ChestSort; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Map; import java.util.Scanner; @@ -36,6 +35,12 @@ public class ChestSortConfigUpdater { plugin.getConfig().set("sorting-hotkeys.shift-right-click", plugin.getConfig().getBoolean("hotkeys.shift-right-click")); } + try { + Files.deleteIfExists(new File(plugin.getDataFolder().getAbsolutePath()+File.separator+"config.old.yml").toPath()); + } catch (IOException e) { + + } + if (plugin.debug) plugin.getLogger().info("rename config.yml -> config.old.yml"); Utils.renameFileInPluginDir(plugin, "config.yml", "config.old.yml"); @@ -44,7 +49,7 @@ public class ChestSortConfigUpdater { plugin.saveDefaultConfig(); File oldConfigFile = new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "config.old.yml"); - FileConfiguration oldConfig = new YamlConfiguration(); + FileConfiguration oldConfig = YamlConfiguration.loadConfiguration(oldConfigFile); try { oldConfig.load(oldConfigFile); @@ -59,7 +64,7 @@ public class ChestSortConfigUpdater { try { Scanner scanner = new Scanner( - new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "config.yml")); + new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "config.yml"),"UTF-8"); while (scanner.hasNextLine()) { linesInDefaultConfig.add(scanner.nextLine() + ""); } @@ -117,10 +122,10 @@ public class ChestSortConfigUpdater { newLines.add(newline); } - FileWriter fw; + BufferedWriter fw; String[] linesArray = newLines.toArray(new String[linesInDefaultConfig.size()]); try { - fw = new FileWriter(plugin.getDataFolder().getAbsolutePath() + File.separator + "config.yml"); + fw = Files.newBufferedWriter(new File(plugin.getDataFolder().getAbsolutePath(),"config.yml").toPath(), StandardCharsets.UTF_8); for (String s : linesArray) { fw.write(s + "\n"); } diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java b/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java index 283e2b6..93a8506 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortListener.java @@ -37,11 +37,6 @@ public class ChestSortListener implements Listener { plugin.permissionsHandler.addPermissions(event.getPlayer()); - // OPs will get an update notice if a new update is available - if (event.getPlayer().isOp()) { - plugin.updateChecker.sendUpdateMessage(event.getPlayer()); - } - // Put player into our perPlayerSettings map plugin.registerPlayerIfNeeded(event.getPlayer()); @@ -479,23 +474,27 @@ public class ChestSortListener implements Listener { == ChestSortPlayerSetting.DoubleClickType.LEFT_CLICK) { // Left double click: put everything into destination plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), false); + plugin.organizer.sortInventory(e.getInventory()); } else { // Left single click: put only matching items into destination plugin.organizer.stuffPlayerInventoryIntoAnother(p.getInventory(), e.getInventory(), true); } + } else if (e.isRightClick() && setting.rightClick) { if (setting.getCurrentDoubleClick(plugin, ChestSortPlayerSetting.DoubleClickType.RIGHT_CLICK) == ChestSortPlayerSetting.DoubleClickType.RIGHT_CLICK) { // Right double click: put everything into player inventory plugin.organizer.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(), e.getInventory(), false); + plugin.organizer.sortInventory(p.getInventory(),9,35); } else { // Right single click: put only matching items into player inventory plugin.organizer.stuffInventoryIntoAnother(e.getInventory(), p.getInventory(), e.getInventory(), true); - } + } //plugin.organizer.sortInventory(e.getInventory()); plugin.organizer.updateInventoryView(e.getInventory()); + plugin.organizer.updateInventoryView(p.getInventory()); } diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java b/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java index 4f39188..e586b19 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortOrganizer.java @@ -510,6 +510,7 @@ public class ChestSortOrganizer { // duplication int currentSlot = startSlot; for (ItemStack item : tempInventory.getContents()) { + if(item==null) break; // TODO: If there is item loss, change break to continue (should not happen) while (unsortableSlots.contains(currentSlot) && currentSlot < endSlot) { currentSlot++; } diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java index a64e32a..c87bd00 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java @@ -67,7 +67,7 @@ public class ChestSortPlugin extends JavaPlugin { String sortingMethod; ArrayList disabledWorlds; ChestSortAPI api; - final int currentConfigVersion = 33; + final int currentConfigVersion = 34; boolean usingMatchingConfig = true; protected boolean debug = false; boolean verbose = true; @@ -131,6 +131,7 @@ public class ChestSortPlugin extends JavaPlugin { // This saves the config.yml included in the .jar file, but it will not // overwrite an existing config.yml this.saveDefaultConfig(); + reloadConfig(); // Load disabled-worlds. If it does not exist in the config, it returns null. // That's no problem @@ -451,8 +452,8 @@ public class ChestSortPlugin extends JavaPlugin { getServer().getPluginManager().registerEvents(settingsGUI, this); ChestSortChestSortCommand chestsortCommandExecutor = new ChestSortChestSortCommand(this); ChestSortTabCompleter tabCompleter = new ChestSortTabCompleter(); - this.getCommand("chestsort").setExecutor(chestsortCommandExecutor); - this.getCommand("chestsort").setTabCompleter(tabCompleter); + this.getCommand("sort").setExecutor(chestsortCommandExecutor); + this.getCommand("sort").setTabCompleter(tabCompleter); ChestSortInvSortCommand invsortCommandExecutor = new ChestSortInvSortCommand(this); this.getCommand("invsort").setExecutor(invsortCommandExecutor); this.getCommand("invsort").setTabCompleter(tabCompleter); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 62672b6..4bec36d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -573,4 +573,4 @@ debug: false # Please DO NOT change the following line manually! # It is used by the automatic config updater. -config-version: 33 \ No newline at end of file +config-version: 34 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 68b5a8c..4db0fdf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: de.jeff_media.ChestSort.ChestSortPlugin name: ChestSort -version: 8.11.1-SNAPSHOT +version: 8.12.0 api-version: "1.13" description: Allows automatic chest sorting author: mfnalex @@ -10,14 +10,14 @@ database: false loadbefore: [InvUnload] softdepend: [CrackShot,InventoryPages,Minepacks] commands: - chestsort: + sort: description: Toggle automatic chest sorting. usage: | / -- Toggles automatic chest sorting / on|off -- Enables/disabled automatic chest sorting / hotkeys -- Opens hotkeys GUI to enable/disable hotkeys / reload -- Reloads config - aliases: sort + aliases: chestsort permission: chestsort.use invsort: description: Toggle automatic inventory sorting or sorts the player's inventory. When no option is specified, only the regular inventory (excluding the hotbar) is sorted.