mirror of
https://github.com/songoda/EpicVouchers.git
synced 2024-12-23 00:57:40 +01:00
optimize voucher check + only check permissions for valid voucher items
This commit is contained in:
parent
b899db2790
commit
b177e9b095
@ -23,38 +23,36 @@ public class PlayerInteractListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void voucherListener(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasItem()) {
|
||||
final ItemStack item = event.getItem();
|
||||
if (item == null || (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK))
|
||||
return;
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
for (Voucher voucher : instance.getVouchers().values()) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.hasPermission(voucher.getPermission()) && !voucher.getPermission().isEmpty()) {
|
||||
final ItemStack voucherItem = voucher.getItemStack();
|
||||
|
||||
// does the item they're holding match this voucher?
|
||||
if (voucherItem != null && !voucher.getItemStack().isSimilar(item))
|
||||
continue;
|
||||
else if (item.getType() != voucher.getMaterial() || item.getDurability() != voucher.getData())
|
||||
continue;
|
||||
else {
|
||||
// material matches - verify the name + lore
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null || !meta.hasDisplayName() || !meta.hasLore() || !meta.getDisplayName().equals(voucher.getName(true)) || !meta.getLore().equals(voucher.getLore(true)))
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
event.setCancelled(true);
|
||||
|
||||
if (voucher.getItemStack() != null) {
|
||||
if (!voucher.getItemStack().isSimilar(item)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (item.getType() != voucher.getMaterial() || item.getDurability() != voucher.getData()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (!item.hasItemMeta() || !meta.hasDisplayName() || !meta.getDisplayName().equals(voucher.getName(true)) || !meta.getLore().equals(voucher.getLore(true))) {
|
||||
continue;
|
||||
}
|
||||
// does the player have permission to redeem this voucher?
|
||||
if (!voucher.getPermission().isEmpty() && !player.hasPermission(voucher.getPermission())) {
|
||||
// todo: probably should send a message to the player...
|
||||
return;
|
||||
}
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (instance.getCoolDowns().isOnCoolDown(uuid)) {
|
||||
instance.getLocale().getMessage("event.general.cooldown")
|
||||
.processPlaceholder("time", instance.getCoolDowns().getTime(uuid))
|
||||
|
Loading…
Reference in New Issue
Block a user