fix item
This commit is contained in:
parent
fa432ff741
commit
bf809208ae
@ -5,7 +5,7 @@ plugins {
|
|||||||
id 'com.github.johnrengelman.shadow' version '4.0.4'
|
id 'com.github.johnrengelman.shadow' version '4.0.4'
|
||||||
}
|
}
|
||||||
group = 'me.skymc'
|
group = 'me.skymc'
|
||||||
version = '5.01'
|
version = '5.02'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package io.izzel.taboolib.cronus.bukkit;
|
package io.izzel.taboolib.cronus.bukkit;
|
||||||
|
|
||||||
import io.izzel.taboolib.util.item.Items;
|
import io.izzel.taboolib.util.item.Items;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,37 +48,11 @@ public class ItemStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasItem(Player player) {
|
public boolean hasItem(Player player) {
|
||||||
int checkAmount = amount;
|
return Items.hasItem(player.getInventory(), this::isItem, amount);
|
||||||
for (org.bukkit.inventory.ItemStack itemStack : player.getInventory().getContents()) {
|
|
||||||
if (itemStack != null && !itemStack.getType().equals(Material.AIR) && isItem(itemStack)) {
|
|
||||||
checkAmount -= itemStack.getAmount();
|
|
||||||
if (checkAmount <= 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean takeItem(Player player) {
|
public boolean takeItem(Player player) {
|
||||||
int takeAmount = amount;
|
return Items.takeItem(player.getInventory(), this::isItem, amount);
|
||||||
org.bukkit.inventory.ItemStack[] contents = player.getInventory().getContents();
|
|
||||||
for (int i = 0; i < contents.length; i++) {
|
|
||||||
org.bukkit.inventory.ItemStack itemStack = contents[i];
|
|
||||||
if (itemStack != null && !itemStack.getType().equals(Material.AIR) && isItem(itemStack)) {
|
|
||||||
takeAmount -= itemStack.getAmount();
|
|
||||||
if (takeAmount < 0) {
|
|
||||||
itemStack.setAmount(itemStack.getAmount() - (takeAmount + itemStack.getAmount()));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
player.getInventory().setItem(i, null);
|
|
||||||
if (takeAmount == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
|
@ -164,7 +164,7 @@ public class Items {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkItem(Player player, ItemStack item, int amount, boolean remove) {
|
public static boolean checkItem(Player player, ItemStack item, int amount, boolean remove) {
|
||||||
return hasItem(player.getInventory(), i -> i.isSimilar(item), amount);
|
return remove ? takeItem(player.getInventory(), i -> i.isSimilar(item), amount) : hasItem(player.getInventory(), i -> i.isSimilar(item), amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkItem(Inventory inventory, ItemStack item, int amount, boolean remove) {
|
public static boolean checkItem(Inventory inventory, ItemStack item, int amount, boolean remove) {
|
||||||
@ -321,7 +321,7 @@ public class Items {
|
|||||||
return NMS.handle().saveNBT(item, nbt);
|
return NMS.handle().saveNBT(item, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Matcher {
|
public interface Matcher {
|
||||||
|
|
||||||
boolean match(ItemStack item);
|
boolean match(ItemStack item);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user