events.listen('entity.death', function (event) {
    if(event.entity.isPlayer()) {
      console.info('Player Died...');
      event.server.scheduleInTicks(5, event, schedule => {
        var players = schedule.data.server.players.filter( (entity) => {
          return entity.profile.id == schedule.data.entity.profile.id;
        });
        if(!players.isEmpty()){
          if(players.getFirst().isAlive()){
            console.info('Player Is alive. Running Commands.');
            schedule.data.server.runCommandSilent('effect give ' + players.getFirst().name + ' minecraft:resistance 30 4 true');
            schedule.data.server.runCommandSilent('effect give ' + players.getFirst().name + ' quark:resilience 30 5 true');
			schedule.data.server.runCommandSilent('effect give ' + players.getFirst().name + ' minecraft:invisibility 30 5 true');
			schedule.data.server.runCommandSilent('tellraw ' + players.getFirst().name + ' ["",{"text":"You have been granted ","color":"yellow"},{"text":"Death Protection","color":"dark_red"},{"text":" for a short time!","color":"yellow"}]');
            console.info('Player Has been given effects.');
          }else{
            console.info('Player was not alive to receive effects. Rescheudling...');
            schedule.reschedule();
          }
        }else{
          console.info('Player UUID could not be found in player list. Rescheduling...');
          console.info("UUID ("+schedule.data.entity.profile.id+")");
          schedule.reschedule();
        }
      });
    }
});



