-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
base: dev/feature
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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:", | ||||||||||||||||||||||||||||||
| "\tsend \"A turtle just fertilized an egg!\"", | ||||||||||||||||||||||||||||||
| "on fertilizing egg:", | ||||||||||||||||||||||||||||||
| "\tif event-entity is a frog:", | ||||||||||||||||||||||||||||||
| "\t\tsend \"A frog just became pregnant!\"" | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| .examples( | |
| "on fertilizing egg of turtles:", | |
| "\tsend \"A turtle just fertilized an egg!\"", | |
| "on fertilizing egg:", | |
| "\tif event-entity is a frog:", | |
| "\t\tsend \"A frog just became pregnant!\"" | |
| ) | |
| .examples(""" | |
| on fertilizing egg of turtles: | |
| send "A turtle just fertilized an egg!" | |
| on fertilizing egg: | |
| if event-entity is a frog: | |
| send "A frog just became pregnant!" | |
| """) |
Also, use broadcast instead of send since that's invalid as there's no default player to send a message to.
Outdated
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.
| .since("2.14"); | |
| .since("INSERT VERSION"); |
Outdated
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.
this will error on all servers with the ea flag, so probably best to remove it
Outdated
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.
| return "on fertilizing egg" + (entitiesLiteral == null ? "" : " of " + entitiesLiteral); | |
| return "on fertilizing egg" + (entitiesLiteral == null ? "" : " of " + entitiesLiteral.toString(event, debug)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.util.SimpleExpression; | ||
| import ch.njol.util.Kleenean; | ||
| import io.papermc.paper.event.entity.EntityFertilizeEggEvent; | ||
| import org.bukkit.entity.LivingEntity; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.event.entity.EntityBreedEvent; | ||
|
|
@@ -38,27 +39,35 @@ public class ExprBreedingFamily extends SimpleExpression<LivingEntity> { | |
| @Override | ||
| public boolean init(Expression<?>[] expressions, int matchedPattern, | ||
| Kleenean isDelayed, ParseResult parseResult) { | ||
| if (!getParser().isCurrentEvent(EntityBreedEvent.class)) { | ||
| Skript.error("The 'breeding family' expression can only be used in an breed event."); | ||
| if (!getParser().isCurrentEvent(EntityBreedEvent.class) && !getParser().isCurrentEvent(EntityFertilizeEggEvent.class)) { | ||
| Skript.error("The 'breeding family' expression can only be used in an breed or fertilize egg event."); | ||
| return false; | ||
| } | ||
|
Comment on lines
+42
to
+45
Member
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. EventRestrictedSyntax |
||
| if (getParser().isCurrentEvent(EntityFertilizeEggEvent.class) && matchedPattern >= 2){ | ||
| Skript.error("The 'bred child' expression cannot be used in a 'fertilize egg' event."); | ||
| return false; | ||
| } | ||
|
|
||
| pattern = matchedPattern; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected @Nullable LivingEntity [] get(Event event) { | ||
| if (!(event instanceof EntityBreedEvent breedEvent)) | ||
| return new LivingEntity[0]; | ||
|
|
||
| return switch (pattern) { | ||
| case 0 -> new LivingEntity[]{breedEvent.getMother()}; | ||
| case 1 -> new LivingEntity[]{breedEvent.getFather()}; | ||
| case 2 -> new LivingEntity[]{breedEvent.getEntity()}; | ||
| case 3 -> new LivingEntity[]{breedEvent.getBreeder()}; | ||
| default -> new LivingEntity[0]; | ||
| }; | ||
| if (event instanceof EntityBreedEvent breedEvent) | ||
| return switch (pattern) { | ||
| case 0 -> new LivingEntity[]{breedEvent.getMother()}; | ||
| case 1 -> new LivingEntity[]{breedEvent.getFather()}; | ||
| case 2 -> new LivingEntity[]{breedEvent.getEntity()}; | ||
| case 3 -> new LivingEntity[]{breedEvent.getBreeder()}; | ||
| default -> new LivingEntity[0]; | ||
| }; | ||
| else if (event instanceof EntityFertilizeEggEvent fertilizeEggEvent) | ||
| return switch (pattern) { | ||
| case 0 -> new LivingEntity[]{fertilizeEggEvent.getMother()}; | ||
| case 1 -> new LivingEntity[]{fertilizeEggEvent.getFather()}; | ||
| default -> new LivingEntity[0]; | ||
| }; | ||
| return new LivingEntity[0]; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
|
Member
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? |
| 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} |
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.