Search in sources :

Example 16 with ICombatManager

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

the class BossBarUpdater method replacePlaceholders.

private String replacePlaceholders(Player player, String message) {
    ICombatLogX combatLogX = getCombatLogX();
    ICombatManager combatManager = combatLogX.getCombatManager();
    LivingEntity enemy = combatManager.getEnemy(player);
    return combatManager.replaceVariables(player, enemy, message);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Example 17 with ICombatManager

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

the class BossBarUpdater method getProgress.

private double getProgress(Player player, double timeLeftMillis) {
    ICombatManager combatManager = getCombatManager();
    long timerMaxSeconds = combatManager.getMaxTimerSeconds(player);
    double timerMaxMillis = TimeUnit.SECONDS.toMillis(timerMaxSeconds);
    double barPercentage = (timeLeftMillis / timerMaxMillis);
    if (barPercentage <= 0.0D) {
        return 0.0D;
    }
    return Math.min(barPercentage, 1.0D);
}
Also used : ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager)

Example 18 with ICombatManager

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

the class CombatNpcManager method createNPC.

public void createNPC(Player player) {
    if (player == null || player.hasMetadata("NPC")) {
        printDebug("player was null or an NPC, not spawning.");
        return;
    }
    UUID uuid = player.getUniqueId();
    String playerName = player.getName();
    printDebug("Spawning NPC for player '" + playerName + "'.");
    EntityType entityType = getEntityType();
    NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
    NPC npc = npcRegistry.createNPC(entityType, playerName);
    printDebug("Created NPC with entity type " + entityType + ".");
    Location location = player.getLocation();
    boolean spawn = npc.spawn(location);
    if (!spawn) {
        printDebug("Failed to spawn an NPC. (npc.spawn() returned false)");
        return;
    }
    Entity entity = npc.getEntity();
    if (!(entity instanceof LivingEntity)) {
        printDebug("NPC for player '" + playerName + "' is not a LivingEntity, removing...");
        npc.destroy();
        return;
    }
    LivingEntity livingEntity = (LivingEntity) entity;
    npc.setProtected(false);
    if (npc.hasTrait(Owner.class)) {
        npc.removeTrait(Owner.class);
    }
    ICombatLogX plugin = this.expansion.getPlugin();
    MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
    EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
    double health = player.getHealth();
    double maxHealth = entityHandler.getMaxHealth(livingEntity);
    if (maxHealth < health)
        entityHandler.setMaxHealth(livingEntity, health);
    livingEntity.setHealth(health);
    YamlConfiguration configuration = getConfiguration();
    if (configuration.getBoolean("mob-target")) {
        double radius = configuration.getDouble("mob-target-radius");
        List<Entity> nearbyEntityList = livingEntity.getNearbyEntities(radius, radius, radius);
        for (Entity nearby : nearbyEntityList) {
            if (!(nearby instanceof Monster)) {
                continue;
            }
            Monster monster = (Monster) nearby;
            monster.setTarget(livingEntity);
        }
    }
    CombatNPC combatNPC = new CombatNPC(this.expansion, npc, player);
    this.playerNpcMap.put(uuid, combatNPC);
    this.npcCombatMap.put(npc.getUniqueId(), combatNPC);
    ICombatManager combatManager = plugin.getCombatManager();
    LivingEntity enemyEntity = combatManager.getEnemy(player);
    if (enemyEntity instanceof Player)
        combatNPC.setEnemy((Player) enemyEntity);
    saveLocation(player, npc);
    saveInventory(player);
    equipNPC(player, npc);
    CitizensExpansion citizensExpansion = getExpansion();
    if (citizensExpansion.isSentinelEnabled()) {
        if (enemyEntity != null && configuration.getBoolean("attack-first")) {
            SentinelTrait sentinelTrait = npc.getOrAddTrait(SentinelTrait.class);
            sentinelTrait.setInvincible(false);
            sentinelTrait.respawnTime = -1;
            UUID enemyId = enemyEntity.getUniqueId();
            String enemyIdString = enemyId.toString();
            SentinelTargetLabel targetLabel = new SentinelTargetLabel("uuid:" + enemyIdString);
            targetLabel.addToList(sentinelTrait.allTargets);
        }
    }
    combatNPC.start();
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) MultiVersionHandler(com.github.sirblobman.api.nms.MultiVersionHandler) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) SentinelTrait(org.mcmonkey.sentinel.SentinelTrait) CitizensExpansion(combatlogx.expansion.compatibility.citizens.CitizensExpansion) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) Monster(org.bukkit.entity.Monster) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) SentinelTargetLabel(org.mcmonkey.sentinel.targeting.SentinelTargetLabel) UUID(java.util.UUID) EntityHandler(com.github.sirblobman.api.nms.EntityHandler) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) Location(org.bukkit.Location)

Example 19 with ICombatManager

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

the class CombatNPC method run.

@Override
public void run() {
    this.survivalTicks--;
    if (this.survivalTicks > 0)
        return;
    YamlConfiguration configuration = this.expansion.getConfigurationManager().get("citizens.yml");
    if (configuration.getBoolean("stay-until-enemy-escape") && this.enemyId != null) {
        Player player = Bukkit.getPlayer(this.enemyId);
        ICombatManager combatManager = this.expansion.getPlugin().getCombatManager();
        if (player != null && combatManager.isInCombat(player)) {
            long timerLeftMillis = combatManager.getTimerLeftMillis(player);
            this.survivalTicks = (timerLeftMillis / 50L) + 1;
            return;
        }
    }
    CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
    combatNpcManager.remove(this);
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager)

Example 20 with ICombatManager

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

the class PlaceholderHelper method getEnemyType.

public static String getEnemyType(ICombatLogX plugin, Player player) {
    ICombatManager combatManager = plugin.getCombatManager();
    LivingEntity enemy = combatManager.getEnemy(player);
    if (enemy == null)
        return getUnknownEnemy(plugin, player);
    EntityType entityType = enemy.getType();
    return entityType.name();
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityType(org.bukkit.entity.EntityType) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager)

Aggregations

ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)56 Player (org.bukkit.entity.Player)29 LivingEntity (org.bukkit.entity.LivingEntity)24 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)19 EventHandler (org.bukkit.event.EventHandler)9 Location (org.bukkit.Location)8 LanguageManager (com.github.sirblobman.api.language.LanguageManager)7 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)7 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)5 TagType (com.github.sirblobman.combatlogx.api.object.TagType)5 Entity (org.bukkit.entity.Entity)5 Replacer (com.github.sirblobman.api.language.Replacer)4 DecimalFormat (java.text.DecimalFormat)4 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 EntityType (org.bukkit.entity.EntityType)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)2 EntityHandler (com.github.sirblobman.api.nms.EntityHandler)2