added a stilldead flag

This commit is contained in:
Bryson Steck 2021-06-15 20:47:32 -06:00
parent 5cc1fe69ba
commit 9431767c3b
4 changed files with 18 additions and 12 deletions

View file

@ -15,12 +15,14 @@ import org.bukkit.scheduler.BukkitRunnable;
public class PlayerListener implements Listener { public class PlayerListener implements Listener {
boolean stillDead;
Location spawn; Location spawn;
@EventHandler @EventHandler
public void onDeath(PlayerDeathEvent e) { public void onDeath(PlayerDeathEvent e) {
System.out.println("Resurrection: A player has died!"); System.out.println("Resurrection: A player has died!");
Player p = e.getEntity(); Player p = e.getEntity();
stillDead = true;
// //
// TimeCheck death = new TimeCheck(timeOfDeath); // TimeCheck death = new TimeCheck(timeOfDeath);
// TimeCheck resurrect = new TimeCheck((timeOfDeath + 86400000) - timeOfDeath); // TimeCheck resurrect = new TimeCheck((timeOfDeath + 86400000) - timeOfDeath);
@ -34,6 +36,7 @@ public class PlayerListener implements Listener {
// save death information to player file // save death information to player file
@Override @Override
public void run() { public void run() {
stillDead = false;
for (PotionEffect effect : p.getActivePotionEffects()) for (PotionEffect effect : p.getActivePotionEffects())
p.removePotionEffect(effect.getType()); p.removePotionEffect(effect.getType());
p.setGameMode(GameMode.SURVIVAL); p.setGameMode(GameMode.SURVIVAL);
@ -47,20 +50,23 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPlayerRespawn(PlayerRespawnEvent e) { public void onPlayerRespawn(PlayerRespawnEvent e) {
final Player p = e.getPlayer(); if (stillDead) {
p.setGameMode(GameMode.SPECTATOR); final Player p = e.getPlayer();
new BukkitRunnable() { p.setGameMode(GameMode.SPECTATOR);
@Override p.sendTitle("You have died!", "You must wait 24 hours before you can respawn.");
public void run() { new BukkitRunnable() {
spawn = p.getLocation(); @Override
public void run() {
spawn = p.getLocation();
// PotionEffect invisibility = new PotionEffect(PotionEffectType.INVISIBILITY, 1728000, 10, false); // PotionEffect invisibility = new PotionEffect(PotionEffectType.INVISIBILITY, 1728000, 10, false);
PotionEffect blindness = new PotionEffect(PotionEffectType.BLINDNESS, 100, 10, false); PotionEffect blindness = new PotionEffect(PotionEffectType.BLINDNESS, 100, 10, false);
PotionEffect slowness = new PotionEffect(PotionEffectType.SLOW, 100, 10, false); PotionEffect slowness = new PotionEffect(PotionEffectType.SLOW, 100, 10, false);
// invisibility.apply(p); // invisibility.apply(p);
blindness.apply(p); blindness.apply(p);
slowness.apply(p); slowness.apply(p);
} }
}.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), 1); }.runTaskLater(JavaPlugin.getProvidingPlugin(Resurrection.class), 1);
}
} }
@EventHandler @EventHandler