Search in sources :

Example 1 with IDeathListener

use of com.github.sirblobman.combatlogx.api.listener.IDeathListener in project CombatLogX by SirBlobman.

the class ListenerDeathEffects method onDeath.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onDeath(PlayerDeathEvent e) {
    YamlConfiguration configuration = getConfiguration();
    List<String> enabledDeathEffectList = configuration.getStringList("death-effect-list");
    if (enabledDeathEffectList.isEmpty())
        return;
    Player player = e.getEntity();
    boolean requireCombatDeath = configuration.getBoolean("combat-death-only");
    if (requireCombatDeath) {
        ICombatLogX combatLogX = getCombatLogX();
        IDeathListener deathListener = combatLogX.getDeathListener();
        if (!deathListener.contains(player))
            return;
    }
    if (enabledDeathEffectList.contains("BLOOD")) {
        playBloodEffect(player);
    }
    if (enabledDeathEffectList.contains("LIGHTNING")) {
        playLightningEffect(player);
    }
}
Also used : Player(org.bukkit.entity.Player) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) EventHandler(org.bukkit.event.EventHandler)

Example 2 with IDeathListener

use of com.github.sirblobman.combatlogx.api.listener.IDeathListener in project CombatLogX by SirBlobman.

the class PunishManager method runKillCheck.

private void runKillCheck(Player player) {
    ConfigurationManager configurationManager = this.plugin.getConfigurationManager();
    YamlConfiguration configuration = configurationManager.get("punish.yml");
    String killOptionString = configuration.getString("kill-time");
    if (killOptionString == null) {
        killOptionString = "QUIT";
    }
    if (killOptionString.equals("QUIT")) {
        IDeathListener listenerDeath = this.plugin.getDeathListener();
        listenerDeath.add(player);
        player.setHealth(0.0D);
    }
    if (killOptionString.equals("JOIN")) {
        YamlConfiguration playerData = this.plugin.getData(player);
        playerData.set("kill-on-join", true);
        this.plugin.saveData(player);
    }
}
Also used : IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager)

Example 3 with IDeathListener

use of com.github.sirblobman.combatlogx.api.listener.IDeathListener in project CombatLogX by SirBlobman.

the class ListenerLootProtection method onDeath.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDeath(EntityDeathEvent e) {
    LivingEntity entity = e.getEntity();
    ICombatLogX combatLogX = getCombatLogX();
    IDeathListener deathListener = combatLogX.getDeathListener();
    YamlConfiguration configuration = getExpansionConfigurationManager().get("config.yml");
    if (entity instanceof Player) {
        Player player = (Player) entity;
        if (configuration.getBoolean("only-protect-after-log", false) && !deathListener.contains(player)) {
            return;
        }
    }
    UUID entityId = entity.getUniqueId();
    UUID enemyId = this.enemyMap.get(entityId);
    if (!checkVoidKill(e) && entity instanceof Player) {
        Player player = (Player) entity;
        PlayerDataManager playerDataManager = getPlayerDataManager();
        YamlConfiguration playerData = playerDataManager.get(player);
        String enemyIdString = playerData.getString("loot-protection-enemy");
        if (enemyIdString != null) {
            playerData.set("loot-protection-enemy", null);
            playerDataManager.save(player);
            enemyId = UUID.fromString(enemyIdString);
        }
    }
    if (enemyId == null) {
        return;
    }
    Entity enemy = Bukkit.getEntity(enemyId);
    if (enemy == null) {
        return;
    }
    enemyId = enemy.getUniqueId();
    WorldXYZ entityLocation = WorldXYZ.from(entity);
    ConcurrentLinkedQueue<ProtectedItem> protectedItemQueue = new ConcurrentLinkedQueue<>();
    List<ItemStack> dropList = e.getDrops();
    for (ItemStack drop : dropList) {
        ProtectedItem protectedItem = new ProtectedItem(entityLocation, drop);
        protectedItem.setOwnerUUID(enemyId);
        protectedItemQueue.add(protectedItem);
    }
    this.pendingProtectionMap.put(entityLocation, protectedItemQueue);
    String entityName = (entity.getCustomName() == null ? entity.getName() : entity.getCustomName());
    long timeLeftMillis = this.protectedItemMap.getExpiration();
    long timeLeftSeconds = TimeUnit.MILLISECONDS.toSeconds(timeLeftMillis);
    String timeLeft = Long.toString(timeLeftSeconds);
    Replacer replacer = message -> message.replace("{time}", timeLeft).replace("{enemy}", entityName);
    sendMessageWithPrefix(enemy, "expansion.loot-protection.enemy-died", replacer, true);
}
Also used : 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) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) Replacer(com.github.sirblobman.api.language.Replacer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) LivingEntity(org.bukkit.entity.LivingEntity) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) UUID(java.util.UUID) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

IDeathListener (com.github.sirblobman.combatlogx.api.listener.IDeathListener)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)2 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)2 Player (org.bukkit.entity.Player)2 EventHandler (org.bukkit.event.EventHandler)2 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)1 Replacer (com.github.sirblobman.api.language.Replacer)1 WorldXYZ (com.github.sirblobman.api.object.WorldXYZ)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 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