Search in sources :

Example 1 with CombatNpcManager

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

the class CitizensExpansion method onDisable.

@Override
public void onDisable() {
    CombatNpcManager combatNpcManager = getCombatNpcManager();
    combatNpcManager.removeAll();
}
Also used : CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager)

Example 2 with CombatNpcManager

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

the class ListenerDeath method onDeathNPC.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDeathNPC(NPCDeathEvent e) {
    printDebug("Detected NPCDeathEvent...");
    NPC npc = e.getNPC();
    CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
    CombatNPC combatNPC = combatNpcManager.getCombatNPC(npc);
    if (combatNPC == null) {
        printDebug("NPC was not combat NPC, ignoring event.");
        return;
    }
    printDebug("Setting drops and exp to zero and sending custom death message.");
    e.setDroppedExp(0);
    e.getDrops().clear();
    checkForDeathMessages(e, combatNPC);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager) EventHandler(org.bukkit.event.EventHandler)

Example 3 with CombatNpcManager

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

the class ListenerDeath method onDamageNPC.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDamageNPC(NPCDamageByEntityEvent e) {
    printDebug("Detected NPCDamageByEntityEvent...");
    YamlConfiguration configuration = getConfiguration();
    if (!configuration.getBoolean("stay-until-no-damage")) {
        printDebug("Stay until no damage setting is not enabled, ignoring event.");
        return;
    }
    NPC npc = e.getNPC();
    CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
    CombatNPC combatNPC = combatNpcManager.getCombatNPC(npc);
    if (combatNPC == null) {
        printDebug("NPC was not combat NPC, ignoring event.");
        return;
    }
    printDebug("Resetting NPC survival time.");
    combatNPC.resetSurvivalTime();
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager) EventHandler(org.bukkit.event.EventHandler)

Example 4 with CombatNpcManager

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

the class ListenerDeath method onDespawnNPC.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDespawnNPC(NPCDespawnEvent e) {
    printDebug("Detected NPCDespawnEvent...");
    DespawnReason despawnReason = e.getReason();
    if (despawnReason == DespawnReason.PENDING_RESPAWN) {
        printDebug("Despawn reason is PENDING_RESPAWN, ignoring event.");
        return;
    }
    NPC npc = e.getNPC();
    CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
    CombatNPC combatNPC = combatNpcManager.getCombatNPC(npc);
    if (combatNPC == null) {
        printDebug("NPC was not combat NPC, ignoring event.");
        return;
    }
    OfflinePlayer offlinePlayer = combatNPC.getOfflineOwner();
    if (despawnReason == DespawnReason.DEATH) {
        Location location = combatNpcManager.getLocation(npc);
        if (location != null) {
            printDebug("Despawn reason was death, drop NPC inventory.");
            InventoryManager inventoryManager = this.expansion.getInventoryManager();
            inventoryManager.dropInventory(offlinePlayer, location);
        }
    }
    if (despawnReason != DespawnReason.REMOVAL) {
        printDebug("Despawn reason was not removal, destroying NPC.");
        combatNpcManager.remove(combatNPC);
        printDebug("Destroy NPC later.");
        JavaPlugin plugin = this.expansion.getPlugin().getPlugin();
        BukkitScheduler scheduler = Bukkit.getScheduler();
        scheduler.runTaskLater(plugin, npc::destroy, 1L);
    }
    printDebug("Setting player to be punished when they next join.");
    YamlConfiguration data = combatNpcManager.getData(offlinePlayer);
    data.set("citizens-compatibility.punish-next-join", true);
    combatNpcManager.saveData(offlinePlayer);
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) InventoryManager(combatlogx.expansion.compatibility.citizens.manager.InventoryManager) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) OfflinePlayer(org.bukkit.OfflinePlayer) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) DespawnReason(net.citizensnpcs.api.event.DespawnReason) CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 5 with CombatNpcManager

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

the class ListenerDeath method checkForDeathMessages.

private void checkForDeathMessages(NPCDeathEvent e, CombatNPC npc) {
    OfflinePlayer offlineOwner = npc.getOfflineOwner();
    EntityDeathEvent entityDeathEvent = e.getEvent();
    if (!(entityDeathEvent instanceof PlayerDeathEvent))
        return;
    PlayerDeathEvent playerDeathEvent = (PlayerDeathEvent) entityDeathEvent;
    String message = playerDeathEvent.getDeathMessage();
    CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
    YamlConfiguration data = combatNpcManager.getData(offlineOwner);
    data.set("citizens-compatibility.last-death-message", message);
    combatNpcManager.saveData(offlineOwner);
}
Also used : EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) OfflinePlayer(org.bukkit.OfflinePlayer) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager)

Aggregations

CombatNpcManager (combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager)11 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)8 CombatNPC (combatlogx.expansion.compatibility.citizens.object.CombatNPC)6 EventHandler (org.bukkit.event.EventHandler)6 NPC (net.citizensnpcs.api.npc.NPC)5 OfflinePlayer (org.bukkit.OfflinePlayer)5 Player (org.bukkit.entity.Player)3 InventoryManager (combatlogx.expansion.compatibility.citizens.manager.InventoryManager)2 Location (org.bukkit.Location)2 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)2 BukkitScheduler (org.bukkit.scheduler.BukkitScheduler)2 ConfigurationManager (com.github.sirblobman.api.configuration.ConfigurationManager)1 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)1 DespawnReason (net.citizensnpcs.api.event.DespawnReason)1 NPCRegistry (net.citizensnpcs.api.npc.NPCRegistry)1 LivingEntity (org.bukkit.entity.LivingEntity)1 EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)1 PlayerDeathEvent (org.bukkit.event.entity.PlayerDeathEvent)1 PlayerInventory (org.bukkit.inventory.PlayerInventory)1