added a better detection system

This commit is contained in:
Louis Vallat 2020-06-13 21:32:22 +02:00
parent 23c2c95a31
commit e25674f4f3

View File

@ -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!");
}
}