Search in sources :

Example 1 with CombatNPC

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

use of combatlogx.expansion.compatibility.citizens.object.CombatNPC 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 3 with CombatNPC

use of combatlogx.expansion.compatibility.citizens.object.CombatNPC 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 4 with CombatNPC

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

the class ListenerJoin method onJoin.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onJoin(PlayerJoinEvent e) {
    printDebug("Detected PlayerJoinEvent...");
    Player player = e.getPlayer();
    printDebug("Player: " + player.getName());
    printDebug("Disabled item pickup for player.");
    player.setCanPickupItems(false);
    CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
    CombatNPC combatNPC = combatNpcManager.getNPC(player);
    if (combatNPC != null) {
        printDebug("Combat NPC exists for player, removing.");
        combatNpcManager.remove(combatNPC);
    }
    BukkitScheduler scheduler = Bukkit.getScheduler();
    Runnable task = () -> {
        printDebug("Scheduled punishment running.");
        punish(player);
        printDebug("Finished punishment, allowing item pickup.");
        player.setCanPickupItems(true);
    };
    JavaPlugin plugin = getJavaPlugin();
    scheduler.scheduleSyncDelayedTask(plugin, task, 1L);
    printDebug("Scheduled punishment for one tick after login.");
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) CombatNPC(combatlogx.expansion.compatibility.citizens.object.CombatNPC) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager) EventHandler(org.bukkit.event.EventHandler)

Example 5 with CombatNPC

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

the class ListenerResurrect method onResurrect.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onResurrect(EntityResurrectEvent e) {
    YamlConfiguration configuration = getConfiguration();
    if (!configuration.getBoolean("prevent-resurrect"))
        return;
    LivingEntity entity = e.getEntity();
    NPCRegistry npcRegistry = CitizensAPI.getNPCRegistry();
    NPC npc = npcRegistry.getNPC(entity);
    if (npc == null)
        return;
    CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
    CombatNPC combatNPC = combatNpcManager.getCombatNPC(npc);
    if (combatNPC == null)
        return;
    e.setCancelled(true);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) 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) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) CombatNpcManager(combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

CombatNPC (combatlogx.expansion.compatibility.citizens.object.CombatNPC)8 NPC (net.citizensnpcs.api.npc.NPC)7 CombatNpcManager (combatlogx.expansion.compatibility.citizens.manager.CombatNpcManager)6 OfflinePlayer (org.bukkit.OfflinePlayer)5 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)5 EventHandler (org.bukkit.event.EventHandler)5 NPCRegistry (net.citizensnpcs.api.npc.NPCRegistry)2 Location (org.bukkit.Location)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Player (org.bukkit.entity.Player)2 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)2 BukkitScheduler (org.bukkit.scheduler.BukkitScheduler)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 CitizensExpansion (combatlogx.expansion.compatibility.citizens.CitizensExpansion)1 InventoryManager (combatlogx.expansion.compatibility.citizens.manager.InventoryManager)1 UUID (java.util.UUID)1 DespawnReason (net.citizensnpcs.api.event.DespawnReason)1