-
-
Notifications
You must be signed in to change notification settings - Fork 438
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 10 commits
b75fde9
642c9f4
57b2a51
74cf6b4
5f44f1e
5e6942f
c4d07e3
e138b84
7f01706
f7c53e4
c47c752
a82d3de
ad29c23
d000757
7fffb1f
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,74 @@ | ||
| package ch.njol.skript.events; | ||
|
|
||
| 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 io.papermc.paper.event.entity.EntityFertilizeEggEvent; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos; | ||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||
|
|
||
| public class EvtFertilizeEgg extends SkriptEvent { | ||
|
|
||
| public static void register(SyntaxRegistry registry) { | ||
| registry.register( | ||
| BukkitSyntaxInfos.Event.KEY, | ||
| BukkitSyntaxInfos.Event.builder(EvtFertilizeEgg.class, "Entity Fertilize") | ||
| .addEvent(EntityFertilizeEggEvent.class) | ||
| .addPatterns("[entity] fertiliz(e|ing) [an] egg [of %-entitytypes%]") | ||
|
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. I think |
||
| .addDescription( | ||
| "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).") | ||
| .addExample(""" | ||
| on fertilizing egg of turtles: | ||
| broadcast "A turtle just fertilized an egg!" | ||
| """) | ||
| .addExample(""" | ||
| on fertilizing egg: | ||
| if event-entity is a frog: | ||
| broadcast "A frog just became pregnant!" | ||
|
CJH3139 marked this conversation as resolved.
|
||
| """) | ||
| .addSince("INSERT VERSION") | ||
| .supplier(EvtFertilizeEgg::new) | ||
| .build() | ||
| ); | ||
| } | ||
|
|
||
| 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)); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.skriptlang.skript.test.tests.syntaxes.events; | ||
|
|
||
| import ch.njol.skript.test.runner.SkriptJUnitTest; | ||
| import io.papermc.paper.event.entity.EntityFertilizeEggEvent; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.entity.EntityType; | ||
| import org.bukkit.entity.Frog; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class EvtFertilizeEggTest extends SkriptJUnitTest { | ||
|
|
||
| static { | ||
| setShutdownDelay(1); | ||
| } | ||
|
|
||
| private Frog mother; | ||
| private Frog father; | ||
|
|
||
| @Before | ||
| public void before() { | ||
| mother = spawnTestEntity(EntityType.FROG); | ||
| father = spawnTestEntity(EntityType.FROG); | ||
| } | ||
|
|
||
| @Test | ||
| public void test() { | ||
| Bukkit.getPluginManager().callEvent( | ||
| new EntityFertilizeEggEvent(mother, father, null, null, 0)); | ||
|
Contributor
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. Should add in a player, itemstack, and arbitrary number for experience to make sure the event values work in the sk file |
||
| } | ||
|
|
||
| @After | ||
| public void after() { | ||
| mother.remove(); | ||
| father.remove(); | ||
| } | ||
|
|
||
| } | ||
|
CJH3139 marked this conversation as resolved.
Outdated
|
||
|
Efnilite marked this conversation as resolved.
|
| 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 egg: | ||
| junit test is {@test} | ||
| complete objective "fertilize egg event - general" for {@test} | ||
|
|
||
| on fertilize egg 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.
This should be moved to org.skriptlang paackage