Files
Purpur/patches/server/0078-Add-sleep-options.patch
William Blake Galbreath d085a5b222 Updated Upstream (Paper)
Upstream has released updates that appears to apply and compile correctly

Paper Changes:
cb15cfa4 Improve Async Login so pending connections dont get exposed
f275e9cb Optimize Hoppers - Major Boost - Got2GoFast!
0106485c Improvements to watchdog changes
65934b1f Fix build for last commit. 5am commits are great
3f436029 Don't process watchdog until server has fully started and ticked.
938bd972 Don't fire BlockFade on worldgen threads - Fixes #3208
509a828e Fix loading spawn chunks when async chunks is off
8a91bfd2 Improvements to async login
bf698865 Revert "Re-track players that dismount from other players"
82b98418 Fix some issues with async login as well another source of sync loads
aa241d2b Allow multiple callbacks to schedule for Callback Executor
a2064a41 Add PlayerAttackEntityCooldownResetEvent This event is called when processing a player's attack on an entity right before their attack strength cd is reset, there are no existing events that fire within this period of time so it was impossible to capture the players attack strength via API prior to this commit.
f48d4299 Allow sleeping players to float
eeb2f67d Fix Bed respawn deviating too far from vanilla (#3195)
68a7b9fe Move player to spawn point if spawn in unloaded world
2020-04-24 08:22:02 -05:00

80 lines
3.8 KiB
Diff

From 13de5fcae50a95059fdc72e167bdf5e7d53202b9 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Sat, 30 Nov 2019 03:30:17 -0600
Subject: [PATCH] Add sleep options
---
.../net/minecraft/server/EntityHuman.java | 19 +++++++++++++++++--
.../net/pl3x/purpur/PurpurWorldConfig.java | 4 ++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 5ac3c464..ed0a559f 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -143,6 +143,21 @@ public abstract class EntityHuman extends EntityLiving {
this.datawatcher.register(EntityHuman.bt, new NBTTagCompound());
}
+ // Purpur start
+ private javax.script.ScriptEngine scriptEngine = new javax.script.ScriptEngineManager().getEngineByName("rhino");
+
+ private boolean unableToSleepRightNow() {
+ if (world.purpurConfig.playerSleepOnlyWithCondition) {
+ try {
+ scriptEngine.eval("time = " + world.getDayTime());
+ return !(Boolean) scriptEngine.eval(world.purpurConfig.playerSleepCondition);
+ } catch (Exception ignore) {
+ }
+ }
+ return world.isDay();
+ }
+ // Purpur end
+
@Override
public void tick() {
this.noclip = this.isSpectator();
@@ -160,7 +175,7 @@ public abstract class EntityHuman extends EntityLiving {
this.sleepTicks = 100;
}
- if (!this.world.isClientSide && this.world.isDay()) {
+ if (!this.world.isClientSide && unableToSleepRightNow()) { // Purpur
this.wakeup(false, true);
}
} else if (this.sleepTicks > 0) {
@@ -1338,7 +1353,7 @@ public abstract class EntityHuman extends EntityLiving {
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
}
- if (this.world.isDay()) {
+ if (unableToSleepRightNow()) { // Purpur
this.setRespawnPosition(blockposition, false, true);
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW);
}
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index 71872a3f..44786e1f 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -150,6 +150,8 @@ public class PurpurWorldConfig {
public boolean disableDropsOnCrammingDeath = false;
public boolean fixClimbingBypassingCrammingRule = false;
public boolean milkCuresBadOmen = true;
+ public boolean playerSleepOnlyWithCondition = false;
+ public String playerSleepCondition = "time >= 12541 && time <= 23458";
public boolean useBetterMending = false;
private void gameplayMechanicsSettings() {
boatEjectPlayersOnLand = getBoolean("gameplay-mechanics.boat.eject-players-on-land", boatEjectPlayersOnLand);
@@ -174,6 +176,8 @@ public class PurpurWorldConfig {
disableDropsOnCrammingDeath = getBoolean("gameplay-mechanics.disable-drops-on-cramming-death", disableDropsOnCrammingDeath);
fixClimbingBypassingCrammingRule = getBoolean("gameplay-mechanics.fix-climbing-bypassing-cramming-rule", fixClimbingBypassingCrammingRule);
milkCuresBadOmen = getBoolean("gameplay-mechanics.milk-cures-bad-omen", milkCuresBadOmen);
+ playerSleepOnlyWithCondition = getBoolean("gameplay-mechanics.player.sleep.only-with-condition", playerSleepOnlyWithCondition);
+ playerSleepCondition = getString("gameplay-mechanics.player.sleep.condition", playerSleepCondition);
useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
}
--
2.24.0