Merge pull request #92 from JEFF-Media-GbR/8.16.1

8.17.2
This commit is contained in:
mfnalex 2020-07-24 16:40:38 +02:00 committed by GitHub
commit 07af660220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 203 additions and 18 deletions

View File

@ -1,5 +1,11 @@
# Changelog
## 8.17.2
- Added possibility to sort a player's inventory from console using /invsort <player> [toggle|on|off|hotbar|inv|all]
- Added placeholders (see new config.yml)
- Added "use permissions" metric
## 8.17.1
- Improved sorting of colored blocks
- White, light gray, gray and black comes first

10
pom.xml
View File

@ -85,6 +85,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
@ -104,6 +108,12 @@
</repositories>
<dependencies>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>

View File

@ -1,5 +1,6 @@
package de.jeff_media.ChestSort;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -17,21 +18,37 @@ public class ChestSortInvSortCommand implements CommandExecutor {
@Override
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("invsort")) {
return false;
}
Player p = null;
if(args.length>0 && args[0].equalsIgnoreCase("help")) {
return false;
}
if (!(sender instanceof Player)) {
sender.sendMessage(plugin.messages.MSG_PLAYERSONLY);
return true;
if(args.length==0) {
sender.sendMessage(plugin.messages.MSG_PLAYERSONLY);
return true;
}
// Console can sort player's inventories
if(Bukkit.getPlayer(args[0]) == null) {
sender.sendMessage("Could not find player "+args[0]);
return true;
}
p = Bukkit.getPlayer(args[0]);
if(args.length>1) {
args = new String[] { args[1] };
} else {
args = new String[0];
}
//sender.sendMessage(plugin.messages.MSG_PLAYERSONLY);
//return true;
}
Player p = (Player) sender;
if(p == null) p = (Player) sender;
int start = 9;
int end = 35;

View File

@ -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;

View File

@ -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<String> 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"))));
}

View File

@ -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.
* <br>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.
* <br>This is what tells PlaceholderAPI to call our onRequest
* method to obtain a value if a placeholder starts with our
* identifier.
* <br>This must be unique and can not contain % or _
*
* @return The identifier in {@code %<identifier>_<value>%} as String.
*/
@Override
public String getIdentifier(){
return "chestsort";
}
/**
* This is the version of the expansion.
* <br>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.
* <br>We specify the value identifier in this method.
* <br>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;
}
}

View File

@ -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
config-version: 42

View File

@ -21,7 +21,7 @@ commands:
/<command> 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: |
/<command> -- Sort your inventory
@ -31,7 +31,7 @@ commands:
/<command> hotbar -- Sort your hotbar
/<command> all -- Sort your inventory and hotbar
/<command> help -- Shows help about this command
aliases: [isort,inventorysort]
aliases: [invsort,inventorysort]
permission: chestsort.use.inventory
permissions:
chestsort.use: