use of combatlogx.expansion.compatibility.citizens.manager.InventoryManager 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.InventoryManager in project CombatLogX by SirBlobman.
the class ListenerJoin method punish.
private void punish(Player player) {
if (player == null || player.hasMetadata("NPC")) {
printDebug("Could not punish player, they are null or an NPC.");
return;
}
CombatNpcManager combatNpcManager = this.expansion.getCombatNpcManager();
YamlConfiguration playerData = combatNpcManager.getData(player);
if (!playerData.getBoolean("citizens-compatibility.punish")) {
printDebug("Punishment set to false in player data.");
return;
}
playerData.set("citizens-compatibility.punish", false);
combatNpcManager.saveData(player);
printDebug("Setting punish to false in player data to prevent double punishment.");
YamlConfiguration configuration = getConfiguration();
if (configuration.getBoolean("store-location")) {
Location location = combatNpcManager.loadLocation(player);
if (location != null) {
printDebug("Teleporting player to last known location for NPC.");
player.teleport(location, TeleportCause.PLUGIN);
}
playerData.set("citizens-compatibility.location", null);
}
if (configuration.getBoolean("store-inventory")) {
printDebug("Clearing player inventory.");
PlayerInventory playerInventory = player.getInventory();
playerInventory.clear();
}
double health = combatNpcManager.loadHealth(player);
setHealth(player, health);
printDebug("Set player health to " + health);
if (health <= 0.0D) {
printDebug("Player died or health was invalid, removing stored inventory to prevent duplication.");
playerData.set("citizens-compatibility.inventory", null);
playerData.set("citizens-compatibility.armor", null);
}
if (configuration.getBoolean("store-inventory")) {
printDebug("Restoring player inventory if possible.");
InventoryManager inventoryManager = expansion.getInventoryManager();
inventoryManager.restoreInventory(player);
}
}
Aggregations