-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
15
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.
+214
−19
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b75fde9
Add paper's EntityFertilizeEgg event
CJH3139 642c9f4
Add test skript
CJH3139 57b2a51
Update EvtFertilizeEgg.java
CJH3139 74cf6b4
Update ExprBreedingFamily.java
CJH3139 5f44f1e
Merge remote-tracking branch 'upstream/dev/feature' into cjh/event/Fe…
CJH3139 5e6942f
Update EvtFertilizeEgg.sk
CJH3139 c4d07e3
Update EvtFertilizeEgg
CJH3139 e138b84
Merge branch 'dev/feature' into cjh/event/FertilizeEgg
CJH3139 7f01706
Update src/main/java/ch/njol/skript/events/EvtFertilizeEgg.java
CJH3139 f7c53e4
Add EventValues for player, itemstack and xp
CJH3139 c47c752
Update src/main/java/ch/njol/skript/events/SimpleEvents.java
CJH3139 a82d3de
Update src/test/java/org/skriptlang/skript/test/tests/syntaxes/events…
CJH3139 ad29c23
Add player, itemstack, and experience to make sure event values work …
CJH3139 d000757
Update EvtFertilizeEgg.sk
CJH3139 7fffb1f
Update ExprBreedingFamily.java
CJH3139 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
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,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)); | ||
| } | ||
|
|
||
| } | ||
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
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
47 changes: 47 additions & 0 deletions
47
src/test/java/org/skriptlang/skript/test/tests/syntaxes/events/EvtFertilizeEggTest.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,47 @@ | ||
| 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.Material; | ||
| import org.bukkit.entity.EntityType; | ||
| import org.bukkit.entity.Frog; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.easymock.EasyMock; | ||
| 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; | ||
| private Player player; | ||
|
|
||
| @Before | ||
| public void before() { | ||
| mother = spawnTestEntity(EntityType.FROG); | ||
| father = spawnTestEntity(EntityType.FROG); | ||
|
|
||
| player = EasyMock.niceMock(Player.class); | ||
| EasyMock.replay(player); | ||
| } | ||
|
|
||
| @Test | ||
| public void test() { | ||
| Bukkit.getPluginManager().callEvent( | ||
| new EntityFertilizeEggEvent(mother, father, player, new ItemStack(Material.SLIME_BALL), 5)); | ||
| } | ||
|
|
||
| @After | ||
| public void after() { | ||
| mother.remove(); | ||
| father.remove(); | ||
| } | ||
|
|
||
| } |
|
Efnilite marked this conversation as resolved.
|
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 @@ | ||
| 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::*} | ||
| add "fertilize egg event - breeder is player" to {_evt::*} | ||
| add "fertilize egg event - item is slime ball" to {_evt::*} | ||
| add "fertilize egg event - experience is 5" 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} | ||
| if event-player is a player: | ||
| complete objective "fertilize egg event - breeder is player" for {@test} | ||
| if event-item is slime ball: | ||
| complete objective "fertilize egg event - item is slime ball" for {@test} | ||
| if event-experience is 5: | ||
| complete objective "fertilize egg event - experience is 5" for {@test} |
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.
This should be moved to org.skriptlang paackage