Search in sources :

Example 26 with ICombatLogX

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

the class ListenerJoin method setHealth.

private void setHealth(Player player, double health) {
    if (Double.isInfinite(health) || Double.isNaN(health)) {
        health = 0.0D;
    }
    ICombatLogX combatLogX = getCombatLogX();
    MultiVersionHandler multiVersionHandler = combatLogX.getMultiVersionHandler();
    EntityHandler entityHandler = multiVersionHandler.getEntityHandler();
    double maxHealth = entityHandler.getMaxHealth(player);
    if (maxHealth < health) {
        entityHandler.setMaxHealth(player, health);
    }
    player.setHealth(health);
}
Also used : MultiVersionHandler(com.github.sirblobman.api.nms.MultiVersionHandler) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) EntityHandler(com.github.sirblobman.api.nms.EntityHandler)

Example 27 with ICombatLogX

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

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

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

the class CombatNPC method start.

public void start() {
    resetSurvivalTime();
    ICombatLogX combatLogX = this.expansion.getPlugin();
    JavaPlugin plugin = combatLogX.getPlugin();
    runTaskTimerAsynchronously(plugin, 1L, 1L);
}
Also used : JavaPlugin(org.bukkit.plugin.java.JavaPlugin) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX)

Example 30 with ICombatLogX

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

the class StoredInventory method loadItemStack.

@Nullable
private static ItemStack loadItemStack(CitizensExpansion expansion, ConfigurationSection section, String path) {
    Validate.notNull(section, "section must not be null!");
    Validate.notEmpty(path, "path must not be empty!");
    if (!section.isSet(path)) {
        return null;
    }
    if (!section.isString(path)) {
        return null;
    }
    String value = section.getString(path);
    if (value == null) {
        return null;
    }
    ICombatLogX plugin = expansion.getPlugin();
    MultiVersionHandler multiVersionHandler = plugin.getMultiVersionHandler();
    ItemHandler itemHandler = multiVersionHandler.getItemHandler();
    return itemHandler.fromBase64String(value);
}
Also used : MultiVersionHandler(com.github.sirblobman.api.nms.MultiVersionHandler) ItemHandler(com.github.sirblobman.api.nms.ItemHandler) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) Nullable(org.jetbrains.annotations.Nullable)

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