File size: 1,538 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package net.minecraft.server.players;

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 boolean areEnoughSleeping(int p_144003_) {
        return this.sleepingPlayers >= this.sleepersNeeded(p_144003_);
    }

    public boolean areEnoughDeepSleeping(int p_144005_, List<ServerPlayer> p_144006_) {
        int i = (int)p_144006_.stream().filter(Player::isSleepingLongEnough).count();
        return i >= this.sleepersNeeded(p_144005_);
    }

    public int sleepersNeeded(int p_144011_) {
        return Math.max(1, Mth.ceil((float)(this.activePlayers * p_144011_) / 100.0F));
    }

    public void removeAllSleepers() {
        this.sleepingPlayers = 0;
    }

    public int amountSleeping() {
        return this.sleepingPlayers;
    }

    public boolean update(List<ServerPlayer> p_144008_) {
        int i = this.activePlayers;
        int j = this.sleepingPlayers;
        this.activePlayers = 0;
        this.sleepingPlayers = 0;

        for (ServerPlayer serverplayer : p_144008_) {
            if (!serverplayer.isSpectator()) {
                this.activePlayers++;
                if (serverplayer.isSleeping()) {
                    this.sleepingPlayers++;
                }
            }
        }

        return (j > 0 || this.sleepingPlayers > 0) && (i != this.activePlayers || j != this.sleepingPlayers);
    }
}