From 7e8bcd2f6022ad019593d2cd9312cc4818fa746e Mon Sep 17 00:00:00 2001 From: mfnalex <1122571+mfnalex@users.noreply.github.com> Date: Mon, 29 Apr 2019 17:55:10 +0200 Subject: [PATCH] 4.0 update: inventory sorting --- pom.xml | 4 ++-- .../JeffChestSortCommandExecutor.java | 15 +++++++++++++++ .../JeffChestSort/JeffChestSortListener.java | 3 ++- .../JeffChestSort/JeffChestSortMessages.java | 5 ++++- .../JeffChestSort/JeffChestSortPlugin.java | 9 ++++++--- src/main/resources/config.yml | 4 +++- src/main/resources/plugin.yml | 11 +++++++++-- 7 files changed, 41 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 3758642..654d613 100644 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,11 @@ de.jeffclan JeffChestSort - 3.7.1 + 4.0 jar JeffChestSort - https://www.spigotmc.org/resources/1-11-1-13-chestsort-api.59773/ + https://www.chestsort.de UTF-8 diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCommandExecutor.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCommandExecutor.java index 8d2b28f..17f09d4 100644 --- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCommandExecutor.java +++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortCommandExecutor.java @@ -41,6 +41,21 @@ public class JeffChestSortCommandExecutor implements CommandExecutor { return true; + } else if(command.getName().equalsIgnoreCase("invsort")) { + // This command sorts the player's inventory + + if (!(sender instanceof Player)) { + sender.sendMessage(plugin.messages.MSG_PLAYERSONLY); + return true; + } + + Player p = (Player) sender; + + plugin.sortInventory(p.getInventory(), 9, 35); + p.sendMessage(plugin.messages.MSG_PLAYERINVSORTED); + + return true; + } return false; diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java index 227040a..f9b53c2 100644 --- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java +++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortListener.java @@ -3,6 +3,7 @@ package de.jeffclan.JeffChestSort; import java.util.UUID; import java.io.File; + import org.bukkit.GameMode; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; @@ -90,7 +91,7 @@ public class JeffChestSortListener implements Listener { // the chestsort.use permission and has /chestsort enabled) @EventHandler public void onInventoryClose(InventoryCloseEvent event) { - + // I don't know if this is neccesary. Have to check if getPlayer() always returns a player, // or if it might return an OfflinePlayer under some circumstances if (!(event.getPlayer() instanceof Player)) { diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortMessages.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortMessages.java index 9289ac0..2f2b91b 100644 --- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortMessages.java +++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortMessages.java @@ -11,7 +11,7 @@ public class JeffChestSortMessages { JeffChestSortPlugin plugin; - final String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY; + final String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY, MSG_PLAYERINVSORTED; JeffChestSortMessages(JeffChestSortPlugin plugin) { @@ -31,6 +31,9 @@ public class JeffChestSortMessages { MSG_PLAYERSONLY = ChatColor.translateAlternateColorCodes('&', plugin.getConfig() .getString("message-error-players-only", "&cError: This command can only be run by players.&r")); + + MSG_PLAYERINVSORTED = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString( + "message-player-inventory-sorted", "&7Your inventory has been sorted.")); } } diff --git a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java index a2a1b42..7d5efce 100644 --- a/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java +++ b/src/main/java/de/jeffclan/JeffChestSort/JeffChestSortPlugin.java @@ -58,7 +58,7 @@ public class JeffChestSortPlugin extends JavaPlugin { JeffChestSortListener listener; String sortingMethod; ArrayList disabledWorlds; - int currentConfigVersion = 6; + int currentConfigVersion = 7; boolean usingMatchingConfig = true; boolean debug = false; boolean verbose = true; @@ -146,6 +146,7 @@ public class JeffChestSortPlugin extends JavaPlugin { getConfig().addDefault("show-message-when-using-chest-and-sorting-is-enabled", false); getConfig().addDefault("show-message-again-after-logout", true); getConfig().addDefault("sorting-method", "{category},{itemsFirst},{name},{color}"); + getConfig().addDefault("allow-player-inventory-sorting", false); getConfig().addDefault("check-for-updates", "true"); getConfig().addDefault("auto-generate-category-files", true); getConfig().addDefault("verbose", true); // Prints some information in onEnable() @@ -187,7 +188,6 @@ public class JeffChestSortPlugin extends JavaPlugin { // the Organizer to sort inventories when a player closes a chest, shulkerbox or barrel inventory listener = new JeffChestSortListener(this); - // The sorting method will determine how stuff is sorted sortingMethod = getConfig().getString("sorting-method"); @@ -197,7 +197,10 @@ public class JeffChestSortPlugin extends JavaPlugin { // Register the /chestsort command and associate it to a new CommandExecutor JeffChestSortCommandExecutor commandExecutor = new JeffChestSortCommandExecutor(this); this.getCommand("chestsort").setExecutor(commandExecutor); - + + // Register the /invsort command + this.getCommand("invsort").setExecutor(commandExecutor); + // Does anyone actually need this? if (verbose) { getLogger().info("Current sorting method: " + sortingMethod); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dfd33e5..909b901 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -8,6 +8,7 @@ # # Please note that players will need the chestsort.use permission # or have to be OP to be able to use automatic chest sorting. +# To use /invsort, the permission chestsort.use.inventory is required. # # when set to false, new players will have to run /chestsort @@ -121,6 +122,7 @@ message-when-using-chest2: "&7Hint: Type &6/chestsort&7 to disable automatic che message-sorting-disabled: "&7Automatic chest sorting has been &cdisabled&7." message-sorting-enabled: "&7Automatic chest sorting has been &aenabled&7." message-error-players-only: "&cError: This command can only be run by players." +message-player-inventory-sorted: "&7Your inventory has been sorted." ##### Chinese - Thanks to qsefthuopq for translating! -> https://www.spigotmc.org/members/qsefthuopq.339953/ #message-when-using-chest: "&7提示: 输入 &6/chestsort&7 来启用自动整理箱子." @@ -184,4 +186,4 @@ message-error-players-only: "&cError: This command can only be run by players." ######################### # please do not change the following line manually! -config-version: 6 +config-version: 7 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4042579..1fd20c4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,10 +1,10 @@ main: de.jeffclan.JeffChestSort.JeffChestSortPlugin name: ChestSort -version: 3.7.1 +version: 4.0 api-version: 1.13 description: Allows automatic chest sorting author: mfnalex -website: https://www.spigotmc.org/resources/1-13-chestsort.59773/ +website: https://www.chestsort.de prefix: ChestSort database: false loadbefore: @@ -15,6 +15,13 @@ commands: usage: / aliases: sort permission: chestsort.use + invsort: + description: Sorts the player's inventory except hotbar, armor slots and items in hands + usage: / + aliases: [isort,inventorysort] + permission: chestsort.use.inventory permissions: chestsort.use: description: Allows usage of automatic chest sorting + chestsort.use.inventory: + description: Allows usage of inventory sorting (/invsort) \ No newline at end of file