Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Remove stream and double iteration in enough deep sleeping player check
Browse files Browse the repository at this point in the history
  • Loading branch information
404Setup committed Oct 19, 2024
1 parent e3d73e3 commit db04bb1
Show file tree
Hide file tree
Showing 78 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 404Setup <[email protected]>
Date: Sat, 19 Oct 2024 19:29:06 +0800
Subject: [PATCH] Leaf: Remove stream and double iteration in enough deep
sleeping player check


diff --git a/src/main/java/net/minecraft/server/players/SleepStatus.java b/src/main/java/net/minecraft/server/players/SleepStatus.java
index caa8a69bde0c212c36dd990a67836ac2f95548c0..5ae435dcc078a5b9af90f01fa70f1a9d6f34e2be 100644
--- a/src/main/java/net/minecraft/server/players/SleepStatus.java
+++ b/src/main/java/net/minecraft/server/players/SleepStatus.java
@@ -19,10 +19,24 @@ public class SleepStatus {

public boolean areEnoughDeepSleeping(int percentage, List<ServerPlayer> players) {
// CraftBukkit start
- int j = (int) players.stream().filter((eh) -> { return eh.isSleepingLongEnough() || eh.fauxSleeping || (eh.level().purpurConfig.idleTimeoutCountAsSleeping && eh.isAfk()); }).count(); // Purpur
- boolean anyDeepSleep = players.stream().anyMatch(Player::isSleepingLongEnough);
+ // Leaf start - Remove stream and double iteration in enough deep sleeping player check
+ int count = 0;
+ boolean anyPlayerSleeping = false;

- return anyDeepSleep && j >= this.sleepersNeeded(percentage);
+ for (ServerPlayer player : players) {
+ final boolean isSleepingLongEnough = player.isSleepingLongEnough();
+
+ if (isSleepingLongEnough) {
+ anyPlayerSleeping = true;
+ }
+
+ if (isSleepingLongEnough || player.fauxSleeping || (player.level().purpurConfig.idleTimeoutCountAsSleeping && player.isAfk())) { // Purpur
+ count++;
+ }
+ }
+
+ return anyPlayerSleeping && count >= this.sleepersNeeded(percentage);
+ // Leaf end - Remove stream and double iteration in enough deep sleeping player check
// CraftBukkit end
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Subject: [PATCH] Paper PR Update Velocity natives
Source in https://github.com/PaperMC/Paper/pull/11347

diff --git a/build.gradle.kts b/build.gradle.kts
index be36af8d51818204c6f4dd4d9ec4665eb9ba7f5c..1553eb2b53eaa7155330fac13603a11eb1b33859 100644
index dfc011af50c8bca01bf0effbb8a72926628b26a4..9baaa79648a0a829726ee89a5712342fb7a4dfad 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -41,7 +41,7 @@ dependencies {
Expand Down

0 comments on commit db04bb1

Please sign in to comment.