Skip to content

Commit

Permalink
first implement of single player sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
owenh28 committed Apr 29, 2022
1 parent 7993a40 commit 2264d9e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
25 changes: 1 addition & 24 deletions src/main/java/onh/plugins/Plugins.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/onh/plugins/singlesleep.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 2264d9e

Please sign in to comment.