示例#1
0
 /**
  * Whether the inventory contains the specified {@link ItemStack}. If the {@link Object} provided
  * is not an ItemStack or a {@link Material} it will return false. If the object passed in is a
  * Material, true will be returned if an ItemStack with that material is found with at least 1
  * amount.
  *
  * @param o ItemStack whose presence is to be tested in this test
  * @return true if specified ItemStack is present
  */
 @Override
 public boolean contains(Object o) {
   for (ItemStack item : contents) {
     if (item == null) {
       continue;
     }
     if (item.equals(o) || item.getMaterial().equals(o)) {
       return true;
     }
   }
   return false;
 }
示例#2
0
 /**
  * Returns the slot of the last occurrence of the specified element, or -1 if this inventory does
  * not contain the element.
  *
  * @param o element to search for
  * @return the slot of the last occurrence of the specified element
  */
 @Override
 public int lastIndexOf(Object o) {
   for (int i = contents.length - 1; i > -1; i--) {
     ItemStack item = get(i);
     if (item == null) {
       continue;
     }
     if (item.equals(o) || item.getMaterial().equals(o)) {
       return i;
     }
   }
   return -1;
 }
示例#3
0
 /**
  * Sets the slot of the first occurrence of this {@link ItemStack} or {@link Material} to null.
  *
  * @param o ItemStack to be removed from the inventory
  * @return true if the inventory contained the specified ItemStack
  */
 @Override
 public boolean remove(Object o) {
   for (int i = 0; i < contents.length; i++) {
     ItemStack item = get(i);
     if (item == null) {
       continue;
     }
     if (item.equals(o) || item.getMaterial().equals(o)) {
       set(i, null);
       return true;
     }
   }
   return false;
 }
示例#4
0
 /**
  * Sets the slot of each element in the specified collection to null.
  *
  * @param objects to remove
  * @return true
  */
 @Override
 public boolean removeAll(Collection<?> objects) {
   Iterator<?> iter = objects.iterator();
   while (iter.hasNext()) {
     Object o = iter.next();
     for (int i = 0; i < contents.length; i++) {
       ItemStack item = get(i);
       if (item == null) {
         continue;
       }
       if (item.equals(o) || item.getMaterial().equals(o)) {
         set(i, null);
       }
     }
   }
   return true;
 }