Search in sources :

Example 1 with QueryPickupEvent

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);
        }
    }
}
Also used : QueryPickupEvent(combatlogx.expansion.loot.protection.event.QueryPickupEvent) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) Item(org.bukkit.entity.Item) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) ExpansionListener(com.github.sirblobman.combatlogx.api.expansion.ExpansionListener) ItemSpawnEvent(org.bukkit.event.entity.ItemSpawnEvent) Player(org.bukkit.entity.Player) EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) EventHandler(org.bukkit.event.EventHandler) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) QueryPickupEvent(combatlogx.expansion.loot.protection.event.QueryPickupEvent) Location(org.bukkit.Location) Replacer(com.github.sirblobman.api.language.Replacer) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Bukkit(org.bukkit.Bukkit) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PlayerPunishEvent(com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent) Entity(org.bukkit.entity.Entity) PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) ExpiringMap(net.jodah.expiringmap.ExpiringMap) Set(java.util.Set) UUID(java.util.UUID) LivingEntity(org.bukkit.entity.LivingEntity) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) ItemStack(org.bukkit.inventory.ItemStack) TimeUnit(java.util.concurrent.TimeUnit) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) List(java.util.List) EventPriority(org.bukkit.event.EventPriority) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Item(org.bukkit.entity.Item) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) Replacer(com.github.sirblobman.api.language.Replacer) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)1 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)1 Replacer (com.github.sirblobman.api.language.Replacer)1 WorldXYZ (com.github.sirblobman.api.object.WorldXYZ)1 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)1 PlayerPunishEvent (com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent)1 PlayerUntagEvent (com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent)1 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)1 ExpansionListener (com.github.sirblobman.combatlogx.api.expansion.ExpansionListener)1 IDeathListener (com.github.sirblobman.combatlogx.api.listener.IDeathListener)1 UntagReason (com.github.sirblobman.combatlogx.api.object.UntagReason)1 QueryPickupEvent (combatlogx.expansion.loot.protection.event.QueryPickupEvent)1 ProtectedItem (combatlogx.expansion.loot.protection.object.ProtectedItem)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1