diff --git a/CHANGELOG.md b/CHANGELOG.md index 97f29d0..e05f561 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 8.17.1-SNAPSHOT - Added possibility to sort a player's inventory from console using /invsort [toggle|on|off|hotbar|inv|all] +- Added placeholders (see new config.yml) +- Added "use permissions" metric ## 8.17.0 - Added option to disable automatic sorting and/or automatic inventory sorting. Hotkeys will still work if enabled. When running /chestsort while automatic sorting is disabled, it will display the hotkeys gui instead. diff --git a/pom.xml b/pom.xml index 8f60085..ebc1e23 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ ChestSort https://www.chestsort.de Automatically sorts your chests! - 8.17.1-SNAPSHOT + 8.17.1 jar @@ -85,6 +85,10 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + placeholderapi + https://repo.extendedclip.com/content/repositories/placeholderapi/ + bungeecord-repo https://oss.sonatype.org/content/repositories/snapshots @@ -104,6 +108,12 @@ + + me.clip + placeholderapi + 2.10.6 + provided + org.spigotmc spigot-api diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortInvSortCommand.java b/src/main/java/de/jeff_media/ChestSort/ChestSortInvSortCommand.java index dd8cb07..eea2128 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortInvSortCommand.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortInvSortCommand.java @@ -20,11 +20,6 @@ public class ChestSortInvSortCommand implements CommandExecutor { Player p = null; - // This command toggles automatic chest sorting for the player that runs the command - if (!command.getName().equalsIgnoreCase("invsort")) { - return false; - } - if(args.length>0 && args[0].equalsIgnoreCase("help")) { return false; } @@ -45,6 +40,8 @@ public class ChestSortInvSortCommand implements CommandExecutor { if(args.length>1) { args = new String[] { args[1] }; + } else { + args = new String[0]; } //sender.sendMessage(plugin.messages.MSG_PLAYERSONLY); diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortPlayerSetting.java b/src/main/java/de/jeff_media/ChestSort/ChestSortPlayerSetting.java index a2c752b..58fd06c 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortPlayerSetting.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortPlayerSetting.java @@ -11,10 +11,10 @@ public class ChestSortPlayerSetting { // - Did this player see the message on how to use ChestSort (message-when-using-chest in config.yml) // Sorting enabled for this player? - boolean sortingEnabled; + public boolean sortingEnabled; // Inventory sorting enabled for this player? - boolean invSortingEnabled; + public boolean invSortingEnabled; // Hotkey settings boolean middleClick, shiftClick, doubleClick, shiftRightClick, leftClick, rightClick; diff --git a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java index c2bac2f..7d9f8ac 100644 --- a/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java +++ b/src/main/java/de/jeff_media/ChestSort/ChestSortPlugin.java @@ -42,6 +42,7 @@ import java.util.Map; import java.util.UUID; import de.jeff_media.ChestSort.hooks.GenericGUIHook; +import de.jeff_media.ChestSort.placeholders.ChestSortPlaceholders; import de.jeff_media.PluginUpdateChecker.PluginUpdateChecker; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; @@ -69,7 +70,7 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo String sortingMethod; ArrayList disabledWorlds; ChestSortAPIHandler api; - final int currentConfigVersion = 41; + final int currentConfigVersion = 42; boolean usingMatchingConfig = true; protected boolean debug = false; boolean verbose = true; @@ -250,6 +251,11 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo } } + public ChestSortPlayerSetting getPlayerSetting(Player p) { + registerPlayerIfNeeded(p); + return perPlayerSettings.get(p.getUniqueId().toString()); + } + @Override public void onEnable() { @@ -259,6 +265,10 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo mcMinorVersion = Integer.parseInt(tmpVersion.substring(0,tmpVersion.indexOf("_"))); load(false); + + if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null){ + new ChestSortPlaceholders(this).register(); + } } private String getCategoryList() { @@ -322,6 +332,8 @@ public class ChestSortPlugin extends JavaPlugin implements de.jeff_media.ChestSo () -> Boolean.toString(getConfig().getBoolean("additional-hotkeys.left-click")))); bStats.addCustomChart(new Metrics.SimplePie("hotkey_right_click", () -> Boolean.toString(getConfig().getBoolean("additional-hotkeys.right-click")))); + bStats.addCustomChart(new Metrics.SimplePie("use_permissions", + () -> Boolean.toString(getConfig().getBoolean("use-permissions")))); } diff --git a/src/main/java/de/jeff_media/ChestSort/placeholders/ChestSortPlaceholders.java b/src/main/java/de/jeff_media/ChestSort/placeholders/ChestSortPlaceholders.java new file mode 100644 index 0000000..e6a0ca1 --- /dev/null +++ b/src/main/java/de/jeff_media/ChestSort/placeholders/ChestSortPlaceholders.java @@ -0,0 +1,108 @@ +package de.jeff_media.ChestSort.placeholders; + +import de.jeff_media.ChestSort.ChestSortPlugin; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.entity.Player; + +public class ChestSortPlaceholders extends PlaceholderExpansion { + private ChestSortPlugin main; + + + public ChestSortPlaceholders(ChestSortPlugin main){ + this.main = main; + } + + /** + * Because this is an internal class, + * you must override this method to let PlaceholderAPI know to not unregister your expansion class when + * PlaceholderAPI is reloaded + * + * @return true to persist through reloads + */ + @Override + public boolean persist(){ + return true; + } + + /** + * Because this is a internal class, this check is not needed + * and we can simply return {@code true} + * + * @return Always true since it's an internal class. + */ + @Override + public boolean canRegister(){ + return true; + } + + /** + * The name of the person who created this expansion should go here. + *
For convienience do we return the author from the plugin.yml + * + * @return The name of the author as a String. + */ + @Override + public String getAuthor(){ + return main.getDescription().getAuthors().toString(); + } + + /** + * The placeholder identifier should go here. + *
This is what tells PlaceholderAPI to call our onRequest + * method to obtain a value if a placeholder starts with our + * identifier. + *
This must be unique and can not contain % or _ + * + * @return The identifier in {@code %_%} as String. + */ + @Override + public String getIdentifier(){ + return "chestsort"; + } + + /** + * This is the version of the expansion. + *
You don't have to use numbers, since it is set as a String. + * + * For convienience do we return the version from the plugin.yml + * + * @return The version as a String. + */ + @Override + public String getVersion(){ + return main.getDescription().getVersion(); + } + + /** + * This is the method called when a placeholder with our identifier + * is found and needs a value. + *
We specify the value identifier in this method. + *
Since version 2.9.1 can you use OfflinePlayers in your requests. + * + * @param player + * A {@link org.bukkit.Player Player}. + * @param identifier + * A String containing the identifier/value. + * + * @return possibly-null String of the requested identifier. + */ + @Override + public String onPlaceholderRequest(Player player, String identifier){ + + if(player == null){ + return ""; + } + + if(identifier.equals("sortingenabled")){ + return Boolean.toString(main.getPlayerSetting(player).sortingEnabled); + } + + if(identifier.equals("invsortingenabled")){ + return Boolean.toString(main.getPlayerSetting(player).invSortingEnabled); + } + + // We return null if an invalid placeholder (f.e. %someplugin_placeholder3%) + // was provided + return null; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c81f8fd..f233ca2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,11 +10,43 @@ # Don't worry! Your changes will be kept after every update. # -# -# 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. -# +############################### +####### Commands ####### +############################### + +# /sort (or /chestsort) Toggle automatic sorting for containers (chests, barrels, enderchests, llamas, etc.) +# /sort on Enable automatic sorting for containers +# /sort off Disable automatic sorting for containers +# /sort hotkeys Open a GUI to change the sorting hotkeys +# /sort help Display help about the /sort (or /chestsort) command + +# /isort (or /invsort) Sort the player's inventory +# /isort hotbar Sort the player's hotbar +# /isort all Sort the player's inventory and hotbar +# /isort toggle Toggle automatic sorting for the player's inventory +# /isort on Enable automatic sorting for the player's inventory +# /isort off Disable automatic sorting for the player's inventory +# /isort help Display help about the /isort (or /invsort) command + + +############################### +####### Permissions ####### +############################### + +# chestsort.use Allows to sort containers using automatic sorting (/sort) or via hotkeys +# chestsort.use.inventory Allows to sort the player's inventory using automatic sorting (/isort) or via hotkeys +# chestsort.reload Allows to reload the config using /sort reload + + +############################### +####### Placeholders ####### +############################### + +# When using PlaceholderAPI, you can use the following placeholders: + +# %chestsort_sortingenabled% - true if this player has automatic sorting enabled for containers +# %chestsort_invsortingenabled% - true if this player has automatic sorting enabled for the player's inventory + ############################ ##### Default settings ##### @@ -588,4 +620,4 @@ log: false # Please DO NOT change the following line manually! # It is used by the automatic config updater. -config-version: 41 \ No newline at end of file +config-version: 42 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 50d4748..f789a82 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.17.1-SNAPSHOT +version: 8.17.1 api-version: "1.13" description: Allows automatic chest sorting author: mfnalex @@ -21,7 +21,7 @@ commands: / help -- Shows help about this command aliases: chestsort permission: chestsort.use - invsort: + isort: description: Toggle automatic inventory sorting or sorts the player's inventory. usage: | / -- Sort your inventory @@ -31,7 +31,7 @@ commands: / hotbar -- Sort your hotbar / all -- Sort your inventory and hotbar / help -- Shows help about this command - aliases: [isort,inventorysort] + aliases: [invsort,inventorysort] permission: chestsort.use.inventory permissions: chestsort.use: