Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playersSleepingPercentage GameRule #2158

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/cn/nukkit/level/GameRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/level/GameRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/cn/nukkit/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -974,15 +974,16 @@ public void checkSleep() {
return;
}

boolean resetTime = true;
int playerCount = 0;
int sleepingPlayerCount = 0;
for (Player p : this.getPlayers().values()) {
playerCount++;
if (!p.isSleeping()) {
lt-name marked this conversation as resolved.
Show resolved Hide resolved
resetTime = false;
break;
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) {
Expand Down