Permalink
Browse files

Use doesInventoryContain for PlayerInvSensor.

  • Loading branch information...
me4502 committed Feb 6, 2017
1 parent 720ba29 commit 29f1a3d4b473cbb1b799734ececa5a14992c34b0
@@ -1,5 +1,6 @@
package com.sk89q.craftbook.mechanics.ic.gates.world.sensors;
+import com.sk89q.craftbook.util.InventoryUtil;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -102,7 +103,7 @@ public boolean isDetected() {
public boolean testPlayer(Player e) {
if(slot == -1 && !inHand)
- return e.getInventory().containsAtLeast(item, item.getAmount());
+ return InventoryUtil.doesInventoryContain(e.getInventory(), false, item);
else if (inHand) { //Eclipse messes with indentation without these {'s
return (e.getInventory().getItemInMainHand() != null && ItemUtil.areItemsIdentical(e.getInventory().getItemInMainHand(), item) && e.getInventory().getItemInMainHand().getAmount() >= item.getAmount())
|| (e.getInventory().getItemInOffHand() != null && ItemUtil.areItemsIdentical(e.getInventory().getItemInOffHand(), item) && e.getInventory().getItemInOffHand().getAmount() >= item.getAmount());
@@ -13,6 +13,7 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.PlayerInventory;
/**
* Class for utilities that include adding items to a furnace based on if it is a fuel or not, and adding items to a chest. Also will include methdos for checking contents and removing.
@@ -126,13 +127,17 @@ public static boolean doesInventoryContain(Inventory inv, boolean exact, ItemSta
if(itemsToFind.isEmpty())
return true;
- for (ItemStack item : inv.getContents()) {
+ List<ItemStack> items = new ArrayList<ItemStack>(Arrays.asList(inv.getContents()));
+ if (inv instanceof PlayerInventory) {
+ items.addAll(Arrays.asList(((PlayerInventory) inv).getArmorContents()));
+ items.add(((PlayerInventory) inv).getItemInOffHand());
+ }
+ for (ItemStack item : inv.getContents()) {

This comment has been minimized.

Show comment
Hide comment
@BillyGalbreath

BillyGalbreath Jan 22, 2018

Was this on purpose? You populate items, but then use inv.getContents()

I'm about to make a PR that modifies this method quite a bit, so I was wondering so I should include this in my PR or not (to minimize conflicts).

@BillyGalbreath

BillyGalbreath Jan 22, 2018

Was this on purpose? You populate items, but then use inv.getContents()

I'm about to make a PR that modifies this method quite a bit, so I was wondering so I should include this in my PR or not (to minimize conflicts).

This comment has been minimized.

Show comment
Hide comment
@me4502

me4502 Jan 22, 2018

Member

It doesn't appear that was intentional, good catch.

@me4502

me4502 Jan 22, 2018

Member

It doesn't appear that was intentional, good catch.

if(!ItemUtil.isStackValid(item))
continue;
for(ItemStack base : stacks) {
-
if(!itemsToFind.contains(base))
continue;
@@ -142,7 +147,6 @@ public static boolean doesInventoryContain(Inventory inv, boolean exact, ItemSta
}
if(ItemUtil.areItemsIdentical(base, item)) {
-
if(exact && base.getAmount() != item.getAmount())
continue;

0 comments on commit 29f1a3d

Please sign in to comment.