From e25674f4f39ed7b6425cbc1517a0ec9356fa54d6 Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Sat, 13 Jun 2020 21:32:22 +0200 Subject: [PATCH] added a better detection system --- .../louisvallat/sweetdreams/SweetDreams.java | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/xyz/louisvallat/sweetdreams/SweetDreams.java b/src/main/java/xyz/louisvallat/sweetdreams/SweetDreams.java index d8806c4..0bd1330 100644 --- a/src/main/java/xyz/louisvallat/sweetdreams/SweetDreams.java +++ b/src/main/java/xyz/louisvallat/sweetdreams/SweetDreams.java @@ -1,6 +1,7 @@ package xyz.louisvallat.sweetdreams; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -9,8 +10,6 @@ import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerBedLeaveEvent; import org.bukkit.plugin.java.JavaPlugin; -import javax.swing.*; - public final class SweetDreams extends JavaPlugin implements Listener { @Override @@ -27,16 +26,25 @@ public final class SweetDreams extends JavaPlugin implements Listener { } @EventHandler(priority = EventPriority.HIGHEST) - public void onSleepEvent(PlayerBedEnterEvent event) { - Player player = event.getPlayer(); - player.sendMessage("You are sleeping"); - getServer().broadcastMessage(player.getName() + " is sleeping!"); + public void onSleep(PlayerBedEnterEvent event) { + final Player player = event.getPlayer(); + final World world = player.getWorld(); + if (world.isThundering() || + (world.getTime() >= 12541 && world.getTime() <= 23458)) // https://minecraft.gamepedia.com/Bed#Sleeping + { + player.sendMessage("You're sleeping."); + this.getServer().getScheduler().scheduleSyncDelayedTask(this, () -> { + world.setTime(1000); + player.sendMessage("You skipped the night for everyone."); + } + , (20)); + } } @EventHandler(priority = EventPriority.LOWEST) - public void onWakeEvent(PlayerBedLeaveEvent event) { - Player player = event.getPlayer(); - player.sendMessage("You are awoken"); - getServer().broadcastMessage(player.getName() + " has awoken!"); + public void onWake(PlayerBedLeaveEvent event) { + final Player player = event.getPlayer(); + + player.sendMessage("Wake up!"); } }