mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-21 10:27:44 +01:00
Simplify the sleep options
This commit is contained in:
@@ -427,18 +427,12 @@ limit-villager-iron-golem-spawns
|
|||||||
|
|
||||||
sleep
|
sleep
|
||||||
~~~~~
|
~~~~~
|
||||||
* only-at-night
|
* only-with-condition
|
||||||
- **default:** false
|
- **default:** false
|
||||||
- **description:** Make players only sleep at night. Night times specified below. Rest of the sleep options are ignored if this is false
|
- **description:** Make players only sleep when the following time condition is true
|
||||||
* night-start
|
* condition
|
||||||
- **default:** 12541
|
- **default:** "time >= 12541 && time <= 23458"
|
||||||
- **description:** The starting time of night (in ticks) when a player can first sleep
|
- **description:** The time condition for player to be able to sleep
|
||||||
* night-end
|
|
||||||
- **default:** 23458
|
|
||||||
- **description:** The ending time of night (in ticks) when a player cannot sleep
|
|
||||||
* invert-condition
|
|
||||||
- **default:** false
|
|
||||||
- **description:** Invert the result of the time condition. Time condition is `!(time < start && time > end)`. Inverting it removes the `!`
|
|
||||||
|
|
||||||
idle-timeout
|
idle-timeout
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -1,27 +1,51 @@
|
|||||||
From 7774dfe2612bbb0fb48b15bed689a11afbb11b89 Mon Sep 17 00:00:00 2001
|
From b3254cd0c8a19f1773a50e43315a75fdb36a4ec0 Mon Sep 17 00:00:00 2001
|
||||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||||
Date: Sat, 30 Nov 2019 03:30:17 -0600
|
Date: Sat, 30 Nov 2019 03:30:17 -0600
|
||||||
Subject: [PATCH] Add sleep options
|
Subject: [PATCH] Add sleep options
|
||||||
|
|
||||||
---
|
---
|
||||||
.../java/net/minecraft/server/EntityHuman.java | 15 +++++++++++++--
|
.../net/minecraft/server/EntityHuman.java | 25 ++++++++++++++++---
|
||||||
.../java/net/pl3x/purpur/PurpurWorldConfig.java | 11 +++++++++++
|
.../net/pl3x/purpur/PurpurWorldConfig.java | 7 ++++++
|
||||||
2 files changed, 24 insertions(+), 2 deletions(-)
|
2 files changed, 29 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
||||||
index 3610611299..2bb4ae2265 100644
|
index 3610611299..26e1b8e2dc 100644
|
||||||
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
||||||
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
||||||
@@ -143,6 +143,17 @@ public abstract class EntityHuman extends EntityLiving {
|
@@ -14,6 +14,11 @@ import java.util.OptionalInt;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
+// Purpur start
|
||||||
|
+import javax.script.ScriptEngine;
|
||||||
|
+import javax.script.ScriptEngineManager;
|
||||||
|
+import javax.script.ScriptException;
|
||||||
|
+// Purpur end
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||||
|
@@ -25,7 +30,6 @@ import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||||
|
import org.bukkit.event.player.PlayerBedLeaveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||||
|
-import org.bukkit.util.Vector;
|
||||||
|
// CraftBukkit end
|
||||||
|
|
||||||
|
public abstract class EntityHuman extends EntityLiving {
|
||||||
|
@@ -143,6 +147,21 @@ public abstract class EntityHuman extends EntityLiving {
|
||||||
this.datawatcher.register(EntityHuman.bw, new NBTTagCompound());
|
this.datawatcher.register(EntityHuman.bw, new NBTTagCompound());
|
||||||
}
|
}
|
||||||
|
|
||||||
+ // Purpur start
|
+ // Purpur start
|
||||||
|
+ private ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||||
|
+
|
||||||
+ private boolean unableToSleepRightNow() {
|
+ private boolean unableToSleepRightNow() {
|
||||||
+ if (world.purpurConfig.sleepOnlyAtNight) {
|
+ if (world.purpurConfig.sleepOnlyWithCondition) {
|
||||||
+ long time = world.getDayTime();
|
+ try {
|
||||||
+ boolean wakeUp = time < world.purpurConfig.sleepStart && time > world.purpurConfig.sleepEnd;
|
+ scriptEngine.eval("time = " + world.getDayTime());
|
||||||
+ return world.purpurConfig.sleepInvertCondition == wakeUp;
|
+ return !(Boolean) scriptEngine.eval(world.purpurConfig.sleepCondition);
|
||||||
|
+ } catch (ScriptException ignore) {
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ return world.isDayTime();
|
+ return world.isDayTime();
|
||||||
+ }
|
+ }
|
||||||
@@ -30,7 +54,7 @@ index 3610611299..2bb4ae2265 100644
|
|||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
this.noclip = this.isSpectator();
|
this.noclip = this.isSpectator();
|
||||||
@@ -160,7 +171,7 @@ public abstract class EntityHuman extends EntityLiving {
|
@@ -160,7 +179,7 @@ public abstract class EntityHuman extends EntityLiving {
|
||||||
this.sleepTicks = 100;
|
this.sleepTicks = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +63,7 @@ index 3610611299..2bb4ae2265 100644
|
|||||||
this.wakeup(false, true, true);
|
this.wakeup(false, true, true);
|
||||||
}
|
}
|
||||||
} else if (this.sleepTicks > 0) {
|
} else if (this.sleepTicks > 0) {
|
||||||
@@ -1268,7 +1279,7 @@ public abstract class EntityHuman extends EntityLiving {
|
@@ -1268,7 +1287,7 @@ public abstract class EntityHuman extends EntityLiving {
|
||||||
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
|
return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,22 +73,18 @@ index 3610611299..2bb4ae2265 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
||||||
index a1237c5b9d..8b62b0588a 100644
|
index a1237c5b9d..f61ed338ce 100644
|
||||||
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
||||||
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
|
||||||
@@ -161,6 +161,17 @@ public class PurpurWorldConfig {
|
@@ -161,6 +161,13 @@ public class PurpurWorldConfig {
|
||||||
limitVillagerIronGolemSpawns = getInt("limit-villager-iron-golem-spawns", limitVillagerIronGolemSpawns);
|
limitVillagerIronGolemSpawns = getInt("limit-villager-iron-golem-spawns", limitVillagerIronGolemSpawns);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ public boolean sleepOnlyAtNight = false;
|
+ public boolean sleepOnlyWithCondition = false;
|
||||||
+ public long sleepStart = 12541L;
|
+ public String sleepCondition = "time >= 12541 && time <= 23458";
|
||||||
+ public long sleepEnd = 23458L;
|
|
||||||
+ public boolean sleepInvertCondition = false;
|
|
||||||
+ private void sleepSettings() {
|
+ private void sleepSettings() {
|
||||||
+ sleepOnlyAtNight = getBoolean("sleep.only-at-night", sleepOnlyAtNight);
|
+ sleepOnlyWithCondition = getBoolean("sleep.only-with-condition", sleepOnlyWithCondition);
|
||||||
+ sleepStart = getInt("sleep.night-start", (int) sleepStart);
|
+ sleepCondition = getString("sleep.condition", sleepCondition);
|
||||||
+ sleepEnd = getInt("sleep.night-end", (int) sleepEnd);
|
|
||||||
+ sleepInvertCondition = getBoolean("sleep.invert-condition", sleepInvertCondition);
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
public boolean idleTimeoutKick = true;
|
public boolean idleTimeoutKick = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user