修复满背包依然可以购买的Bug

玩家背包getContent获取的内容包括了防具栏等
也就是说,即便背包是满的,只要没穿防具就依然可以购买物品
但是因为没有储存空间,导致花了钱,也无法获得该物品
pull/8/MERGE
17jiong 2018-01-31 18:49:19 +08:00
parent 4a18053026
commit 2b82a8430d
1 changed files with 480 additions and 463 deletions

View File

@ -18,7 +18,9 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.MaterialData;
import org.bukkit.material.Sign;
import org.maxgamer.QuickShop.QuickShop;
@ -71,7 +73,7 @@ public class Util {
*/
public static int countItems(final Inventory inv, final ItemStack item) {
int items = 0;
for (final ItemStack iStack : inv.getContents()) {
for (final ItemStack iStack : inv.getStorageContents()) {
if (iStack == null) {
continue;
}
@ -94,7 +96,7 @@ public class Util {
*/
public static int countSpace(final Inventory inv, final ItemStack item) {
int space = 0;
for (final ItemStack iStack : inv.getContents()) {
for (final ItemStack iStack : inv.getStorageContents()) {
if (iStack == null || iStack.getType() == Material.AIR) {
space += item.getMaxStackSize();
} else if (matches(item, iStack)) {
@ -111,7 +113,9 @@ public class Util {
}
public static String firstUppercase(final String string) {
if (string.length() > 1) { return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase(); }
if (string.length() > 1) {
return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase();
}
return string.toUpperCase();
}
@ -177,14 +181,18 @@ public class Util {
* @return the block which is also a chest and connected to b.
*/
public static Block getSecondHalf(final Block b) {
if (!b.getType().toString().contains("CHEST")) { return null; }
if (!b.getType().toString().contains("CHEST")) {
return null;
}
final Block[] blocks = new Block[4];
blocks[0] = b.getRelative(1, 0, 0);
blocks[1] = b.getRelative(-1, 0, 0);
blocks[2] = b.getRelative(0, 0, 1);
blocks[3] = b.getRelative(0, 0, -1);
for (final Block c : blocks) {
if (c.getType() == b.getType()) { return c; }
if (c.getType() == b.getType()) {
return c;
}
}
return null;
}
@ -453,22 +461,29 @@ public class Util {
* The first item stack
* @param stack2
* The second item stack
* @return true if the itemstacks match. (Material, durability, enchants, name)
* @return true if the itemstacks match. (Material, durability, enchants,
* name)
*/
public static boolean matches(final ItemStack stack1, final ItemStack stack2) {
if (stack1 == stack2) { return true; // Referring to the same thing, or both are null.
if (stack1 == stack2) {
return true; // Referring to the same thing, or both are null.
}
if (stack1 == null || stack2 == null) { return false; // One of them is null (Can't be both, see above)
if (stack1 == null || stack2 == null) {
return false; // One of them is null (Can't be both, see above)
}
if (stack1.getType() != stack2.getType()) { return false; // Not the same material
if (stack1.getType() != stack2.getType()) {
return false; // Not the same material
}
if (stack1.getDurability() != stack2.getDurability()) { return false; // Not the same durability
if (stack1.getDurability() != stack2.getDurability()) {
return false; // Not the same durability
}
if (!stack1.getEnchantments().equals(stack2.getEnchantments())) { return false; // They have the same enchants
if (!stack1.getEnchantments().equals(stack2.getEnchantments())) {
return false; // They have the same enchants
}
if (stack1.getItemMeta().hasDisplayName() || stack2.getItemMeta().hasDisplayName()) {
if (stack1.getItemMeta().hasDisplayName() && stack2.getItemMeta().hasDisplayName()) {
if (!stack1.getItemMeta().getDisplayName().equals(stack2.getItemMeta().getDisplayName())) { return false; // items have different display name
if (!stack1.getItemMeta().getDisplayName().equals(stack2.getItemMeta().getDisplayName())) {
return false; // items have different display name
}
} else {
return false; // one of the item stacks have a display name
@ -544,14 +559,16 @@ public class Util {
Class.forName("org.bukkit.inventory.meta.EnchantmentStorageMeta");
final boolean book1 = stack1.getItemMeta() instanceof EnchantmentStorageMeta;
final boolean book2 = stack2.getItemMeta() instanceof EnchantmentStorageMeta;
if (book1 != book2) { return false;// One has enchantment meta, the other does not.
if (book1 != book2) {
return false;// One has enchantment meta, the other does not.
}
if (book1) { // They are the same here (both true or both
// false). So if one is true, the other is
// true.
final Map<Enchantment, Integer> ench1 = ((EnchantmentStorageMeta) stack1.getItemMeta()).getStoredEnchants();
final Map<Enchantment, Integer> ench2 = ((EnchantmentStorageMeta) stack2.getItemMeta()).getStoredEnchants();
if (!ench1.equals(ench2)) { return false; // Enchants aren't the same.
if (!ench1.equals(ench2)) {
return false; // Enchants aren't the same.
}
}
} catch (final ClassNotFoundException e) {