blob: 3c9f6b9baf1e988f73613f5886b982b6240e4d5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
--- a/net/minecraft/server/players/SleepStatus.java
+++ b/net/minecraft/server/players/SleepStatus.java
@@ -1,25 +1,33 @@
package net.minecraft.server.players;
+import java.util.Iterator;
import java.util.List;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
public class SleepStatus {
+
private int activePlayers;
private int sleepingPlayers;
+ public SleepStatus() {}
+
public boolean areEnoughSleeping(int requiredSleepPercentage) {
return this.sleepingPlayers >= this.sleepersNeeded(requiredSleepPercentage);
}
public boolean areEnoughDeepSleeping(int requiredSleepPercentage, List<ServerPlayer> sleepingPlayers) {
- int i = (int)sleepingPlayers.stream().filter(Player::isSleepingLongEnough).count();
- return i >= this.sleepersNeeded(requiredSleepPercentage);
+ // CraftBukkit start
+ int j = (int) sleepingPlayers.stream().filter((eh) -> { return eh.isSleepingLongEnough() || eh.fauxSleeping; }).count();
+ boolean anyDeepSleep = sleepingPlayers.stream().anyMatch(Player::isSleepingLongEnough);
+
+ return anyDeepSleep && j >= this.sleepersNeeded(requiredSleepPercentage);
+ // CraftBukkit end
}
public int sleepersNeeded(int requiredSleepPercentage) {
- return Math.max(1, Mth.ceil((float)(this.activePlayers * requiredSleepPercentage) / 100.0F));
+ return Math.max(1, Mth.ceil((float) (this.activePlayers * requiredSleepPercentage) / 100.0F));
}
public void removeAllSleepers() {
@@ -32,19 +40,29 @@
public boolean update(List<ServerPlayer> players) {
int i = this.activePlayers;
- int i1 = this.sleepingPlayers;
+ int j = this.sleepingPlayers;
+
this.activePlayers = 0;
this.sleepingPlayers = 0;
+ Iterator iterator = players.iterator();
+ boolean anySleep = false; // CraftBukkit
- for (ServerPlayer serverPlayer : players) {
- if (!serverPlayer.isSpectator()) {
- this.activePlayers++;
- if (serverPlayer.isSleeping()) {
- this.sleepingPlayers++;
+ while (iterator.hasNext()) {
+ ServerPlayer entityplayer = (ServerPlayer) iterator.next();
+
+ if (!entityplayer.isSpectator()) {
+ ++this.activePlayers;
+ if (entityplayer.isSleeping() || entityplayer.fauxSleeping) { // CraftBukkit
+ ++this.sleepingPlayers;
}
+ // CraftBukkit start
+ if (entityplayer.isSleeping()) {
+ anySleep = true;
+ }
+ // CraftBukkit end
}
}
- return (i1 > 0 || this.sleepingPlayers > 0) && (i != this.activePlayers || i1 != this.sleepingPlayers);
+ return anySleep && (j > 0 || this.sleepingPlayers > 0) && (i != this.activePlayers || j != this.sleepingPlayers); // CraftBukkit
}
}
|