added a better detection system
This commit is contained in:
parent
23c2c95a31
commit
e25674f4f3
@ -1,6 +1,7 @@
|
|||||||
package xyz.louisvallat.sweetdreams;
|
package xyz.louisvallat.sweetdreams;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -9,8 +10,6 @@ import org.bukkit.event.player.PlayerBedEnterEvent;
|
|||||||
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
|
|
||||||
public final class SweetDreams extends JavaPlugin implements Listener {
|
public final class SweetDreams extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -27,16 +26,25 @@ public final class SweetDreams extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onSleepEvent(PlayerBedEnterEvent event) {
|
public void onSleep(PlayerBedEnterEvent event) {
|
||||||
Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
player.sendMessage("You are sleeping");
|
final World world = player.getWorld();
|
||||||
getServer().broadcastMessage(player.getName() + " is sleeping!");
|
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)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onWakeEvent(PlayerBedLeaveEvent event) {
|
public void onWake(PlayerBedLeaveEvent event) {
|
||||||
Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
player.sendMessage("You are awoken");
|
|
||||||
getServer().broadcastMessage(player.getName() + " has awoken!");
|
player.sendMessage("Wake up!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user