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