This commit is contained in:
mfnalex 2020-06-24 20:53:10 +02:00
parent 6b0d3d46f1
commit 61b88c8d94
12 changed files with 38 additions and 48 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.md_5.bungee.api.ChatColor;
import org.jetbrains.annotations.NotNull;
public class ChestSortChestSortCommand implements CommandExecutor {
@ -16,7 +17,7 @@ public class ChestSortChestSortCommand implements CommandExecutor {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
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")) {

View File

@ -6,6 +6,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ChestSortEvent extends Event implements Cancellable {
@ -35,7 +36,7 @@ public class ChestSortEvent extends Event implements Cancellable {
return p;
}
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}

View File

@ -4,6 +4,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class ChestSortInvSortCommand implements CommandExecutor {
@ -14,7 +15,7 @@ public class ChestSortInvSortCommand implements CommandExecutor {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
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")) {

View File

@ -79,8 +79,8 @@ public class ChestSortListener implements Listener {
@EventHandler
public void onPlayerInventoryClose(InventoryCloseEvent event) {
if (event.getInventory() == null) return;
if (event.getInventory().getHolder() == null) return;
// Might be obsolete, because its @NotNull in 1.15, but who knows if thats for 1.8
if (event.getInventory().getType() == null) return;
if (event.getInventory().getType() != InventoryType.CRAFTING)
return; // Weird! Returns CRAFTING instead of PLAYER
@ -413,11 +413,9 @@ public class ChestSortListener implements Listener {
if (event.getSlotType() == SlotType.QUICKBAR) {
plugin.organizer.sortInventory(p.getInventory(), 0, 8);
plugin.organizer.updateInventoryView(event);
return;
} else if (event.getSlotType() == SlotType.CONTAINER) {
plugin.organizer.sortInventory(p.getInventory(), 9, 35);
plugin.organizer.updateInventoryView(event);
return;
}
}
}

View File

@ -2,14 +2,7 @@ package de.jeff_media.ChestSort;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.*;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -152,11 +145,11 @@ public class ChestSortOrganizer {
plugin.getLogger().info("Sticky set to true in " + file.getName());
}
} else {
if (currentLine != null) {
//if (currentLine != null) {
lines.add(new TypeMatchPositionPair(currentLine, currentLineNumber, appendLineNumber));
if (plugin.debug)
plugin.getLogger().info("Added typeMatch to category file: " + currentLine);
}
//}
}
}
currentLineNumber++;
@ -471,9 +464,6 @@ public class ChestSortOrganizer {
}
}
// We no longer need the original array that includes all the null-stacks
items = null;
// We need the new list as array. So why did'nt we take an array from the
// beginning?
// Because I did not bother to count the number of non-null items beforehand.
@ -482,7 +472,7 @@ public class ChestSortOrganizer {
ItemStack[] nonNullItems = nonNullItemsList.toArray(new ItemStack[0]);
// Sort the array with ItemStacks according to each ItemStacks' sortable String
Arrays.sort(nonNullItems, (s1, s2) -> (getSortableString(s1).compareTo(getSortableString(s2))));
Arrays.sort(nonNullItems, Comparator.comparing(this::getSortableString));
// Now, we put everything back in a temporary inventory to combine ItemStacks
// even when using strict slot sorting
@ -515,14 +505,14 @@ public class ChestSortOrganizer {
// our temporary inventory was already sorted. Feel free to make a pull request
// to
// save your server half a nanosecond :)
if (item != null)
{
//if (item != null)
//{
while(unsortableSlots.contains(currentSlot) && currentSlot < endSlot) {
currentSlot++;
}
inv.setItem(currentSlot, item);
}
//}
currentSlot++;
}
@ -632,24 +622,25 @@ public class ChestSortOrganizer {
boolean destinationIsShulkerBox = destination.getType().name().equalsIgnoreCase("SHULKER_BOX");
Inventory temp = Bukkit.createInventory(null, maxInventorySize);
for(int i = playerInvStartSlot;i<=playerInvEndSlot;i++) {
if(source.getItem(i)==null) continue;
ItemStack currentItem = source.getItem(i);
if(currentItem==null) continue;
// This prevents Minepacks from being put into Minepacks
/*if(plugin.hookMinepacks && plugin.listener.minepacksHook.isMinepacksBackpack(destination)
&& plugin.listener.minepacksHook.isMinepacksBackpack(source.getItem(i))) continue;*/
&& plugin.listener.minepacksHook.isMinepacksBackpack(currentItem)) continue;*/
// This prevents Minepacks from being moved at all
if(plugin.hookMinepacks && plugin.listener.minepacksHook.isMinepacksBackpack(source.getItem(i))) continue;
if(plugin.hookMinepacks && plugin.listener.minepacksHook.isMinepacksBackpack(currentItem)) continue;
if(plugin.hookInventoryPages
&& plugin.organizer.inventoryPagesHook.isButton(source.getItem(i), i, source)) continue;
&& plugin.organizer.inventoryPagesHook.isButton(currentItem, i, source)) continue;
if(destinationIsShulkerBox && source.getItem(i).getType().name().endsWith("SHULKER_BOX")) continue;
if(destinationIsShulkerBox && currentItem.getType().name().endsWith("SHULKER_BOX")) continue;
if(isOversizedStack(source.getItem(i))) continue;
if(isOversizedStack(currentItem)) continue;
if(onlyMatchingStuff && !doesInventoryContain(destination,source.getItem(i).getType())) continue;
if(onlyMatchingStuff && !doesInventoryContain(destination,currentItem.getType())) continue;
temp.addItem(source.getItem(i));
temp.addItem(currentItem);
source.clear(i);
}
stuffInventoryIntoAnother(temp,destination,source,false);

View File

@ -25,7 +25,7 @@ public class ChestSortPlayerSetting {
boolean hasSeenMessage = false;
// Do we have to save these settings?
boolean changed = false;
boolean changed;
DoubleClickType currentDoubleClick = DoubleClickType.NONE;

View File

@ -31,7 +31,6 @@ package de.jeff_media.ChestSort;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
@ -147,7 +146,6 @@ public class ChestSortPlugin extends JavaPlugin {
showOldConfigWarning();
ChestSortConfigUpdater configUpdater = new ChestSortConfigUpdater(this);
configUpdater.updateConfig();
configUpdater = null;
usingMatchingConfig = true;
//createConfig();
}
@ -237,15 +235,15 @@ public class ChestSortPlugin extends JavaPlugin {
}
private String getCategoryList() {
String list = "";
StringBuilder list = new StringBuilder();
ChestSortCategory[] categories = organizer.categories.toArray(new ChestSortCategory[0]);
Arrays.sort(categories);
for(ChestSortCategory category : categories) {
list = list + category.name + " (";
list = list + category.typeMatches.length + "), ";
list.append(category.name).append(" (");
list.append(category.typeMatches.length).append("), ");
}
list = list.substring(0, list.length()-2);
return list;
list = new StringBuilder(list.substring(0, list.length() - 2));
return list.toString();
}
@ -560,8 +558,8 @@ public class ChestSortPlugin extends JavaPlugin {
playerConfig.addDefault("leftClick", getConfig().getBoolean("additional-hotkeys.left-click"));
playerConfig.addDefault("rightClick", getConfig().getBoolean("additional-hotkeys.right-click"));
boolean activeForThisPlayer = false;
boolean invActiveForThisPlayer = false;
boolean activeForThisPlayer;
boolean invActiveForThisPlayer;
boolean middleClick, shiftClick, doubleClick, shiftRightClick, leftClick, rightClick;
boolean changed = false;

View File

@ -36,7 +36,7 @@ public class ChestSortSettingsGUI implements Listener {
}
ItemStack getItem(boolean active, Hotkey hotkey) {
ItemStack is = null;
ItemStack is;
String suffix;
if(active) {

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
public class ChestSortTabCompleter implements TabCompleter {
@ -24,7 +25,7 @@ public class ChestSortTabCompleter implements TabCompleter {
return list;
}
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
String entered = "";
if(args.length>0) {

View File

@ -27,9 +27,8 @@ public class MinepacksHook {
if(minepacks == null) return false;
try {
if(minepacks.getClass().getMethod("isBackpackItem", ItemStack.class) != null) {
if(minepacks.isBackpackItem(item)) return true;
}
minepacks.getClass().getMethod("isBackpackItem", ItemStack.class);
if(minepacks.isBackpackItem(item)) return true;
} catch (NoSuchMethodException | SecurityException e) {
plugin.getLogger().warning("You are using a version of Minepacks that is too old and does not implement every API method needed by ChestSort. Minepacks hook will be disabled.");
minepacks = null;

View File

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

View File

@ -4,7 +4,7 @@ public class TypeMatchPositionPair {
final String typeMatch;
final String formattedPosition;
boolean sticky=false;
boolean sticky;
public String getTypeMatch() {
return typeMatch;