Search in sources :

Example 1 with CitizensExpansion

use of combatlogx.expansion.compatibility.citizens.CitizensExpansion 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 2 with CitizensExpansion

use of combatlogx.expansion.compatibility.citizens.CitizensExpansion in project CombatLogX by SirBlobman.

the class CombatNpcManager method equipNPC.

public void equipNPC(Player player, NPC npc) {
    CitizensExpansion expansion = getExpansion();
    InventoryManager inventoryManager = expansion.getInventoryManager();
    inventoryManager.equipNPC(player, npc);
}
Also used : CitizensExpansion(combatlogx.expansion.compatibility.citizens.CitizensExpansion)

Example 3 with CitizensExpansion

use of combatlogx.expansion.compatibility.citizens.CitizensExpansion in project CombatLogX by SirBlobman.

the class InventoryManager method storeInventory.

public void storeInventory(Player player) {
    Validate.notNull(player, "player must not be null!");
    if (player.hasMetadata("NPC")) {
        throw new IllegalArgumentException("player must not be an NPC!");
    }
    PlayerInventory playerInventory = player.getInventory();
    StoredInventory storedInventory = StoredInventory.createFrom(playerInventory);
    UUID playerId = player.getUniqueId();
    this.storedInventoryMap.put(playerId, storedInventory);
    PlayerDataManager playerDataManager = getPlayerDataManager();
    YamlConfiguration configuration = playerDataManager.get(player);
    ConfigurationSection section = configuration.createSection("citizens-compatibility.stored-inventory");
    CitizensExpansion expansion = getExpansion();
    storedInventory.save(expansion, section);
    playerDataManager.save(player);
}
Also used : StoredInventory(combatlogx.expansion.compatibility.citizens.object.StoredInventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) UUID(java.util.UUID) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) CitizensExpansion(combatlogx.expansion.compatibility.citizens.CitizensExpansion) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 4 with CitizensExpansion

use of combatlogx.expansion.compatibility.citizens.CitizensExpansion in project CombatLogX by SirBlobman.

the class CombatNpcManager method saveInventory.

public void saveInventory(Player player) {
    YamlConfiguration configuration = getConfiguration();
    if (!configuration.getBoolean("store-inventory")) {
        return;
    }
    CitizensExpansion expansion = getExpansion();
    InventoryManager inventoryManager = expansion.getInventoryManager();
    inventoryManager.storeInventory(player);
    PlayerInventory playerInventory = player.getInventory();
    playerInventory.clear();
    player.updateInventory();
}
Also used : PlayerInventory(org.bukkit.inventory.PlayerInventory) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) CitizensExpansion(combatlogx.expansion.compatibility.citizens.CitizensExpansion)

Example 5 with CitizensExpansion

use of combatlogx.expansion.compatibility.citizens.CitizensExpansion in project CombatLogX by SirBlobman.

the class InventoryManager method getStoredInventory.

@Nullable
public StoredInventory getStoredInventory(OfflinePlayer player) {
    Validate.notNull(player, "player must not be null!");
    UUID playerId = player.getUniqueId();
    if (this.storedInventoryMap.containsKey(playerId)) {
        return this.storedInventoryMap.get(playerId);
    }
    PlayerDataManager playerDataManager = getPlayerDataManager();
    YamlConfiguration configuration = playerDataManager.get(player);
    String storagePath = ("citizens-compatibility.stored-inventory");
    ConfigurationSection section = configuration.getConfigurationSection(storagePath);
    if (section == null) {
        return null;
    }
    CitizensExpansion expansion = getExpansion();
    return StoredInventory.createFrom(expansion, section);
}
Also used : UUID(java.util.UUID) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) CitizensExpansion(combatlogx.expansion.compatibility.citizens.CitizensExpansion) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CitizensExpansion (combatlogx.expansion.compatibility.citizens.CitizensExpansion)5 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)4 UUID (java.util.UUID)3 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2 EntityHandler (com.github.sirblobman.api.nms.EntityHandler)1 MultiVersionHandler (com.github.sirblobman.api.nms.MultiVersionHandler)1 ICombatLogX (com.github.sirblobman.combatlogx.api.ICombatLogX)1 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)1 CombatNPC (combatlogx.expansion.compatibility.citizens.object.CombatNPC)1 StoredInventory (combatlogx.expansion.compatibility.citizens.object.StoredInventory)1 NPC (net.citizensnpcs.api.npc.NPC)1 NPCRegistry (net.citizensnpcs.api.npc.NPCRegistry)1 Location (org.bukkit.Location)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Entity (org.bukkit.entity.Entity)1 EntityType (org.bukkit.entity.EntityType)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Monster (org.bukkit.entity.Monster)1