-
-
Notifications
You must be signed in to change notification settings - Fork 446
Bat Support #7362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
erenkarakal
merged 17 commits into
SkriptLang:dev/feature
from
Absolutionism:dev/BatSupport
Mar 31, 2025
Merged
Bat Support #7362
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
73ac664
Initial Commit
Absolutionism 5f6377e
Requested Changes
Absolutionism f5a5bad
Requested Changes
Absolutionism 0489aa4
Merge branch 'dev/feature' into dev/BatSupport
Absolutionism cac460b
Fix Malformed Pattern
Absolutionism 6b213a4
Requested Changes
Absolutionism faab9f2
Runtime warning
Absolutionism 89f80b3
Merge remote-tracking branch 'upstream/dev/feature' into dev/BatSupport
Absolutionism 2503e26
Update Runtime Warning
Absolutionism 0b11876
Requested Changes
Absolutionism 3441ccf
Merge branch 'dev/feature' into dev/BatSupport
Absolutionism fde4b81
warning update
Absolutionism f4948d3
Merge branch 'dev/feature' into dev/BatSupport
Absolutionism 6a2e45a
Merge branch 'dev/feature' into dev/BatSupport
sovdeeth 46bd5c9
Merge remote-tracking branch 'upstream/dev/feature' into dev/BatSupport
Absolutionism 79bf7d0
Merge branch 'dev/feature' into dev/BatSupport
erenkarakal 49e2e45
Merge branch 'dev/feature' into dev/BatSupport
erenkarakal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 12 additions & 13 deletions
25
src/main/java/ch/njol/skript/conditions/CondIsSleeping.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/main/java/ch/njol/skript/effects/EffWakeupSleep.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| 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; | ||
| 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; | ||
| import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer; | ||
|
|
||
| @Name("Wake And Sleep") | ||
| @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. " | ||
| + "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({ | ||
| "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 wake up without spawn location update" | ||
| }) | ||
| @Since("INSERT VERSION") | ||
| public class EffWakeupSleep extends Effect implements SyntaxRuntimeErrorProducer { | ||
|
|
||
| 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)"); | ||
| } | ||
|
|
||
| private Expression<LivingEntity> entities; | ||
| private @Nullable Expression<Location> location; | ||
| private boolean sleep; | ||
| private boolean force; | ||
| private boolean setSpawn; | ||
| private Node node; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| //noinspection unchecked | ||
| entities = (Expression<LivingEntity>) exprs[0]; | ||
| sleep = matchedPattern <= 3; | ||
| force = parseResult.hasTag("force"); | ||
| setSpawn = !parseResult.hasTag("spawn"); | ||
| if (sleep && exprs[1] != null) { | ||
| if (exprs[2] == null) | ||
| return false; | ||
| //noinspection unchecked | ||
| this.location = Direction.combine((Expression<Direction>) exprs[1], (Expression<Location>) exprs[2]); | ||
| } | ||
| node = getParser().getNode(); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected void execute(Event event) { | ||
| Location location = null; | ||
| if (this.location != null) | ||
| location = this.location.getSingle(event); | ||
| 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) { | ||
| failed = true; | ||
| continue; | ||
| } | ||
| if (!sleep) { | ||
| villager.wakeup(); | ||
| } else { | ||
| villager.sleep(location); | ||
| } | ||
| } else if (entity instanceof Fox fox) { | ||
| fox.setSleeping(sleep); | ||
| } else if (entity instanceof HumanEntity humanEntity) { | ||
| if (sleep && location == null) { | ||
| failed = true; | ||
| continue; | ||
| } | ||
| if (!sleep) { | ||
| humanEntity.wakeup(setSpawn); | ||
| } else { | ||
| humanEntity.sleep(location, force); | ||
|
Absolutionism marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
| if (failed) | ||
| warning("The provided location is not set. This effect will have no effect for villagers and players."); | ||
| } | ||
|
|
||
| @Override | ||
| public Node getNode() { | ||
| return node; | ||
| } | ||
|
|
||
| @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"); | ||
| } | ||
|
Absolutionism marked this conversation as resolved.
|
||
| 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(); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
|
|
||
| # Bats require time to go to sleep | ||
|
|
||
| test "fox wakeup and sleep": | ||
| spawn a fox at test-location: | ||
| set {_entity} to entity | ||
| make {_entity} go to sleep | ||
| assert {_entity} is sleeping with "Fox should be sleeping" | ||
| make {_entity} wake up | ||
| 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} go to sleep at test-block | ||
| assert {_entity} is sleeping with "Villager should be sleeping" | ||
| 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::*} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.