mirror of
https://github.com/songoda/EpicVouchers.git
synced 2024-12-23 09:08:22 +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
|
@EventHandler
|
||||||
public void voucherListener(PlayerInteractEvent event) {
|
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;
|
return;
|
||||||
}
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
for (Voucher voucher : instance.getVouchers().values()) {
|
for (Voucher voucher : instance.getVouchers().values()) {
|
||||||
Player player = event.getPlayer();
|
final ItemStack voucherItem = voucher.getItemStack();
|
||||||
if (!player.hasPermission(voucher.getPermission()) && !voucher.getPermission().isEmpty()) {
|
|
||||||
|
// does the item they're holding match this voucher?
|
||||||
|
if (voucherItem != null && !voucher.getItemStack().isSimilar(item))
|
||||||
continue;
|
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) {
|
// does the player have permission to redeem this voucher?
|
||||||
if (!voucher.getItemStack().isSimilar(item)) {
|
if (!voucher.getPermission().isEmpty() && !player.hasPermission(voucher.getPermission())) {
|
||||||
continue;
|
// todo: probably should send a message to the player...
|
||||||
}
|
return;
|
||||||
} 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
if (instance.getCoolDowns().isOnCoolDown(uuid)) {
|
if (instance.getCoolDowns().isOnCoolDown(uuid)) {
|
||||||
instance.getLocale().getMessage("event.general.cooldown")
|
instance.getLocale().getMessage("event.general.cooldown")
|
||||||
.processPlaceholder("time", instance.getCoolDowns().getTime(uuid))
|
.processPlaceholder("time", instance.getCoolDowns().getTime(uuid))
|
||||||
|
Loading…
Reference in New Issue
Block a user