-
-
Notifications
You must be signed in to change notification settings - Fork 414
Add paper's EntityFertilizeEgg event #8231
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
Open
CJH3139
wants to merge
3
commits into
SkriptLang:dev/feature
Choose a base branch
from
CJH3139:cjh/event/FertilizeEgg
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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,73 @@ | ||
| package ch.njol.skript.events; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.entity.EntityType; | ||
| import ch.njol.skript.lang.Literal; | ||
| import ch.njol.skript.lang.SkriptEvent; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.registrations.EventValues; | ||
| import io.papermc.paper.event.entity.EntityFertilizeEggEvent; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| public class EvtFertilizeEgg extends SkriptEvent { | ||
|
|
||
| static { | ||
| Skript.registerEvent("Entity Fertilize", EvtFertilizeEgg.class, EntityFertilizeEggEvent.class, | ||
| "[entity] fertiliz(e|ing) [an] egg [of %-entitytypes%]") | ||
| .description( | ||
| "Called whenever an entity fertilizes an egg (e.g. a turtle has an egg, a frog becomes pregnant, or a " + | ||
| "sniffer finds a sniffer egg).") | ||
| .examples(""" | ||
| on fertilizing egg of turtles: | ||
| broadcast "A turtle just fertilized an egg!" | ||
| on fertilizing egg: | ||
| if event-entity is a frog: | ||
| broadcast "A frog just became pregnant!" | ||
| """) | ||
| .since("INSERT VERSION"); | ||
|
|
||
| EventValues.registerEventValue(EntityFertilizeEggEvent.class, Entity.class, event -> { | ||
| return event.getEntity(); | ||
| }, EventValues.TIME_NOW, | ||
| "Use 'mother' and/or 'father' in fertilize egg events", | ||
| EntityFertilizeEggEvent.class | ||
| ); | ||
| } | ||
|
|
||
| private @Nullable Literal<EntityType> entitiesLiteral; | ||
| private EntityType @Nullable [] entities; | ||
|
|
||
| @Override | ||
| public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||
| if (args[0] != null) { | ||
| //noinspection unchecked | ||
| entitiesLiteral = ((Literal<EntityType>) args[0]); | ||
| entities = entitiesLiteral.getAll(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Event event) { | ||
| return event instanceof EntityFertilizeEggEvent fertilizeEvent && checkEntity(fertilizeEvent.getEntity()); | ||
| } | ||
|
|
||
| private boolean checkEntity(Entity entity) { | ||
| if (entities != null) { | ||
| for (EntityType entityType : entities) { | ||
| if (entityType.isInstance(entity)) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return "on fertilizing egg" + (entitiesLiteral == null ? "" : " of " + entitiesLiteral.toString(event, debug)); | ||
| } | ||
|
|
||
| } |
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
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where's the java code for summoning the frogs? |
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,21 @@ | ||
| options: | ||
| test: "org.skriptlang.skript.test.tests.syntaxes.events.EvtFertilizeEggTest" | ||
|
|
||
| test "EvtFertilizeEggTest" when running Junit: | ||
| add "fertilize egg event - general" to {_evt::*} | ||
| add "fertilize egg event - specified entity" to {_evt::*} | ||
| add "fertilize egg event - mother" to {_evt::*} | ||
| add "fertilize egg event - father" to {_evt::*} | ||
| ensure junit test {@test} completes {_evt::*} | ||
|
|
||
| on fertilize: | ||
| junit test is {@test} | ||
| complete objective "fertilize egg event - general" for {@test} | ||
|
|
||
| on fertilize of frog: | ||
| junit test is {@test} | ||
| complete objective "fertilize egg event - specified entity" for {@test} | ||
| breeding mother is frog | ||
| complete objective "fertilize egg event - mother" for {@test} | ||
| breeding father is frog | ||
| complete objective "fertilize egg event - father" for {@test} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventRestrictedSyntax