use of combatlogx.expansion.loot.protection.event.QueryPickupEvent in project CombatLogX by SirBlobman.
the class ListenerLootProtection method onEntityItemPickup.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityItemPickup(EntityPickupItemEvent e) {
Item itemEntity = e.getItem();
if (!contains(itemEntity)) {
return;
}
Entity entity = e.getEntity();
if (!(entity instanceof Player)) {
e.setCancelled(true);
return;
}
Player player = (Player) entity;
UUID itemEntityId = itemEntity.getUniqueId();
ProtectedItem protectedItem = this.protectedItemMap.get(itemEntityId);
UUID playerId = player.getUniqueId();
QueryPickupEvent queryPickupEvent = new QueryPickupEvent(player, protectedItem);
Bukkit.getPluginManager().callEvent(queryPickupEvent);
if (!protectedItem.getOwnerUUID().equals(playerId) && !queryPickupEvent.isCancelled()) {
e.setCancelled(true);
if (!this.messageCooldownSet.contains(playerId)) {
long expireMillisLeft = this.protectedItemMap.getExpectedExpiration(itemEntityId);
long expireSecondsLeft = TimeUnit.MILLISECONDS.toSeconds(expireMillisLeft);
String timeLeft = Long.toString(expireSecondsLeft);
Replacer replacer = message -> message.replace("{time}", timeLeft);
sendMessageWithPrefix(player, "expansion.loot-protection.protected", replacer, true);
this.messageCooldownSet.add(playerId);
}
}
}
Aggregations