From 2264d9e87b48893768f428f312a5aaac7888eab2 Mon Sep 17 00:00:00 2001 From: owenh Date: Fri, 29 Apr 2022 14:44:57 -0600 Subject: [PATCH] first implement of single player sleep --- src/main/java/onh/plugins/Plugins.java | 25 +--------------------- src/main/java/onh/plugins/singlesleep.java | 25 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 src/main/java/onh/plugins/singlesleep.java diff --git a/src/main/java/onh/plugins/Plugins.java b/src/main/java/onh/plugins/Plugins.java index 4289f53..e30738c 100644 --- a/src/main/java/onh/plugins/Plugins.java +++ b/src/main/java/onh/plugins/Plugins.java @@ -1,16 +1,10 @@ package onh.plugins; -import io.papermc.paper.event.player.PlayerDeepSleepEvent; import onh.plugins.commands.beacon; import onh.plugins.commands.beaconother; import onh.plugins.commands.bitches; import onh.plugins.commands.info; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; - -import java.util.EventListener; import java.util.Objects; public final class Plugins extends JavaPlugin { @@ -25,24 +19,7 @@ public void onEnable() { Objects.requireNonNull(this.getCommand("beacon")).setExecutor(new beacon()); Objects.requireNonNull(this.getCommand("beaconother")).setExecutor(new beaconother()); Objects.requireNonNull(this.getCommand("bitches")).setExecutor(new bitches()); - - - - //Single player sleep? -// while(true) { -// -// Server srv = getServer(); -// -// Player[] onlp = srv.getOnlinePlayers().toArray(new Player[0]); -// for(int i = 0; i < srv.getOnlinePlayers().size(); i++){ -// if(onlp[i].isSleeping()){ -// World wld = onlp[i].getWorld(); -// wld.setTime(6000); -// } -// } -// } - - + getServer().getPluginManager().registerEvents(new singlesleep(), this); } @Override diff --git a/src/main/java/onh/plugins/singlesleep.java b/src/main/java/onh/plugins/singlesleep.java new file mode 100644 index 0000000..eea9069 --- /dev/null +++ b/src/main/java/onh/plugins/singlesleep.java @@ -0,0 +1,25 @@ +package onh.plugins; + +import io.papermc.paper.event.player.PlayerDeepSleepEvent; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class singlesleep implements Listener { + @EventHandler + public void onSleep(PlayerDeepSleepEvent event){ + Player sleepy = event.getPlayer(); + Server srv = sleepy.getServer(); + World world = sleepy.getWorld(); + Player[] onlinePlayers = world.getPlayers().toArray(new Player[0]); + if(sleepy.isSleeping()) { + for (Player onlinePlayer : onlinePlayers) { + onlinePlayer.sendMessage(sleepy.getName() + " is sleeping, changing to day"); + } + world.setTime(6000); + world.setClearWeatherDuration(400); + } + } +}