ignoring player sleeping when going to bed, and not ignoring it anymore when they wake up

This commit is contained in:
Louis Vallat 2020-06-14 14:27:07 +02:00
parent 52a4fa93bb
commit 0c6261973c

View File

@ -36,6 +36,7 @@ public final class SweetDreams extends JavaPlugin implements Listener {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final World world = player.getWorld(); final World world = player.getWorld();
if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) { if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) {
player.setSleepingIgnored(true);
sleepingSchedulers.put(player, this.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> { sleepingSchedulers.put(player, this.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
if (world.isThundering()) world.setThundering(false); if (world.isThundering()) world.setThundering(false);
else world.setTime(1000); else world.setTime(1000);
@ -48,5 +49,6 @@ public final class SweetDreams extends JavaPlugin implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onWake(PlayerBedLeaveEvent event) { public void onWake(PlayerBedLeaveEvent event) {
this.getServer().getScheduler().cancelTask(sleepingSchedulers.get(event.getPlayer())); this.getServer().getScheduler().cancelTask(sleepingSchedulers.get(event.getPlayer()));
event.getPlayer().setSleepingIgnored(false);
} }
} }