From 73ac6648456fea1dadd65d92a6af058c942c4041 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 2 Jan 2025 14:48:17 -0500 Subject: [PATCH 1/9] Initial Commit --- .../skript/conditions/CondIsSleeping.java | 21 ++-- .../njol/skript/effects/EffWakeupSleep.java | 111 ++++++++++++++++++ .../ch/njol/skript/events/SimpleEvents.java | 5 + .../tests/syntaxes/effects/EffWakeupSleep.sk | 23 ++++ 4 files changed, 150 insertions(+), 10 deletions(-) create mode 100644 src/main/java/ch/njol/skript/effects/EffWakeupSleep.java create mode 100644 src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java index d253829b89d..d60a71872e9 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java @@ -1,33 +1,34 @@ package ch.njol.skript.conditions; -import org.bukkit.entity.Player; - import ch.njol.skript.conditions.base.PropertyCondition; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; import ch.njol.skript.doc.Since; +import org.bukkit.entity.LivingEntity; /** * @author Peter Güttinger */ @Name("Is Sleeping") -@Description("Checks whether a player is sleeping.") -@Examples({"# cut your enemies' throats in their sleep >=)", +@Description("Checks whether an entity is sleeping.") +@Examples({ + "# cut your enemies' throats in their sleep >=)", "on attack:", " attacker is holding a sword", " victim is sleeping", - " increase the damage by 1000"}) -@Since("1.4.4") -public class CondIsSleeping extends PropertyCondition { + " increase the damage by 1000" +}) +@Since("1.4.4, INSERT VERSION (livingentities)") +public class CondIsSleeping extends PropertyCondition { static { - register(CondIsSleeping.class, "sleeping", "players"); + register(CondIsSleeping.class, "sleeping", "livingentities"); } @Override - public boolean check(final Player p) { - return p.isSleeping(); + public boolean check(LivingEntity entity) { + return entity.isSleeping(); } @Override diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java new file mode 100644 index 00000000000..2a4e434470c --- /dev/null +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -0,0 +1,111 @@ +package ch.njol.skript.effects; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Examples; +import ch.njol.skript.doc.Name; +import ch.njol.skript.doc.Since; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser.ParseResult; +import ch.njol.skript.lang.SyntaxStringBuilder; +import ch.njol.skript.util.Direction; +import ch.njol.util.Kleenean; +import org.bukkit.Location; +import org.bukkit.entity.*; +import org.bukkit.event.Event; +import org.jetbrains.annotations.Nullable; + +@Name("Wakeup And Sleep") +@Description({ + "Make bats and foxes sleep or wakeup.", + "Make villagers sleep by providing a location of a bed.", + "Make players sleep by providing a location of a bed and 'with force' to bypass nearby monsters.", + "Using 'without spawn location update' will make players wake up without setting their spawn location to the bed." +}) +@Examples({ + "make {_fox} go to sleep", + "make {_bat} stop sleeping", + "make {_villager} start sleeping at location(0, 0, 0)", + "make player go to sleep at location(0, 0, 0) with force", + "make player wakeup without spawn location update" +}) +@Since("INSERT VERSION") +public class EffWakeupSleep extends Effect { + + static { + Skript.registerEffect(EffWakeupSleep.class, + "make %livingentities% (start sleeping|[go[ ]to] sleep) [%-direction% %-location%] [force:with force]", + "make %livingentities% (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]"); + } + + private Expression entities; + private @Nullable Expression location; + private boolean sleep; + private boolean force; + private boolean setSpawn; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { + //noinspection unchecked + entities = (Expression) exprs[0]; + sleep = matchedPattern == 0; + force = parseResult.hasTag("force"); + setSpawn = !parseResult.hasTag("spawn"); + if (sleep && exprs[1] != null) { + if (exprs[2] == null) + return false; + //noinspection unchecked + Expression direction = (Expression) exprs[1]; + //noinspection unchecked + Expression location = (Expression) exprs[2]; + this.location = Direction.combine(direction, location); + } + return true; + } + + @Override + protected void execute(Event event) { + Location location = this.location == null ? null : this.location.getSingle(event); + for (LivingEntity entity : entities.getArray(event)) { + if (entity instanceof Bat bat) { + bat.setAwake(!sleep); + } else if (entity instanceof Villager villager) { + if (!sleep) { + villager.wakeup(); + } else if (location != null) { + villager.sleep(location); + } + } else if (entity instanceof Fox fox) { + fox.setSleeping(sleep); + } else if (entity instanceof HumanEntity humanEntity) { + if (!sleep) { + humanEntity.wakeup(setSpawn); + } else if (location != null) { + humanEntity.sleep(location, force); + } + } + } + } + + @Override + public String toString(@Nullable Event event, boolean debug) { + SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); + builder.append("make", entities); + if (sleep) { + builder.append("start"); + } else { + builder.append("stop"); + } + builder.append("sleeping"); + if (location != null) { + builder.append(location); + } + if (force) + builder.append("with force"); + if (!setSpawn) + builder.append("without spawn location update"); + return builder.toString(); + } + +} diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index 4a105833d70..c1dd5d1f8a7 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -763,6 +763,11 @@ public class SimpleEvents { .since("2.10"); } + Skript.registerEvent("Bat Toggle Sleep", SimpleEvent.class, BatToggleSleepEvent.class, "bat toggle sleep") + .description("Called when a bat attempts to go to sleep or wakeup.") + .examples("on bat toggle sleep:") + .since("INSERT VERSION"); + } } diff --git a/src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk b/src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk new file mode 100644 index 00000000000..105f60832f3 --- /dev/null +++ b/src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk @@ -0,0 +1,23 @@ + +# Bats require time to go to sleep + +test "fox wakeup and sleep": + spawn a fox at test-location: + set {_entity} to entity + make {_entity} goto sleep + assert {_entity} is sleeping with "Fox should be sleeping" + make {_entity} wakeup + assert {_entity} is not sleeping with "Fox should be awake" + clear entity within {_entity} + +test "villager wakeup and sleep": + set {_old} to block at test-block + set block at test-block to red bed + spawn a villager at test-location: + set {_entity} to entity + make {_entity} goto sleep at test-block + assert {_entity} is sleeping with "Villager should be sleeping" + make {_entity} wakeup + assert {_entity} is not sleeping with "Villager should be awake" + clear entity within {_entity} + set block at test-block to {_old} From 5f6377edc2debe03fd6dc0d6f6280f0edce62176 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:27:19 -0500 Subject: [PATCH 2/9] Requested Changes --- .../ch/njol/skript/conditions/CondIsSleeping.java | 11 ++++------- .../java/ch/njol/skript/effects/EffWakeupSleep.java | 11 ++++++----- src/main/java/ch/njol/skript/events/SimpleEvents.java | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java index d60a71872e9..db016097111 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java @@ -7,17 +7,14 @@ import ch.njol.skript.doc.Since; import org.bukkit.entity.LivingEntity; -/** - * @author Peter Güttinger - */ @Name("Is Sleeping") @Description("Checks whether an entity is sleeping.") @Examples({ "# cut your enemies' throats in their sleep >=)", - "on attack:", - " attacker is holding a sword", - " victim is sleeping", - " increase the damage by 1000" + "on attack:", + "\tattacker is holding a sword", + "\tvictim is sleeping", + "\tincrease the damage by 1000" }) @Since("1.4.4, INSERT VERSION (livingentities)") public class CondIsSleeping extends PropertyCondition { diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index 2a4e434470c..559d4a1e87e 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -18,7 +18,7 @@ @Name("Wakeup And Sleep") @Description({ - "Make bats and foxes sleep or wakeup.", + "Make bats and foxes sleep or wake up.", "Make villagers sleep by providing a location of a bed.", "Make players sleep by providing a location of a bed and 'with force' to bypass nearby monsters.", "Using 'without spawn location update' will make players wake up without setting their spawn location to the bed." @@ -35,8 +35,10 @@ public class EffWakeupSleep extends Effect { static { Skript.registerEffect(EffWakeupSleep.class, - "make %livingentities% (start sleeping|[go[ ]to] sleep) [%-direction% %-location%] [force:with force]", - "make %livingentities% (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]"); + "make %livingentities% (start sleeping|[go[ ]to] sleep) [%-direction% %-location%]", + "make %players% (start sleeping|[go[ ]to] sleep) %direction% %location% [force:with force]", + "make %livingentities% (stop sleeping|wake[ ]up)", + "make %players% (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]"); } private Expression entities; @@ -98,9 +100,8 @@ public String toString(@Nullable Event event, boolean debug) { builder.append("stop"); } builder.append("sleeping"); - if (location != null) { + if (location != null) builder.append(location); - } if (force) builder.append("with force"); if (!setSpawn) diff --git a/src/main/java/ch/njol/skript/events/SimpleEvents.java b/src/main/java/ch/njol/skript/events/SimpleEvents.java index c1dd5d1f8a7..c790dd95a30 100644 --- a/src/main/java/ch/njol/skript/events/SimpleEvents.java +++ b/src/main/java/ch/njol/skript/events/SimpleEvents.java @@ -764,7 +764,7 @@ public class SimpleEvents { } Skript.registerEvent("Bat Toggle Sleep", SimpleEvent.class, BatToggleSleepEvent.class, "bat toggle sleep") - .description("Called when a bat attempts to go to sleep or wakeup.") + .description("Called when a bat attempts to go to sleep or wakes up.") .examples("on bat toggle sleep:") .since("INSERT VERSION"); From f5a5bad84c7c9f316039d49fb05b51abe03c2a04 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:31:16 -0500 Subject: [PATCH 3/9] Requested Changes --- .../ch/njol/skript/conditions/CondIsSleeping.java | 12 ++++++------ .../java/ch/njol/skript/effects/EffWakeupSleep.java | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java index db016097111..1cc67ecf6f5 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java @@ -10,13 +10,13 @@ @Name("Is Sleeping") @Description("Checks whether an entity is sleeping.") @Examples({ - "# cut your enemies' throats in their sleep >=)", - "on attack:", - "\tattacker is holding a sword", - "\tvictim is sleeping", - "\tincrease the damage by 1000" + "if player is sleeping:", + "\tmake player wakeup without spawn location update", + "", + "if last spawned fox is sleeping:", + "\tmake last spawned fox stop sleeping" }) -@Since("1.4.4, INSERT VERSION (livingentities)") +@Since("1.4.4, INSERT VERSION (living entities)") public class CondIsSleeping extends PropertyCondition { static { diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index 559d4a1e87e..5ae39cf7da0 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -16,7 +16,7 @@ import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; -@Name("Wakeup And Sleep") +@Name("Wake And Sleep") @Description({ "Make bats and foxes sleep or wake up.", "Make villagers sleep by providing a location of a bed.", @@ -36,9 +36,13 @@ public class EffWakeupSleep extends Effect { static { Skript.registerEffect(EffWakeupSleep.class, "make %livingentities% (start sleeping|[go[ ]to] sleep) [%-direction% %-location%]", + "force %livingentities% to (start sleeping|[go[ ]to sleep) [%-direction% %-location%]", "make %players% (start sleeping|[go[ ]to] sleep) %direction% %location% [force:with force]", + "force %players% to (start sleeping|[go[ ]to] sleep) %direction% %location% [force:with force]", "make %livingentities% (stop sleeping|wake[ ]up)", - "make %players% (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]"); + "force %livingentities% to (stop sleeping|wake[ ]up)", + "make %players% (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]", + "force %players% to (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]"); } private Expression entities; @@ -51,7 +55,7 @@ public class EffWakeupSleep extends Effect { public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { //noinspection unchecked entities = (Expression) exprs[0]; - sleep = matchedPattern == 0; + sleep = matchedPattern <= 3; force = parseResult.hasTag("force"); setSpawn = !parseResult.hasTag("spawn"); if (sleep && exprs[1] != null) { From cac460bf957173f2eb5758d635dcf50116ed17e1 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Sat, 4 Jan 2025 00:49:32 -0500 Subject: [PATCH 4/9] Fix Malformed Pattern --- src/main/java/ch/njol/skript/effects/EffWakeupSleep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index 5ae39cf7da0..cb301ed3f5f 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -36,7 +36,7 @@ public class EffWakeupSleep extends Effect { static { Skript.registerEffect(EffWakeupSleep.class, "make %livingentities% (start sleeping|[go[ ]to] sleep) [%-direction% %-location%]", - "force %livingentities% to (start sleeping|[go[ ]to sleep) [%-direction% %-location%]", + "force %livingentities% to (start sleeping|[go[ ]to] sleep) [%-direction% %-location%]", "make %players% (start sleeping|[go[ ]to] sleep) %direction% %location% [force:with force]", "force %players% to (start sleeping|[go[ ]to] sleep) %direction% %location% [force:with force]", "make %livingentities% (stop sleeping|wake[ ]up)", From 6b213a4213b0751382ebd43ad90ac117d8245450 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:07:42 -0500 Subject: [PATCH 5/9] Requested Changes --- .../skript/conditions/CondIsSleeping.java | 2 +- .../njol/skript/effects/EffWakeupSleep.java | 25 +++++++++++-------- .../tests/syntaxes/effects/EffWakeupSleep.sk | 15 ++++++++--- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java index 1cc67ecf6f5..34cf03c234d 100644 --- a/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java +++ b/src/main/java/ch/njol/skript/conditions/CondIsSleeping.java @@ -11,7 +11,7 @@ @Description("Checks whether an entity is sleeping.") @Examples({ "if player is sleeping:", - "\tmake player wakeup without spawn location update", + "\tmake player wake up without spawn location update", "", "if last spawned fox is sleeping:", "\tmake last spawned fox stop sleeping" diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index cb301ed3f5f..96dcc584077 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -28,21 +28,21 @@ "make {_bat} stop sleeping", "make {_villager} start sleeping at location(0, 0, 0)", "make player go to sleep at location(0, 0, 0) with force", - "make player wakeup without spawn location update" + "make player wake up without spawn location update" }) @Since("INSERT VERSION") public class EffWakeupSleep extends Effect { static { Skript.registerEffect(EffWakeupSleep.class, - "make %livingentities% (start sleeping|[go[ ]to] sleep) [%-direction% %-location%]", - "force %livingentities% to (start sleeping|[go[ ]to] sleep) [%-direction% %-location%]", - "make %players% (start sleeping|[go[ ]to] sleep) %direction% %location% [force:with force]", - "force %players% to (start sleeping|[go[ ]to] sleep) %direction% %location% [force:with force]", - "make %livingentities% (stop sleeping|wake[ ]up)", - "force %livingentities% to (stop sleeping|wake[ ]up)", - "make %players% (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]", - "force %players% to (stop sleeping|wake[ ]up) [spawn:without spawn [location] update]"); + "make %livingentities% (start sleeping|[go to] sleep) [%-direction% %-location%]", + "force %livingentities% to (start sleeping|[go to] sleep) [%-direction% %-location%]", + "make %players% (start sleeping|[go to] sleep) %direction% %location% [force:with force]", + "force %players% to (start sleeping|[go to] sleep) %direction% %location% [force:with force]", + "make %livingentities% (stop sleeping|wake up)", + "force %livingentities% to (stop sleeping|wake up)", + "make %players% (stop sleeping|wake up) [spawn:without spawn [location] update]", + "force %players% to (stop sleeping|wake up) [spawn:without spawn [location] update]"); } private Expression entities; @@ -72,7 +72,12 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { - Location location = this.location == null ? null : this.location.getSingle(event); + Location location = null; + if (this.location != null) { + location = this.location.getSingle(event); + //if (location == null) + // Runtime warning + } for (LivingEntity entity : entities.getArray(event)) { if (entity instanceof Bat bat) { bat.setAwake(!sleep); diff --git a/src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk b/src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk index 105f60832f3..7c26018de96 100644 --- a/src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk +++ b/src/test/skript/tests/syntaxes/effects/EffWakeupSleep.sk @@ -4,9 +4,9 @@ test "fox wakeup and sleep": spawn a fox at test-location: set {_entity} to entity - make {_entity} goto sleep + make {_entity} go to sleep assert {_entity} is sleeping with "Fox should be sleeping" - make {_entity} wakeup + make {_entity} wake up assert {_entity} is not sleeping with "Fox should be awake" clear entity within {_entity} @@ -15,9 +15,16 @@ test "villager wakeup and sleep": set block at test-block to red bed spawn a villager at test-location: set {_entity} to entity - make {_entity} goto sleep at test-block + make {_entity} go to sleep at test-block assert {_entity} is sleeping with "Villager should be sleeping" - make {_entity} wakeup + make {_entity} wake up assert {_entity} is not sleeping with "Villager should be awake" clear entity within {_entity} set block at test-block to {_old} + +test "invalid entities": + spawn a cow, a sheep and a pig at test-location: + add entity to {_entities::*} + make {_entities::*} go to sleep + assert {_entities::*} is not sleeping with "Invalid entities should not be able to sleep" + clear entities within {_entities::*} From faab9f2670a923118879ef8cd30547e175e4779e Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:28:40 -0500 Subject: [PATCH 6/9] Runtime warning --- .../ch/njol/skript/effects/EffWakeupSleep.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index 96dcc584077..7dbe19a8908 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -1,6 +1,7 @@ package ch.njol.skript.effects; import ch.njol.skript.Skript; +import ch.njol.skript.config.Node; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; @@ -15,6 +16,7 @@ import org.bukkit.entity.*; import org.bukkit.event.Event; import org.jetbrains.annotations.Nullable; +import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer; @Name("Wake And Sleep") @Description({ @@ -31,7 +33,7 @@ "make player wake up without spawn location update" }) @Since("INSERT VERSION") -public class EffWakeupSleep extends Effect { +public class EffWakeupSleep extends Effect implements SyntaxRuntimeErrorProducer { static { Skript.registerEffect(EffWakeupSleep.class, @@ -50,6 +52,7 @@ public class EffWakeupSleep extends Effect { private boolean sleep; private boolean force; private boolean setSpawn; + private Node node; @Override public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { @@ -67,6 +70,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye Expression location = (Expression) exprs[2]; this.location = Direction.combine(direction, location); } + node = getParser().getNode(); return true; } @@ -75,8 +79,8 @@ protected void execute(Event event) { Location location = null; if (this.location != null) { location = this.location.getSingle(event); - //if (location == null) - // Runtime warning + if (location == null) + warning("The provided location is null, this effect will not work as intended for villagers and player."); } for (LivingEntity entity : entities.getArray(event)) { if (entity instanceof Bat bat) { @@ -99,6 +103,11 @@ protected void execute(Event event) { } } + @Override + public Node getNode() { + return node; + } + @Override public String toString(@Nullable Event event, boolean debug) { SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); From 2503e2683ecf18cda0799ce80b9f30f6dd5a81d3 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:14:19 -0500 Subject: [PATCH 7/9] Update Runtime Warning --- src/main/java/ch/njol/skript/effects/EffWakeupSleep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index 7dbe19a8908..1afaaa2ccc7 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -80,7 +80,7 @@ protected void execute(Event event) { if (this.location != null) { location = this.location.getSingle(event); if (location == null) - warning("The provided location is null, this effect will not work as intended for villagers and player."); + warning("The provided location is not set. This effect will have no effect for villagers and players."); } for (LivingEntity entity : entities.getArray(event)) { if (entity instanceof Bat bat) { From 0b1187682de4e08d2663d91754ee448bdf8d393e Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Tue, 4 Feb 2025 02:32:53 -0500 Subject: [PATCH 8/9] Requested Changes --- .../njol/skript/effects/EffWakeupSleep.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index 1afaaa2ccc7..36cb26e0470 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -22,7 +22,9 @@ @Description({ "Make bats and foxes sleep or wake up.", "Make villagers sleep by providing a location of a bed.", - "Make players sleep by providing a location of a bed and 'with force' to bypass nearby monsters.", + "Make players sleep by providing a location of a bed. " + + "Using 'with force' will bypass \"nearby monsters\" and the max distance, making players go to sleep if the bed " + + "is far away or in another world.", "Using 'without spawn location update' will make players wake up without setting their spawn location to the bed." }) @Examples({ @@ -39,12 +41,12 @@ public class EffWakeupSleep extends Effect implements SyntaxRuntimeErrorProducer Skript.registerEffect(EffWakeupSleep.class, "make %livingentities% (start sleeping|[go to] sleep) [%-direction% %-location%]", "force %livingentities% to (start sleeping|[go to] sleep) [%-direction% %-location%]", - "make %players% (start sleeping|[go to] sleep) %direction% %location% [force:with force]", - "force %players% to (start sleeping|[go to] sleep) %direction% %location% [force:with force]", + "make %players% (start sleeping|[go to] sleep) %direction% %location% (force:with force)", + "force %players% to (start sleeping|[go to] sleep) %direction% %location% (force:with force)", "make %livingentities% (stop sleeping|wake up)", "force %livingentities% to (stop sleeping|wake up)", - "make %players% (stop sleeping|wake up) [spawn:without spawn [location] update]", - "force %players% to (stop sleeping|wake up) [spawn:without spawn [location] update]"); + "make %players% (stop sleeping|wake up) (spawn:without spawn [location] update)", + "force %players% to (stop sleeping|wake up) (spawn:without spawn [location] update)"); } private Expression entities; @@ -65,10 +67,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye if (exprs[2] == null) return false; //noinspection unchecked - Expression direction = (Expression) exprs[1]; - //noinspection unchecked - Expression location = (Expression) exprs[2]; - this.location = Direction.combine(direction, location); + this.location = Direction.combine((Expression) exprs[1], (Expression) exprs[2]); } node = getParser().getNode(); return true; @@ -77,26 +76,38 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye @Override protected void execute(Event event) { Location location = null; - if (this.location != null) { + if (this.location != null) location = this.location.getSingle(event); - if (location == null) - warning("The provided location is not set. This effect will have no effect for villagers and players."); - } + boolean warned = false; for (LivingEntity entity : entities.getArray(event)) { if (entity instanceof Bat bat) { bat.setAwake(!sleep); } else if (entity instanceof Villager villager) { + if (sleep && location == null) { + if (!warned) { + warned = true; + warning("The provided location is not set. This effect will have no effect for villagers and players."); + } + continue; + } if (!sleep) { villager.wakeup(); - } else if (location != null) { + } else { villager.sleep(location); } } else if (entity instanceof Fox fox) { fox.setSleeping(sleep); } else if (entity instanceof HumanEntity humanEntity) { + if (sleep && location == null) { + if (!warned) { + warned = true; + warning("The provided location is not set. This effect will have no effect for villagers and players."); + } + continue; + } if (!sleep) { humanEntity.wakeup(setSpawn); - } else if (location != null) { + } else { humanEntity.sleep(location, force); } } From fde4b810ce4cd2932121ff98a6fd9db52d95c9c1 Mon Sep 17 00:00:00 2001 From: SirSmurfy2 <82696841+TheAbsolutionism@users.noreply.github.com> Date: Wed, 5 Feb 2025 05:05:23 -0500 Subject: [PATCH 9/9] warning update --- .../njol/skript/effects/EffWakeupSleep.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java index 36cb26e0470..15f7a2ef9fc 100644 --- a/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java +++ b/src/main/java/ch/njol/skript/effects/EffWakeupSleep.java @@ -23,8 +23,9 @@ "Make bats and foxes sleep or wake up.", "Make villagers sleep by providing a location of a bed.", "Make players sleep by providing a location of a bed. " - + "Using 'with force' will bypass \"nearby monsters\" and the max distance, making players go to sleep if the bed " - + "is far away or in another world.", + + "Using 'with force' will bypass \"nearby monsters\" ,the max distance, allowing players to sleep even if the bed " + + "is far away, and lets players sleep in the nether and end. " + + "Does not work if the location of the bed is not in the world the player is currently in.", "Using 'without spawn location update' will make players wake up without setting their spawn location to the bed." }) @Examples({ @@ -78,16 +79,13 @@ protected void execute(Event event) { Location location = null; if (this.location != null) location = this.location.getSingle(event); - boolean warned = false; + boolean failed = false; for (LivingEntity entity : entities.getArray(event)) { if (entity instanceof Bat bat) { bat.setAwake(!sleep); } else if (entity instanceof Villager villager) { if (sleep && location == null) { - if (!warned) { - warned = true; - warning("The provided location is not set. This effect will have no effect for villagers and players."); - } + failed = true; continue; } if (!sleep) { @@ -99,10 +97,7 @@ protected void execute(Event event) { fox.setSleeping(sleep); } else if (entity instanceof HumanEntity humanEntity) { if (sleep && location == null) { - if (!warned) { - warned = true; - warning("The provided location is not set. This effect will have no effect for villagers and players."); - } + failed = true; continue; } if (!sleep) { @@ -112,6 +107,8 @@ protected void execute(Event event) { } } } + if (failed) + warning("The provided location is not set. This effect will have no effect for villagers and players."); } @Override