This commit is contained in:
mfnalex 2020-06-24 20:32:16 +02:00
parent 202fdebd3f
commit 6b0d3d46f1
24 changed files with 116 additions and 150 deletions

View File

@ -1,4 +1,8 @@
# Changelog # Changelog
## 8.11.1
- Improved help messages
- Huge code cleanup
## 8.11.0 ## 8.11.0
- Adjustet Left-Click / Right-Click hotkeys: - Adjustet Left-Click / Right-Click hotkeys:
- Left-Click outside of inventories will put matching items from your inventory into the chest - Left-Click outside of inventories will put matching items from your inventory into the chest
@ -8,6 +12,7 @@
- Using new universal Update checker (https://github.com/JEFF-Media-GbR/Spigot-UpdateChecker) - Using new universal Update checker (https://github.com/JEFF-Media-GbR/Spigot-UpdateChecker)
Note: The last two messages in the config.yml have changed, so please retranslate them. I am also always happy to integrate your translations into the default config.yml if you send them to me. Note: The last two messages in the config.yml have changed, so please retranslate them. I am also always happy to integrate your translations into the default config.yml if you send them to me.
## 8.10.5 ## 8.10.5
- Added reload command (/chestsort reload) with permission chestsort.reload - Added reload command (/chestsort reload) with permission chestsort.reload
- ChestSort checks if Minepacks version is recent enough and, if not, disable the Minepacks hook. - ChestSort checks if Minepacks version is recent enough and, if not, disable the Minepacks hook.

View File

@ -9,7 +9,7 @@
<name>JeffChestSort</name> <name>JeffChestSort</name>
<url>https://www.chestsort.de</url> <url>https://www.chestsort.de</url>
<description>Automatically sorts your chests!</description> <description>Automatically sorts your chests!</description>
<version>8.11.0</version> <version>8.11.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
@ -132,7 +132,7 @@
<dependency> <dependency>
<groupId>de.jeff_media</groupId> <groupId>de.jeff_media</groupId>
<artifactId>PluginUpdateChecker</artifactId> <artifactId>PluginUpdateChecker</artifactId>
<version>1.2</version> <version>[1.2,</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -5,7 +5,7 @@ import org.bukkit.inventory.Inventory;
public class ChestSortAPI { public class ChestSortAPI {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
ChestSortAPI(ChestSortPlugin plugin) { ChestSortAPI(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;

View File

@ -12,9 +12,9 @@ public class ChestSortCategory implements Comparable<ChestSortCategory>{
// "COARSE_DIRT" will not match the typeMatch "dirt" // "COARSE_DIRT" will not match the typeMatch "dirt"
// "COARSE_DIRT" will match the typeMatch "*dirt" // "COARSE_DIRT" will match the typeMatch "*dirt"
String name; final String name;
boolean sticky = false; boolean sticky = false;
TypeMatchPositionPair[] typeMatches; final TypeMatchPositionPair[] typeMatches;
ChestSortCategory(String name, TypeMatchPositionPair[] typeMatchPositionPairs) { ChestSortCategory(String name, TypeMatchPositionPair[] typeMatchPositionPairs) {
this.name = name; this.name = name;
@ -48,15 +48,15 @@ public class ChestSortCategory implements Comparable<ChestSortCategory>{
typeMatch = typeMatch.substring(0, typeMatch.length() - 1); typeMatch = typeMatch.substring(0, typeMatch.length() - 1);
} }
if (asteriskBefore == false && asteriskAfter == false) { if (!asteriskBefore && !asteriskAfter) {
if (itemname.equalsIgnoreCase(typeMatch)) { if (itemname.equalsIgnoreCase(typeMatch)) {
return typeMatchPositionPair.getPosition(); return typeMatchPositionPair.getPosition();
} }
} else if (asteriskBefore == true && asteriskAfter == true) { } else if (asteriskBefore && asteriskAfter) {
if (itemname.contains(typeMatch)) { if (itemname.contains(typeMatch)) {
return typeMatchPositionPair.getPosition(); return typeMatchPositionPair.getPosition();
} }
} else if (asteriskBefore == true && asteriskAfter == false) { } else if (asteriskBefore && !asteriskAfter) {
if (itemname.endsWith(typeMatch)) { if (itemname.endsWith(typeMatch)) {
return typeMatchPositionPair.getPosition(); return typeMatchPositionPair.getPosition();
} }

View File

@ -9,7 +9,7 @@ import net.md_5.bungee.api.ChatColor;
public class ChestSortChestSortCommand implements CommandExecutor { public class ChestSortChestSortCommand implements CommandExecutor {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
ChestSortChestSortCommand(ChestSortPlugin plugin) { ChestSortChestSortCommand(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -58,7 +58,7 @@ public class ChestSortChestSortCommand implements CommandExecutor {
if(args.length>0) { if(args.length>0) {
if(args[0].equalsIgnoreCase("hotkey") || args[0].equalsIgnoreCase("hotkeys")) { if(args[0].equalsIgnoreCase("hotkey") || args[0].equalsIgnoreCase("hotkeys")) {
if(plugin.hotkeyGUI==false) { if(!plugin.hotkeyGUI) {
p.sendMessage(plugin.messages.MSG_ERR_HOTKEYSDISABLED); p.sendMessage(plugin.messages.MSG_ERR_HOTKEYSDISABLED);
return true; return true;
} }

View File

@ -16,7 +16,7 @@ import de.jeff_media.ChestSort.utils.Utils;
public class ChestSortConfigUpdater { public class ChestSortConfigUpdater {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
public ChestSortConfigUpdater(ChestSortPlugin jeffChestSortPlugin) { public ChestSortConfigUpdater(ChestSortPlugin jeffChestSortPlugin) {
this.plugin = jeffChestSortPlugin; this.plugin = jeffChestSortPlugin;
@ -55,7 +55,7 @@ public class ChestSortConfigUpdater {
Map<String, Object> oldValues = oldConfig.getValues(false); Map<String, Object> oldValues = oldConfig.getValues(false);
// Read default config to keep comments // Read default config to keep comments
ArrayList<String> linesInDefaultConfig = new ArrayList<String>(); ArrayList<String> linesInDefaultConfig = new ArrayList<>();
try { try {
Scanner scanner = new Scanner( Scanner scanner = new Scanner(
@ -68,7 +68,7 @@ public class ChestSortConfigUpdater {
e.printStackTrace(); e.printStackTrace();
} }
ArrayList<String> newLines = new ArrayList<String>(); ArrayList<String> newLines = new ArrayList<>();
for (String line : linesInDefaultConfig) { for (String line : linesInDefaultConfig) {
String newline = line; String newline = line;
if (line.startsWith("config-version:")) { if (line.startsWith("config-version:")) {
@ -121,8 +121,8 @@ public class ChestSortConfigUpdater {
String[] linesArray = newLines.toArray(new String[linesInDefaultConfig.size()]); String[] linesArray = newLines.toArray(new String[linesInDefaultConfig.size()]);
try { try {
fw = new FileWriter(plugin.getDataFolder().getAbsolutePath() + File.separator + "config.yml"); fw = new FileWriter(plugin.getDataFolder().getAbsolutePath() + File.separator + "config.yml");
for (int i = 0; i < linesArray.length; i++) { for (String s : linesArray) {
fw.write(linesArray[i] + "\n"); fw.write(s + "\n");
} }
fw.close(); fw.close();
} catch (IOException e) { } catch (IOException e) {

View File

@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull;
public class ChestSortDebugger implements @NotNull Listener { public class ChestSortDebugger implements @NotNull Listener {
private ChestSortPlugin plugin; private final ChestSortPlugin plugin;
ChestSortDebugger(ChestSortPlugin plugin) { ChestSortDebugger(ChestSortPlugin plugin) {
plugin.getLogger().warning("======================================="); plugin.getLogger().warning("=======================================");

View File

@ -12,7 +12,7 @@ public class ChestSortEvent extends Event implements Cancellable {
boolean cancelled = false; boolean cancelled = false;
Location loc; Location loc;
Inventory inv; final Inventory inv;
Player p; Player p;
private static final HandlerList HANDLERS = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();

View File

@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
public class ChestSortInvSortCommand implements CommandExecutor { public class ChestSortInvSortCommand implements CommandExecutor {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
ChestSortInvSortCommand(ChestSortPlugin plugin) { ChestSortInvSortCommand(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;

View File

@ -24,8 +24,8 @@ import org.bukkit.inventory.InventoryHolder;
public class ChestSortListener implements Listener { public class ChestSortListener implements Listener {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
MinepacksHook minepacksHook; final MinepacksHook minepacksHook;
ChestSortListener(ChestSortPlugin plugin) { ChestSortListener(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -207,13 +207,10 @@ public class ChestSortListener implements Listener {
// WARNING: The names are inconsistent! A chest will return // WARNING: The names are inconsistent! A chest will return
// org.bukkit.craftbukkit.v1_14_R1.block.CraftChest // org.bukkit.craftbukkit.v1_14_R1.block.CraftChest
// in Spigot 1.14 while a double chest returns org.bukkit.block.DoubleChest // in Spigot 1.14 while a double chest returns org.bukkit.block.DoubleChest
if (!(inventory.getHolder() instanceof Chest) && !(inventory.getHolder() instanceof DoubleChest) return inventory.getHolder() instanceof Chest || inventory.getHolder() instanceof DoubleChest
&& !(inventory.getHolder().getClass().toString().endsWith(".CraftMinecartChest")) || inventory.getHolder().getClass().toString().endsWith(".CraftMinecartChest")
&& !(inventory.getHolder().getClass().toString().endsWith(".CraftShulkerBox")) //Obsolete, is checked above by InventoryType || inventory.getHolder().getClass().toString().endsWith(".CraftShulkerBox") //Obsolete, is checked above by InventoryType
&& !(inventory.getHolder().getClass().toString().endsWith(".CraftBarrel"))) { || inventory.getHolder().getClass().toString().endsWith(".CraftBarrel");
return false;
}
return true;
} }
private boolean isReadyToSort(Player p) { private boolean isReadyToSort(Player p) {
@ -408,7 +405,6 @@ public class ChestSortListener implements Listener {
plugin.organizer.sortInventory(event.getClickedInventory()); plugin.organizer.sortInventory(event.getClickedInventory());
plugin.organizer.updateInventoryView(event); plugin.organizer.updateInventoryView(event);
return;
} else if (holder instanceof Player) { } else if (holder instanceof Player) {
if (!p.hasPermission("chestsort.use.inventory")) { if (!p.hasPermission("chestsort.use.inventory")) {
return; return;
@ -423,7 +419,6 @@ public class ChestSortListener implements Listener {
plugin.organizer.updateInventoryView(event); plugin.organizer.updateInventoryView(event);
return; return;
} }
return;
} }
} }

View File

@ -11,7 +11,7 @@ public class ChestSortMessages {
// When creating pull requests that feature a message to the player, please // When creating pull requests that feature a message to the player, please
// stick to this scheme // stick to this scheme
ChestSortPlugin plugin; final ChestSortPlugin plugin;
final String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_INVACTIVATED, MSG_INVDEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY, final String MSG_ACTIVATED, MSG_DEACTIVATED, MSG_INVACTIVATED, MSG_INVDEACTIVATED, MSG_COMMANDMESSAGE, MSG_COMMANDMESSAGE2, MSG_PLAYERSONLY,
MSG_PLAYERINVSORTED, MSG_INVALIDOPTIONS; MSG_PLAYERINVSORTED, MSG_INVALIDOPTIONS;

View File

@ -44,9 +44,9 @@ public class ChestSortOrganizer {
* they are already alphabetically in the right order * they are already alphabetically in the right order
*/ */
ChestSortPlugin plugin; final ChestSortPlugin plugin;
CrackShotHook crackShotHook; final CrackShotHook crackShotHook;
InventoryPagesHook inventoryPagesHook; final InventoryPagesHook inventoryPagesHook;
private static final int maxInventorySize=54; private static final int maxInventorySize=54;
private static final int playerInvStartSlot=9; // Inclusive private static final int playerInvStartSlot=9; // Inclusive
@ -64,8 +64,8 @@ public class ChestSortOrganizer {
private static final String emptyPlaceholderString = "~"; private static final String emptyPlaceholderString = "~";
// We store a list of all Category objects // We store a list of all Category objects
ArrayList<ChestSortCategory> categories = new ArrayList<ChestSortCategory>(); final ArrayList<ChestSortCategory> categories = new ArrayList<>();
ArrayList<String> stickyCategoryNames = new ArrayList<String>(); final ArrayList<String> stickyCategoryNames = new ArrayList<>();
ChestSortOrganizer(ChestSortPlugin plugin) { ChestSortOrganizer(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -73,18 +73,13 @@ public class ChestSortOrganizer {
// Load Categories // Load Categories
File categoriesFolder = new File( File categoriesFolder = new File(
plugin.getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator); plugin.getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator);
File[] listOfCategoryFiles = categoriesFolder.listFiles(new FilenameFilter() { File[] listOfCategoryFiles = categoriesFolder.listFiles((directory, fileName) -> {
public boolean accept(File directory, String fileName) {
if (!fileName.endsWith(".txt")) { if (!fileName.endsWith(".txt")) {
return false; return false;
} }
if (fileName.matches("(?i)^\\d\\d\\d.*\\.txt$")) // Category between 900 and 999-... are default // Category between 900 and 999-... are default
// categories // categories
{ return fileName.matches("(?i)^\\d\\d\\d.*\\.txt$");
return true;
}
return false;
}
}); });
for (File file : listOfCategoryFiles) { for (File file : listOfCategoryFiles) {
if (file.isFile()) { if (file.isFile()) {
@ -129,7 +124,7 @@ public class ChestSortOrganizer {
// you can set it per category // you can set it per category
boolean appendLineNumber = false; boolean appendLineNumber = false;
Scanner sc = new Scanner(file); Scanner sc = new Scanner(file);
List<TypeMatchPositionPair> lines = new ArrayList<TypeMatchPositionPair>(); List<TypeMatchPositionPair> lines = new ArrayList<>();
short currentLineNumber = 1; short currentLineNumber = 1;
while (sc.hasNextLine()) { while (sc.hasNextLine()) {
String currentLine = sc.nextLine(); String currentLine = sc.nextLine();
@ -323,7 +318,7 @@ public class ChestSortOrganizer {
} }
} }
} }
} catch (NoSuchMethodException | SecurityException e) { } } catch (NoSuchMethodException | SecurityException ignored) { }
// potionEffects = potionEffects.substring(0, potionEffects.length()-1); // potionEffects = potionEffects.substring(0, potionEffects.length()-1);
} }
@ -410,7 +405,7 @@ public class ChestSortOrganizer {
System.out.println(" "); System.out.println(" ");
} }
ArrayList<Integer> unsortableSlots = new ArrayList<Integer>(); ArrayList<Integer> unsortableSlots = new ArrayList<>();
// We copy the complete inventory into an array // We copy the complete inventory into an array
ItemStack[] items = inv.getContents(); ItemStack[] items = inv.getContents();
@ -469,7 +464,7 @@ public class ChestSortOrganizer {
// We don't want to have stacks of null, so we create a new ArrayList and put in // We don't want to have stacks of null, so we create a new ArrayList and put in
// everything != null // everything != null
ArrayList<ItemStack> nonNullItemsList = new ArrayList<ItemStack>(); ArrayList<ItemStack> nonNullItemsList = new ArrayList<>();
for (ItemStack item : items) { for (ItemStack item : items) {
if (item != null) { if (item != null) {
nonNullItemsList.add(item); nonNullItemsList.add(item);
@ -484,15 +479,10 @@ public class ChestSortOrganizer {
// Because I did not bother to count the number of non-null items beforehand. // Because I did not bother to count the number of non-null items beforehand.
// TODO: Feel free to make a Pull request if you want to save your server a few // TODO: Feel free to make a Pull request if you want to save your server a few
// nanoseconds :) // nanoseconds :)
ItemStack[] nonNullItems = nonNullItemsList.toArray(new ItemStack[nonNullItemsList.size()]); ItemStack[] nonNullItems = nonNullItemsList.toArray(new ItemStack[0]);
// Sort the array with ItemStacks according to each ItemStacks' sortable String // Sort the array with ItemStacks according to each ItemStacks' sortable String
Arrays.sort(nonNullItems, new Comparator<ItemStack>() { Arrays.sort(nonNullItems, (s1, s2) -> (getSortableString(s1).compareTo(getSortableString(s2))));
@Override
public int compare(ItemStack s1, ItemStack s2) {
return (getSortableString(s1).compareTo(getSortableString(s2)));
}
});
// Now, we put everything back in a temporary inventory to combine ItemStacks // Now, we put everything back in a temporary inventory to combine ItemStacks
// even when using strict slot sorting // even when using strict slot sorting
@ -579,8 +569,7 @@ public class ChestSortOrganizer {
} }
public boolean isOversizedStack(ItemStack item) { public boolean isOversizedStack(ItemStack item) {
if(item!=null && item.getAmount()>64) return true; return item != null && item.getAmount() > 64;
return false;
} }
public void stuffInventoryIntoAnother(Inventory source, Inventory destination,Inventory origSource, boolean onlyMatchingStuff) { public void stuffInventoryIntoAnother(Inventory source, Inventory destination,Inventory origSource, boolean onlyMatchingStuff) {
@ -601,7 +590,7 @@ public class ChestSortOrganizer {
} }
ArrayList<ItemStack> leftovers = new ArrayList<ItemStack>(); ArrayList<ItemStack> leftovers = new ArrayList<>();
for(int i = 0;i<source.getSize();i++) { for(int i = 0;i<source.getSize();i++) {
@ -615,12 +604,10 @@ public class ChestSortOrganizer {
HashMap<Integer,ItemStack> currentLeftovers = destination.addItem(current); HashMap<Integer,ItemStack> currentLeftovers = destination.addItem(current);
for(ItemStack currentLeftover : currentLeftovers.values()) { leftovers.addAll(currentLeftovers.values());
leftovers.add(currentLeftover);
}
} }
origSource.addItem(leftovers.toArray(new ItemStack[leftovers.size()])); origSource.addItem(leftovers.toArray(new ItemStack[0]));
// Restore hotbar // Restore hotbar
if(destinationIsPlayerInventory) { if(destinationIsPlayerInventory) {

View File

@ -8,12 +8,12 @@ import org.bukkit.permissions.PermissionAttachment;
public class ChestSortPermissionsHandler { public class ChestSortPermissionsHandler {
HashMap<UUID,PermissionAttachment> permissions; final HashMap<UUID,PermissionAttachment> permissions;
ChestSortPlugin plugin; final ChestSortPlugin plugin;
ChestSortPermissionsHandler(ChestSortPlugin plugin) { ChestSortPermissionsHandler(ChestSortPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.permissions = new HashMap<UUID,PermissionAttachment>(); this.permissions = new HashMap<>();
} }
void addPermissions(Player p) { void addPermissions(Player p) {

View File

@ -30,7 +30,7 @@ public class ChestSortPlayerSetting {
DoubleClickType currentDoubleClick = DoubleClickType.NONE; DoubleClickType currentDoubleClick = DoubleClickType.NONE;
enum DoubleClickType { enum DoubleClickType {
NONE, RIGHT_CLICK, LEFT_CLICK; NONE, RIGHT_CLICK, LEFT_CLICK
} }
ChestSortPlayerSetting(boolean sortingEnabled, boolean invSortingEnabled, boolean middleClick, boolean shiftClick, boolean doubleClick, boolean shiftRightClick, boolean leftClick, boolean rightClick, boolean changed) { ChestSortPlayerSetting(boolean sortingEnabled, boolean invSortingEnabled, boolean middleClick, boolean shiftClick, boolean doubleClick, boolean shiftRightClick, boolean leftClick, boolean rightClick, boolean changed) {
@ -53,12 +53,7 @@ public class ChestSortPlayerSetting {
} }
if(currentDoubleClick != click) { if(currentDoubleClick != click) {
currentDoubleClick = click; currentDoubleClick = click;
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { Bukkit.getScheduler().runTaskLater(plugin, () -> currentDoubleClick = DoubleClickType.NONE, 10);
@Override
public void run() {
currentDoubleClick = DoubleClickType.NONE;
}
}, 10);
return DoubleClickType.NONE; return DoubleClickType.NONE;
} }
return DoubleClickType.NONE; return DoubleClickType.NONE;

View File

@ -58,7 +58,7 @@ import de.jeff_media.ChestSort.utils.Utils;
public class ChestSortPlugin extends JavaPlugin { public class ChestSortPlugin extends JavaPlugin {
Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<String, ChestSortPlayerSetting>(); Map<String, ChestSortPlayerSetting> perPlayerSettings = new HashMap<>();
ChestSortMessages messages; ChestSortMessages messages;
ChestSortOrganizer organizer; ChestSortOrganizer organizer;
PluginUpdateChecker updateChecker; PluginUpdateChecker updateChecker;
@ -68,11 +68,11 @@ public class ChestSortPlugin extends JavaPlugin {
String sortingMethod; String sortingMethod;
ArrayList<String> disabledWorlds; ArrayList<String> disabledWorlds;
ChestSortAPI api; ChestSortAPI api;
int currentConfigVersion = 33; final int currentConfigVersion = 33;
boolean usingMatchingConfig = true; boolean usingMatchingConfig = true;
protected boolean debug = false; protected boolean debug = false;
boolean verbose = true; boolean verbose = true;
boolean hotkeyGUI = true; final boolean hotkeyGUI = true;
public boolean hookCrackShot = false; public boolean hookCrackShot = false;
public boolean hookInventoryPages = false; public boolean hookInventoryPages = false;
@ -109,7 +109,7 @@ public class ChestSortPlugin extends JavaPlugin {
boolean isSortingEnabled(Player p) { boolean isSortingEnabled(Player p) {
if (perPlayerSettings == null) { if (perPlayerSettings == null) {
perPlayerSettings = new HashMap<String, ChestSortPlayerSetting>(); perPlayerSettings = new HashMap<>();
} }
listener.plugin.registerPlayerIfNeeded(p); listener.plugin.registerPlayerIfNeeded(p);
return perPlayerSettings.get(p.getUniqueId().toString()).sortingEnabled; return perPlayerSettings.get(p.getUniqueId().toString()).sortingEnabled;
@ -238,7 +238,7 @@ public class ChestSortPlugin extends JavaPlugin {
private String getCategoryList() { private String getCategoryList() {
String list = ""; String list = "";
ChestSortCategory[] categories = organizer.categories.toArray(new ChestSortCategory[organizer.categories.size()]); ChestSortCategory[] categories = organizer.categories.toArray(new ChestSortCategory[0]);
Arrays.sort(categories); Arrays.sort(categories);
for(ChestSortCategory category : categories) { for(ChestSortCategory category : categories) {
list = list + category.name + " ("; list = list + category.name + " (";
@ -296,7 +296,7 @@ public class ChestSortPlugin extends JavaPlugin {
private void saveDefaultCategories() { private void saveDefaultCategories() {
// Abort when auto-generate-category-files is set to false in config.yml // Abort when auto-generate-category-files is set to false in config.yml
if (getConfig().getBoolean("auto-generate-category-files", true) != true) { if (!getConfig().getBoolean("auto-generate-category-files", true)) {
return; return;
} }
@ -306,18 +306,13 @@ public class ChestSortPlugin extends JavaPlugin {
// Delete all files starting with 9.. // Delete all files starting with 9..
for (File file : new File(getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator) for (File file : new File(getDataFolder().getAbsolutePath() + File.separator + "categories" + File.separator)
.listFiles(new FilenameFilter() { .listFiles((directory, fileName) -> {
public boolean accept(File directory, String fileName) {
if (!fileName.endsWith(".txt")) { if (!fileName.endsWith(".txt")) {
return false; return false;
} }
if (fileName.matches("(?i)9\\d\\d.*\\.txt$")) // Category between 900 and 999-... are default // Category between 900 and 999-... are default
// categories // categories
{ return fileName.matches("(?i)9\\d\\d.*\\.txt$");
return true;
}
return false;
}
})) { })) {
boolean delete = true; boolean delete = true;
@ -433,13 +428,13 @@ public class ChestSortPlugin extends JavaPlugin {
} }
hookCrackShot = getConfig().getBoolean("hook-crackshot") hookCrackShot = getConfig().getBoolean("hook-crackshot")
&& Bukkit.getPluginManager().getPlugin("CrackShot") instanceof Plugin ? true : false; && Bukkit.getPluginManager().getPlugin("CrackShot") instanceof Plugin;
hookInventoryPages = getConfig().getBoolean("hook-inventorypages") hookInventoryPages = getConfig().getBoolean("hook-inventorypages")
&& Bukkit.getPluginManager().getPlugin("InventoryPages") instanceof Plugin ? true : false; && Bukkit.getPluginManager().getPlugin("InventoryPages") instanceof Plugin;
hookMinepacks = getConfig().getBoolean("hook-minepacks") hookMinepacks = getConfig().getBoolean("hook-minepacks")
&& Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin ? true : false; && Bukkit.getPluginManager().getPlugin("Minepacks") instanceof MinepacksPlugin;
saveDefaultCategories(); saveDefaultCategories();
@ -521,7 +516,7 @@ public class ChestSortPlugin extends JavaPlugin {
} }
} }
} else { } else {
perPlayerSettings = new HashMap<String,ChestSortPlayerSetting>(); perPlayerSettings = new HashMap<>();
} }
} }

View File

@ -15,20 +15,20 @@ import org.bukkit.inventory.meta.ItemMeta;
public class ChestSortSettingsGUI implements Listener { public class ChestSortSettingsGUI implements Listener {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
public static int slotMiddleClick = 1; public static final int slotMiddleClick = 1;
public static int slotShiftClick = 3 ; public static final int slotShiftClick = 3 ;
public static int slotDoubleClick = 5 ; public static final int slotDoubleClick = 5 ;
public static int slotShiftRightClick = 7 ; public static final int slotShiftRightClick = 7 ;
public static int slotLeftClick = 2+18; public static final int slotLeftClick = 2+18;
public static int slotRightClick = 6+18; public static final int slotRightClick = 6+18;
final static Material red = Material.REDSTONE_BLOCK; final static Material red = Material.REDSTONE_BLOCK;
final static Material green = Material.EMERALD_BLOCK; final static Material green = Material.EMERALD_BLOCK;
enum Hotkey { enum Hotkey {
MiddleClick, ShiftClick, DoubleClick, ShiftRightClick, LeftClick, RightClick; MiddleClick, ShiftClick, DoubleClick, ShiftRightClick, LeftClick, RightClick
} }
ChestSortSettingsGUI(ChestSortPlugin plugin) { ChestSortSettingsGUI(ChestSortPlugin plugin) {
@ -95,13 +95,12 @@ public class ChestSortSettingsGUI implements Listener {
} }
Inventory createGUI(String name, Player inventoryHolder) { Inventory createGUI(String name, Player inventoryHolder) {
Inventory inventory = Bukkit.createInventory(inventoryHolder, InventoryType.CHEST, name); return Bukkit.createInventory(inventoryHolder, InventoryType.CHEST, name);
return inventory;
} }
@EventHandler @EventHandler
void onGUIInteract(InventoryClickEvent event) { void onGUIInteract(InventoryClickEvent event) {
if(plugin.hotkeyGUI==false) { if(!plugin.hotkeyGUI) {
return; return;
} }
if(!(event.getWhoClicked() instanceof Player)) { if(!(event.getWhoClicked() instanceof Player)) {
@ -131,28 +130,22 @@ public class ChestSortSettingsGUI implements Listener {
if(event.getSlot() == ChestSortSettingsGUI.slotMiddleClick) { if(event.getSlot() == ChestSortSettingsGUI.slotMiddleClick) {
setting.toggleMiddleClick(); setting.toggleMiddleClick();
plugin.settingsGUI.openGUI(p); plugin.settingsGUI.openGUI(p);
return;
} }
else if(event.getSlot() == ChestSortSettingsGUI.slotShiftClick) { else if(event.getSlot() == ChestSortSettingsGUI.slotShiftClick) {
setting.toggleShiftClick(); setting.toggleShiftClick();
plugin.settingsGUI.openGUI(p); plugin.settingsGUI.openGUI(p);
return;
} else if(event.getSlot() == ChestSortSettingsGUI.slotDoubleClick) { } else if(event.getSlot() == ChestSortSettingsGUI.slotDoubleClick) {
setting.toggleDoubleClick(); setting.toggleDoubleClick();
plugin.settingsGUI.openGUI(p); plugin.settingsGUI.openGUI(p);
return;
} else if(event.getSlot() == ChestSortSettingsGUI.slotShiftRightClick) { } else if(event.getSlot() == ChestSortSettingsGUI.slotShiftRightClick) {
setting.toggleShiftRightClick(); setting.toggleShiftRightClick();
plugin.settingsGUI.openGUI(p); plugin.settingsGUI.openGUI(p);
return;
} else if(event.getSlot() == ChestSortSettingsGUI.slotLeftClick) { } else if(event.getSlot() == ChestSortSettingsGUI.slotLeftClick) {
setting.toggleLeftClick(); setting.toggleLeftClick();
plugin.settingsGUI.openGUI(p); plugin.settingsGUI.openGUI(p);
return;
} else if(event.getSlot() == ChestSortSettingsGUI.slotRightClick) { } else if(event.getSlot() == ChestSortSettingsGUI.slotRightClick) {
setting.toggleRightClick(); setting.toggleRightClick();
plugin.settingsGUI.openGUI(p); plugin.settingsGUI.openGUI(p);
return;
} }
} }

View File

@ -13,7 +13,7 @@ public class ChestSortTabCompleter implements TabCompleter {
static final String[] invsortOptions = { "toggle","on","off","all", "hotbar", "inv" }; static final String[] invsortOptions = { "toggle","on","off","all", "hotbar", "inv" };
private List<String> getMatchingOptions(String entered, String[] options) { private List<String> getMatchingOptions(String entered, String[] options) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for(String option : options) { for(String option : options) {
if(option.toLowerCase().startsWith(entered.toLowerCase())) { if(option.toLowerCase().startsWith(entered.toLowerCase())) {
@ -36,7 +36,7 @@ public class ChestSortTabCompleter implements TabCompleter {
if(command.getName().equalsIgnoreCase("invsort")) { if(command.getName().equalsIgnoreCase("invsort")) {
return getMatchingOptions(entered,invsortOptions); return getMatchingOptions(entered,invsortOptions);
} }
return new ArrayList<String>(); return new ArrayList<>();
} }
} }

View File

@ -8,7 +8,7 @@ import de.jeff_media.ChestSort.ChestSortPlugin;
public class CrackShotHook { public class CrackShotHook {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
CSUtility crackShotUtility = null; CSUtility crackShotUtility = null;
public CrackShotHook(ChestSortPlugin plugin) { public CrackShotHook(ChestSortPlugin plugin) {
@ -22,7 +22,7 @@ public class CrackShotHook {
// Will return when not a weapon // Will return when not a weapon
public String getCrackShotWeaponName(ItemStack item) { public String getCrackShotWeaponName(ItemStack item) {
if(crackShotUtility == null || plugin.hookCrackShot==false) { if(crackShotUtility == null || !plugin.hookCrackShot) {
return null; return null;
} }

View File

@ -13,7 +13,7 @@ import net.md_5.bungee.api.ChatColor;
public class InventoryPagesHook { public class InventoryPagesHook {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
YamlConfiguration inventoryPagesConfig; YamlConfiguration inventoryPagesConfig;
int prevSlot, nextSlot; int prevSlot, nextSlot;
@ -63,26 +63,20 @@ public class InventoryPagesHook {
//System.out.println("Checking if slot " + slot + " "+ item.toString() + " is button"); //System.out.println("Checking if slot " + slot + " "+ item.toString() + " is button");
// When using &f as color, we manually have to add this to the string because it gets removed by InventoryPages // When using &f as color, we manually have to add this to the string because it gets removed by InventoryPages
if(prevName.startsWith("§f")) prevName = prevName.substring(2,prevName.length()); if(prevName.startsWith("§f")) prevName = prevName.substring(2);
if(nextName.startsWith("§f")) nextName = nextName.substring(2,nextName.length()); if(nextName.startsWith("§f")) nextName = nextName.substring(2);
if(noPageName.startsWith("§f")) noPageName = noPageName.substring(2,noPageName.length()); if(noPageName.startsWith("§f")) noPageName = noPageName.substring(2);
if(slot == prevSlot ) { if(slot == prevSlot ) {
if(item.getType() == prevMat && (item.getItemMeta().getDisplayName().equals(prevName))) { if(item.getType() == prevMat && (item.getItemMeta().getDisplayName().equals(prevName))) {
return true; return true;
} else if(item.getType() == noPageMat && item.getItemMeta().getDisplayName().equals(noPageName)) { } else return item.getType() == noPageMat && item.getItemMeta().getDisplayName().equals(noPageName);
return true;
}
return false;
} }
if(slot == nextSlot ) { if(slot == nextSlot ) {
if(item.getType() == nextMat && item.getItemMeta().getDisplayName().equals(nextName)) { if(item.getType() == nextMat && item.getItemMeta().getDisplayName().equals(nextName)) {
return true; return true;
} else if(item.getType() == noPageMat && item.getItemMeta().getDisplayName().equals(noPageName)) { } else return item.getType() == noPageMat && item.getItemMeta().getDisplayName().equals(noPageName);
return true;
}
return false;
} }
return false; return false;

View File

@ -11,7 +11,7 @@ import de.jeff_media.ChestSort.ChestSortPlugin;
public class MinepacksHook { public class MinepacksHook {
ChestSortPlugin plugin; final ChestSortPlugin plugin;
MinepacksPlugin minepacks = null; MinepacksPlugin minepacks = null;
public MinepacksHook(ChestSortPlugin plugin) { public MinepacksHook(ChestSortPlugin plugin) {
@ -45,11 +45,7 @@ public class MinepacksHook {
if( inv.getHolder() == null) return false; if( inv.getHolder() == null) return false;
if(inv.getHolder() instanceof Backpack) { return inv.getHolder() instanceof Backpack;
return true;
}
return false;
} }

View File

@ -2,10 +2,10 @@ package de.jeff_media.ChestSort.utils;
public class CategoryLinePair { public class CategoryLinePair {
String categoryName; final String categoryName;
String formattedPosition; final String formattedPosition;
boolean sticky = false; boolean sticky = false;
short position; final short position;
public CategoryLinePair(String categoryName,short position) { public CategoryLinePair(String categoryName,short position) {
this(categoryName,position,false); this(categoryName,position,false);

View File

@ -21,10 +21,7 @@ public class LlamaUtils {
} }
public static boolean belongsToLlama(Inventory inv) { public static boolean belongsToLlama(Inventory inv) {
if(inv != null && inv.getHolder() != null && inv.getHolder().getClass().getName().endsWith("CraftLlama")) { return inv != null && inv.getHolder() != null && inv.getHolder().getClass().getName().endsWith("CraftLlama");
return true;
}
return false;
} }
} }

View File

@ -2,8 +2,8 @@ package de.jeff_media.ChestSort.utils;
public class TypeMatchPositionPair { public class TypeMatchPositionPair {
String typeMatch; final String typeMatch;
String formattedPosition; final String formattedPosition;
boolean sticky=false; boolean sticky=false;
public String getTypeMatch() { public String getTypeMatch() {
@ -23,7 +23,7 @@ public class TypeMatchPositionPair {
return formattedPosition; return formattedPosition;
} }
short position; final short position;
public TypeMatchPositionPair(String typeMatch,short position) { public TypeMatchPositionPair(String typeMatch,short position) {
this(typeMatch,position,false); this(typeMatch,position,false);

View File

@ -1,7 +1,7 @@
main: de.jeff_media.ChestSort.ChestSortPlugin main: de.jeff_media.ChestSort.ChestSortPlugin
name: ChestSort name: ChestSort
version: 8.11.0 version: 8.11.1
api-version: 1.13 api-version: "1.13"
description: Allows automatic chest sorting description: Allows automatic chest sorting
author: mfnalex author: mfnalex
website: https://www.chestsort.de website: https://www.chestsort.de
@ -12,12 +12,21 @@ softdepend: [CrackShot,InventoryPages,Minepacks]
commands: commands:
chestsort: chestsort:
description: Toggle automatic chest sorting. description: Toggle automatic chest sorting.
usage: /<command> [on|off|toggle] usage: |
/<command> -- Toggles automatic chest sorting
/<command> on|off -- Enables/disabled automatic chest sorting
/<command> hotkeys -- Opens hotkeys GUI to enable/disable hotkeys
/<command> reload -- Reloads config
aliases: sort aliases: sort
permission: chestsort.use permission: chestsort.use
invsort: 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. 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.
usage: /<command> [on|off|toggle|inv|hotbar|all] usage: |
/<command> toggle -- Toggles automatic inventory sorting
/<command> on|off -- Enables/disables automatic inventory sorting
/<command> inv -- Sorts your inventory
/<command> hotbar -- Sorts your hotbar
/<command> all -- Sorts your inventory and hotbar
aliases: [isort,inventorysort] aliases: [isort,inventorysort]
permission: chestsort.use.inventory permission: chestsort.use.inventory
permissions: permissions: