Search in sources :

Example 71 with ICombatLogX

use of com.github.sirblobman.combatlogx.api.ICombatLogX 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)

Example 72 with ICombatLogX

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

the class ListenerDamage method checkTag.

private void checkTag(Entity entity, Entity enemy, TagReason tagReason) {
    if (!(entity instanceof Player)) {
        return;
    }
    Player player = (Player) entity;
    if (hasBypassPermission(player)) {
        return;
    }
    if (!(enemy instanceof LivingEntity)) {
        return;
    }
    LivingEntity livingEnemy = (LivingEntity) enemy;
    EntityType enemyType = livingEnemy.getType();
    if (isDisabled(enemyType)) {
        return;
    }
    SpawnReason spawnReason = getSpawnReason(livingEnemy);
    if (isDisabled(spawnReason)) {
        return;
    }
    ICombatLogX plugin = getCombatLogX();
    ICombatManager combatManager = plugin.getCombatManager();
    combatManager.tag(player, livingEnemy, TagType.MOB, tagReason);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityType(org.bukkit.entity.EntityType) Player(org.bukkit.entity.Player) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Example 73 with ICombatLogX

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

the class SpawnReasonManager_New method getPlugin.

private JavaPlugin getPlugin() {
    MobTaggerExpansion expansion = getExpansion();
    ICombatLogX combatLogX = expansion.getPlugin();
    return combatLogX.getPlugin();
}
Also used : ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) MobTaggerExpansion(combatlogx.expansion.mob.tagger.MobTaggerExpansion)

Example 74 with ICombatLogX

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

the class Reward method getEntityName.

private String getEntityName(LivingEntity entity) {
    ICombatLogX plugin = this.expansion.getPlugin();
    MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
    EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
    return entityHandler.getName(entity);
}
Also used : MultiVersionHandler(com.github.sirblobman.api.nms.MultiVersionHandler) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) EntityHandler(com.github.sirblobman.api.nms.EntityHandler)

Example 75 with ICombatLogX

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

the class ScoreboardExpansion method onEnable.

@Override
public void onEnable() {
    ICombatLogX plugin = getPlugin();
    ITimerManager timerManager = plugin.getTimerManager();
    timerManager.addUpdaterTask(new ScoreboardUpdater(this));
}
Also used : ITimerManager(com.github.sirblobman.combatlogx.api.manager.ITimerManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Aggregations

ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)96 ExpansionManager (com.github.sirblobman.combatlogx.api.expansion.ExpansionManager)24 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)19 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)19 Player (org.bukkit.entity.Player)18 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)14 LivingEntity (org.bukkit.entity.LivingEntity)13 LanguageManager (com.github.sirblobman.api.language.LanguageManager)12 Logger (java.util.logging.Logger)11 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)10 MultiVersionHandler (com.github.sirblobman.api.nms.MultiVersionHandler)9 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)8 Expansion (com.github.sirblobman.combatlogx.api.expansion.Expansion)8 List (java.util.List)8 Replacer (com.github.sirblobman.api.language.Replacer)6 EntityHandler (com.github.sirblobman.api.nms.EntityHandler)5 State (com.github.sirblobman.combatlogx.api.expansion.Expansion.State)5 Collections (java.util.Collections)5 EventHandler (org.bukkit.event.EventHandler)5 NewbieHelperExpansion (combatlogx.expansion.newbie.helper.NewbieHelperExpansion)4