4242import  org .bukkit .entity .EntityType ;
4343import  org .bukkit .entity .Player ;
4444import  org .bukkit .entity .TropicalFish ;
45- import  org .bukkit .inventory .EquipmentSlot ;
46- import  org .bukkit .inventory .Inventory ;
47- import  org .bukkit .inventory .ItemFlag ;
48- import  org .bukkit .inventory .ItemStack ;
45+ import  org .bukkit .inventory .*;
4946import  org .bukkit .inventory .meta .*;
5047import  org .bukkit .inventory .meta .trim .ArmorTrim ;
5148import  org .bukkit .inventory .meta .trim .TrimMaterial ;
5552import  org .bukkit .material .SpawnEgg ;
5653import  org .bukkit .potion .PotionEffect ;
5754import  org .bukkit .potion .PotionType ;
55+ import  org .jetbrains .annotations .Contract ;
5856import  org .jetbrains .annotations .NotNull ;
5957import  org .jetbrains .annotations .Nullable ;
58+ import  org .jetbrains .annotations .Range ;
6059
6160import  java .util .*;
6261import  java .util .function .BiPredicate ;
7776 * <a href="https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html">ItemStack</a> 
7877 * 
7978 * @author Crypto Morin 
80-  * @version 7.5.1  
79+  * @version 7.5.2  
8180 * @see XMaterial 
8281 * @see XPotion 
8382 * @see XSkull 
@@ -1236,6 +1235,7 @@ public static Color parseColor(@Nullable String str) {
12361235     * @since 2.0.1 
12371236     */ 
12381237    @ NotNull 
1238+     @ Contract (mutates  = "param1" )
12391239    public  static  List <ItemStack > giveOrDrop (@ NotNull  Player  player , @ Nullable  ItemStack ... items ) {
12401240        return  giveOrDrop (player , false , items );
12411241    }
@@ -1250,6 +1250,7 @@ public static List<ItemStack> giveOrDrop(@NotNull Player player, @Nullable ItemS
12501250     * @since 2.0.1 
12511251     */ 
12521252    @ NotNull 
1253+     @ Contract (mutates  = "param1" )
12531254    public  static  List <ItemStack > giveOrDrop (@ NotNull  Player  player , boolean  split , @ Nullable  ItemStack ... items ) {
12541255        if  (items  == null  || items .length  == 0 ) return  new  ArrayList <>();
12551256        List <ItemStack > leftOvers  = addItems (player .getInventory (), split , items );
@@ -1260,6 +1261,7 @@ public static List<ItemStack> giveOrDrop(@NotNull Player player, boolean split,
12601261        return  leftOvers ;
12611262    }
12621263
1264+     @ Contract (mutates  = "param1" )
12631265    public  static  List <ItemStack > addItems (@ NotNull  Inventory  inventory , boolean  split , @ NotNull  ItemStack ... items ) {
12641266        return  addItems (inventory , split , null , items );
12651267    }
@@ -1277,7 +1279,9 @@ public static List<ItemStack> addItems(@NotNull Inventory inventory, boolean spl
12771279     * @return items that didn't fit in the inventory. 
12781280     * @since 4.0.0 
12791281     */ 
1282+ 
12801283    @ NotNull 
1284+     @ Contract (mutates  = "param1" )
12811285    public  static  List <ItemStack > addItems (@ NotNull  Inventory  inventory , boolean  split ,
12821286                                           @ Nullable  Predicate <Integer > modifiableSlots , @ NotNull  ItemStack ... items ) {
12831287        Objects .requireNonNull (inventory , "Cannot add items to null inventory" );
@@ -1344,6 +1348,9 @@ public static List<ItemStack> addItems(@NotNull Inventory inventory, boolean spl
13441348        return  leftOvers ;
13451349    }
13461350
1351+     @ NotNull 
1352+     @ Contract (pure  = true )
1353+     @ Range (from  = -1 , to  = Integer .MAX_VALUE )
13471354    public  static  int  firstPartial (@ NotNull  Inventory  inventory , @ Nullable  ItemStack  item , int  beginIndex ) {
13481355        return  firstPartial (inventory , item , beginIndex , null );
13491356    }
@@ -1361,6 +1368,9 @@ public static int firstPartial(@NotNull Inventory inventory, @Nullable ItemStack
13611368     * @throws IndexOutOfBoundsException if the beginning index is less than 0 or greater than the inventory storage size. 
13621369     * @since 4.0.0 
13631370     */ 
1371+     @ NotNull 
1372+     @ Contract (pure  = true )
1373+     @ Range (from  = -1 , to  = Integer .MAX_VALUE )
13641374    public  static  int  firstPartial (@ NotNull  Inventory  inventory , @ Nullable  ItemStack  item , int  beginIndex , @ Nullable  Predicate <Integer > modifiableSlots ) {
13651375        if  (item  != null ) {
13661376            ItemStack [] items  = getStorageContents (inventory );
@@ -1378,6 +1388,8 @@ public static int firstPartial(@NotNull Inventory inventory, @Nullable ItemStack
13781388        return  -1 ;
13791389    }
13801390
1391+     @ NotNull 
1392+     @ Contract (pure  = true )
13811393    public  static  List <ItemStack > stack (@ NotNull  Collection <ItemStack > items ) {
13821394        return  stack (items , ItemStack ::isSimilar );
13831395    }
@@ -1396,6 +1408,7 @@ public static List<ItemStack> stack(@NotNull Collection<ItemStack> items) {
13961408     * @since 4.0.0 
13971409     */ 
13981410    @ NotNull 
1411+     @ Contract (pure  = true )
13991412    public  static  List <ItemStack > stack (@ NotNull  Collection <ItemStack > items , @ NotNull  BiPredicate <ItemStack , ItemStack > similarity ) {
14001413        Objects .requireNonNull (items , "Cannot stack null items" );
14011414        Objects .requireNonNull (similarity , "Similarity check cannot be null" );
@@ -1418,6 +1431,8 @@ public static List<ItemStack> stack(@NotNull Collection<ItemStack> items, @NotNu
14181431        return  stacked ;
14191432    }
14201433
1434+     @ Contract (pure  = true )
1435+     @ Range (from  = -1 , to  = Integer .MAX_VALUE )
14211436    public  static  int  firstEmpty (@ NotNull  Inventory  inventory , int  beginIndex ) {
14221437        return  firstEmpty (inventory , beginIndex , null );
14231438    }
@@ -1434,6 +1449,8 @@ public static int firstEmpty(@NotNull Inventory inventory, int beginIndex) {
14341449     * @throws IndexOutOfBoundsException if the beginning index is less than 0 or greater than the inventory storage size. 
14351450     * @since 4.0.0 
14361451     */ 
1452+     @ Contract (pure  = true )
1453+     @ Range (from  = -1 , to  = Integer .MAX_VALUE )
14371454    public  static  int  firstEmpty (@ NotNull  Inventory  inventory , int  beginIndex , @ Nullable  Predicate <Integer > modifiableSlots ) {
14381455        ItemStack [] items  = getStorageContents (inventory );
14391456        int  invSize  = items .length ;
@@ -1458,6 +1475,8 @@ public static int firstEmpty(@NotNull Inventory inventory, int beginIndex, @Null
14581475     * @see #firstPartial(Inventory, ItemStack, int) 
14591476     * @since 4.2.0 
14601477     */ 
1478+     @ Contract (pure  = true )
1479+     @ Range (from  = -1 , to  = Integer .MAX_VALUE )
14611480    public  static  int  firstPartialOrEmpty (@ NotNull  Inventory  inventory , @ Nullable  ItemStack  item , int  beginIndex ) {
14621481        if  (item  != null ) {
14631482            ItemStack [] items  = getStorageContents (inventory );
@@ -1474,6 +1493,10 @@ public static int firstPartialOrEmpty(@NotNull Inventory inventory, @Nullable It
14741493        return  -1 ;
14751494    }
14761495
1496+     /** 
1497+      * Cross-version compatible version of {@link Inventory#getStorageContents()}. 
1498+      */ 
1499+     @ Contract (pure  = true )
14771500    public  static  ItemStack [] getStorageContents (Inventory  inventory ) {
14781501        // Mojang divides player inventory like this: 
14791502        //     public final ItemStack[] items = new ItemStack[36]; 
@@ -1489,6 +1512,31 @@ public static ItemStack[] getStorageContents(Inventory inventory) {
14891512        }
14901513    }
14911514
1515+     /** 
1516+      * @see #isEmpty(ItemStack) 
1517+      * @since 7.5.2 
1518+      */ 
1519+     @ Contract (pure  = true )
1520+     public  static  boolean  notEmpty (@ Nullable  ItemStack  item ) {
1521+         return  !isEmpty (item );
1522+     }
1523+ 
1524+     /** 
1525+      * Checks if this item is {@code null} or {@link Material#AIR}. 
1526+      * The latter can only happen in the following situations: 
1527+      * <ul> 
1528+      *     <li>{@link PlayerInventory#getItemInMainHand()}</li> 
1529+      *     <li>{@link PlayerInventory#getItemInOffHand()}</li> 
1530+      * </ul> 
1531+      * 
1532+      * @see #notEmpty(ItemStack) 
1533+      * @since 7.5.2 
1534+      */ 
1535+     @ Contract (pure  = true )
1536+     public  static  boolean  isEmpty (@ Nullable  ItemStack  item ) {
1537+         return  item  == null  || item .getType () == Material .AIR ;
1538+     }
1539+ 
14921540    public  static  class  MaterialCondition  extends  RuntimeException  {
14931541        protected  XMaterial  solution ;
14941542
0 commit comments