Fixed an issue with tokens.

This commit is contained in:
songoda 2020-01-16 23:10:51 -05:00
parent e8653b0f65
commit 33efa61776
2 changed files with 18 additions and 2 deletions

View File

@ -1,14 +1,19 @@
package com.songoda.epicheads.utils;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.hooks.economies.Economy;
import com.songoda.core.utils.ItemUtils;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
public class ItemEconomy extends Economy {
public boolean isItem(ItemStack itemStack) {
if (itemStack == null)
if (itemStack == null || itemStack.getType() == Material.AIR)
return false;
if (CompatibleMaterial.getMaterial(itemStack) == CompatibleMaterial.PLAYER_HEAD)
return ItemUtils.getSkullTexture(itemStack).equals(ItemUtils.getSkullTexture(Methods.createToken(1)));
return itemStack.isSimilar(Methods.createToken(1));
}
@ -16,6 +21,17 @@ public class ItemEconomy extends Economy {
return (int) Math.ceil(amount);
}
@Override
public double getBalance(OfflinePlayer player) {
int amount = 0;
for (ItemStack item : player.getPlayer().getInventory().getContents()) {
if (!isItem(item))
continue;
amount += item.getAmount();
}
return amount;
}
@Override
public boolean hasBalance(OfflinePlayer player, double cost) {
int amount = convertAmount(cost);

View File

@ -30,7 +30,7 @@ public class Methods {
for (String line : Settings.ITEM_TOKEN_LORE.getStringList())
if (!line.equals(""))
lore.add(formatText(line));
if (lore != null) meta.setLore(lore);
meta.setLore(lore);
itemStack.setItemMeta(meta);
return itemStack;
}