use of io.xol.chunkstories.api.GameContext in project chunkstories-core by Hugobros3.
the class EntityComponentHealth method handleDeath.
private void handleDeath() {
EntityDeathEvent entityDeathEvent = new EntityDeathEvent(entityLiving);
entity.getWorld().getGameLogic().getPluginsManager().fireEvent(entityDeathEvent);
// Handles cases of controlled player death
if (entity instanceof EntityControllable) {
Controller controller = ((EntityControllable) entity).getControllerComponent().getController();
if (controller != null) {
controller.setControlledEntity(null);
// Serverside stuff
if (controller instanceof Player && entity.getWorld() instanceof WorldMaster) {
Player player = (Player) controller;
PlayerDeathEvent event = new PlayerDeathEvent(player);
entity.getWorld().getGameLogic().getPluginsManager().fireEvent(event);
// When a player dies, delete his save as well
File playerSavefile = new File(((WorldMaster) entity.getWorld()).getFolderPath() + "/players/" + player.getName().toLowerCase() + ".csf");
if (playerSavefile.exists()) {
// Player save file is deleted upon death
playerSavefile.delete();
}
if (event.getDeathMessage() != null) {
GameContext gc = player.getContext();
if (gc instanceof ServerInterface)
((ServerInterface) gc).broadcastMessage(event.getDeathMessage());
}
} else {
// Weird, undefined cases ( controller wasn't a player, maybe some weird mod logic here
}
}
}
}
Aggregations