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();
}
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);
}
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();
}
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);
}
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);
}
Aggregations