diff --git a/src/main/java/cn/nukkit/level/GameRule.java b/src/main/java/cn/nukkit/level/GameRule.java index f1623b885ea..aeabe6d4836 100644 --- a/src/main/java/cn/nukkit/level/GameRule.java +++ b/src/main/java/cn/nukkit/level/GameRule.java @@ -31,7 +31,8 @@ public enum GameRule { SHOW_DEATH_MESSAGES("showDeathMessages"), SPAWN_RADIUS("spawnRadius"), TNT_EXPLODES("tntExplodes"), - SHOW_TAGS("showTags"); + SHOW_TAGS("showTags"), + PLAYERS_SLEEPING_PERCENTAGE("playersSleepingPercentage"); private final String name; diff --git a/src/main/java/cn/nukkit/level/GameRules.java b/src/main/java/cn/nukkit/level/GameRules.java index 3e09c11bea8..21036427862 100644 --- a/src/main/java/cn/nukkit/level/GameRules.java +++ b/src/main/java/cn/nukkit/level/GameRules.java @@ -52,6 +52,7 @@ public static GameRules getDefault() { gameRules.gameRules.put(SPAWN_RADIUS, new Value<>(Type.INTEGER, 5)); gameRules.gameRules.put(TNT_EXPLODES, new Value<>(Type.BOOLEAN, true)); gameRules.gameRules.put(SHOW_TAGS, new Value<>(Type.BOOLEAN, true)); + gameRules.gameRules.put(PLAYERS_SLEEPING_PERCENTAGE, new Value<>(Type.INTEGER, 100)); return gameRules; } diff --git a/src/main/java/cn/nukkit/level/Level.java b/src/main/java/cn/nukkit/level/Level.java index aca3e1e94de..cf9511cdeb4 100644 --- a/src/main/java/cn/nukkit/level/Level.java +++ b/src/main/java/cn/nukkit/level/Level.java @@ -974,15 +974,16 @@ public void checkSleep() { return; } - boolean resetTime = true; + int playerCount = 0; + int sleepingPlayerCount = 0; for (Player p : this.getPlayers().values()) { - if (!p.isSleeping()) { - resetTime = false; - break; + playerCount++; + if (p.isSleeping()) { + sleepingPlayerCount++; } } - if (resetTime) { + if (playerCount > 0 && sleepingPlayerCount / playerCount * 100 >= this.gameRules.getInteger(GameRule.PLAYERS_SLEEPING_PERCENTAGE)) { int time = this.getTime() % Level.TIME_FULL; if (time >= Level.TIME_NIGHT && time < Level.TIME_SUNRISE) {