-
-
Notifications
You must be signed in to change notification settings - Fork 446
Goat Support #7479
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
Efnilite
merged 18 commits into
SkriptLang:dev/feature
from
Absolutionism:dev/GoatSupport
Mar 30, 2025
Merged
Goat Support #7479
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
79c8243
Initial Commit
Absolutionism 1dd0ff5
Ram Note
Absolutionism 4b57955
Requested Changes
Absolutionism bd5de06
Docs Update
Absolutionism 3972deb
Merge branch 'dev/feature' into dev/GoatSupport
Absolutionism 0f0ed07
Semi-Update
Absolutionism 7058971
Merge branch 'dev/feature' into dev/GoatSupport
Absolutionism 42053ce
No Work
Absolutionism f0944e7
update junit tests
Efnilite 04a74c8
Void GoatHorns Test
Absolutionism 8c88b03
Merge branch 'dev/feature' into dev/GoatSupport
Absolutionism 5f52bb4
Requested Changes
Absolutionism 90d929a
Merge branch 'dev/GoatSupport' of https://github.com/TheAbsolutionism…
Absolutionism 023325d
Merge branch 'dev/feature' into dev/GoatSupport
Absolutionism bba77bf
Merge branch 'dev/feature' into dev/GoatSupport
Absolutionism d068f1b
Merge remote-tracking branch 'upstream/dev/feature' into dev/GoatSupport
Absolutionism 9681851
Example Annotation
Absolutionism 0d53934
Merge branch 'dev/feature' into dev/GoatSupport
Efnilite 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
70 changes: 70 additions & 0 deletions
70
src/main/java/ch/njol/skript/conditions/CondGoatHasHorns.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,70 @@ | ||
| package ch.njol.skript.conditions; | ||
|
|
||
| import ch.njol.skript.conditions.base.PropertyCondition; | ||
| import ch.njol.skript.doc.*; | ||
| import ch.njol.skript.effects.EffGoatHorns.GoatHorn; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.entity.Goat; | ||
| import org.bukkit.entity.LivingEntity; | ||
|
|
||
| @Name("Goat Has Horns") | ||
| @Description("Checks to see if a goat has or does not have a left, right, or both horns.") | ||
| @Example(""" | ||
| if last spawned goat does not have both horns: | ||
| make last spawned goat have both horns | ||
| """ | ||
| ) | ||
| @Example(""" | ||
| if {_goat} has a right horn: | ||
| force {_goat} to not have a right horn | ||
| """ | ||
| ) | ||
| @Since("INSERT VERSION") | ||
| public class CondGoatHasHorns extends PropertyCondition<LivingEntity> { | ||
|
|
||
| static { | ||
| register(CondGoatHasHorns.class, PropertyType.HAVE, | ||
| "((any|a) horn|left:[a] left horn[s]|right:[a] right horn[s]|both:both horns)", "livingentities"); | ||
| } | ||
|
|
||
| private GoatHorn goatHorn = GoatHorn.ANY; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| if (parseResult.hasTag("left")) { | ||
| goatHorn = GoatHorn.LEFT; | ||
| } else if (parseResult.hasTag("right")) { | ||
| goatHorn = GoatHorn.RIGHT; | ||
| } else if (parseResult.hasTag("both")) { | ||
| goatHorn = GoatHorn.BOTH; | ||
| } | ||
| return super.init(exprs, matchedPattern, isDelayed, parseResult); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(LivingEntity entity) { | ||
| if (!(entity instanceof Goat goat)) | ||
| return false; | ||
| boolean leftHorn = goat.hasLeftHorn(); | ||
| boolean rightHorn = goat.hasRightHorn(); | ||
| return switch (goatHorn) { | ||
| case ANY -> leftHorn || rightHorn; | ||
| case BOTH -> leftHorn && rightHorn; | ||
| case LEFT -> leftHorn; | ||
| case RIGHT -> rightHorn; | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return switch (goatHorn) { | ||
| case ANY -> "a horn"; | ||
| case BOTH -> "both horns"; | ||
| case LEFT -> "left horn"; | ||
| case RIGHT -> "right horn"; | ||
| }; | ||
| } | ||
|
|
||
| } | ||
47 changes: 47 additions & 0 deletions
47
src/main/java/ch/njol/skript/conditions/CondIsScreaming.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 ch.njol.skript.conditions; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.conditions.base.PropertyCondition; | ||
| import ch.njol.skript.doc.*; | ||
| import org.bukkit.entity.Enderman; | ||
| import org.bukkit.entity.Goat; | ||
| import org.bukkit.entity.LivingEntity; | ||
|
|
||
| @Name("Is Screaming") | ||
| @Description("Check whether a goat or enderman is screaming.") | ||
| @Example(""" | ||
| if last spawned goat is not screaming: | ||
| make last spawned goat scream | ||
| """ | ||
| ) | ||
| @Example(""" | ||
| if {_enderman} is screaming: | ||
| force {_enderman} to stop screaming | ||
| """ | ||
| ) | ||
| @RequiredPlugins("Paper (endermen)") | ||
| @Since("INSERT VERSION") | ||
| public class CondIsScreaming extends PropertyCondition<LivingEntity> { | ||
|
|
||
| private static final boolean SUPPORTS_ENDERMAN = Skript.methodExists(Enderman.class, "isScreaming"); | ||
|
|
||
| static { | ||
| register(CondIsScreaming.class, "screaming", "livingentities"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(LivingEntity entity) { | ||
| if (entity instanceof Goat goat) { | ||
| return goat.isScreaming(); | ||
| } else if (SUPPORTS_ENDERMAN && entity instanceof Enderman enderman) { | ||
| return enderman.isScreaming(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return "screaming"; | ||
| } | ||
|
|
||
| } |
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,87 @@ | ||
| package ch.njol.skript.effects; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| 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.util.Kleenean; | ||
| import org.bukkit.entity.Goat; | ||
| import org.bukkit.entity.LivingEntity; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Name("Goat Horns") | ||
| @Description("Make a goat have or not have a left, right, or both horns.") | ||
| @Examples({ | ||
| "remove the left horn of last spawned goat", | ||
| "regrow {_goat}'s horns", | ||
| "remove both horns of all goats" | ||
| }) | ||
| @Since("INSERT VERSION") | ||
| public class EffGoatHorns extends Effect { | ||
|
Absolutionism marked this conversation as resolved.
|
||
|
|
||
| public enum GoatHorn { | ||
| LEFT, RIGHT, BOTH, ANY | ||
| } | ||
|
|
||
| static { | ||
| Skript.registerEffect(EffGoatHorns.class, | ||
| "remove [the] (left horn[s]|right:right horn[s]|both:both horns) of %livingentities%", | ||
| "remove %livingentities%'[s] (left horn[s]|right:right horn[s]|both:horns)", | ||
| "(regrow|replace) [the] (left horn[s]|right:right horn[s]|both:both horns) of %livingentities%", | ||
| "(regrow|replace) %livingentities%'[s] (left horn[s]|right:right horn[s]|both:horns)"); | ||
| } | ||
|
|
||
| private Expression<LivingEntity> entities; | ||
| private GoatHorn goatHorn = GoatHorn.LEFT; | ||
| private boolean remove; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| if (parseResult.hasTag("right")) { | ||
| goatHorn = GoatHorn.RIGHT; | ||
| } else if (parseResult.hasTag("both")) { | ||
| goatHorn = GoatHorn.BOTH; | ||
| } | ||
| //noinspection unchecked | ||
| entities = (Expression<LivingEntity>) exprs[0]; | ||
| remove = matchedPattern <= 1; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected void execute(Event event) { | ||
| for (LivingEntity entity : entities.getArray(event)) { | ||
| if (entity instanceof Goat goat) { | ||
| if (goatHorn != GoatHorn.RIGHT) | ||
| goat.setLeftHorn(remove); | ||
| if (goatHorn != GoatHorn.LEFT) | ||
| goat.setRightHorn(remove); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); | ||
| if (remove) { | ||
| builder.append("remove"); | ||
| } else { | ||
| builder.append("regrow"); | ||
| } | ||
| builder.append(switch (goatHorn) { | ||
| case LEFT -> "the left horn"; | ||
| case RIGHT -> "the right horn"; | ||
| case BOTH -> "both horns"; | ||
| case ANY -> "any horn"; | ||
| }); | ||
| builder.append("of", entities); | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package ch.njol.skript.effects; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.doc.*; | ||
| import ch.njol.skript.lang.Effect; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.entity.Goat; | ||
| import org.bukkit.entity.LivingEntity; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Name("Make Goat Ram") | ||
| @Description({ | ||
| "Make a goat ram an entity.", | ||
| "Ramming does have a cooldown and currently no way to change it." | ||
| }) | ||
| @Examples("make all goats ram player") | ||
| @RequiredPlugins("Paper") | ||
| @Since("INSERT VERSION") | ||
| public class EffGoatRam extends Effect { | ||
|
|
||
| static { | ||
| if (Skript.methodExists(Goat.class, "ram", LivingEntity.class)) | ||
| Skript.registerEffect(EffGoatRam.class, | ||
| "make %livingentities% ram %livingentity%", | ||
| "force %livingentities% to ram %livingentity%"); | ||
| } | ||
|
|
||
| private Expression<LivingEntity> entities; | ||
| private Expression<LivingEntity> target; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| //noinspection unchecked | ||
| entities = (Expression<LivingEntity>) exprs[0]; | ||
| //noinspection unchecked | ||
| target = (Expression<LivingEntity>) exprs[1]; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected void execute(Event event) { | ||
| LivingEntity target = this.target.getSingle(event); | ||
| if (target == null) | ||
| return; | ||
| for (LivingEntity entity : entities.getArray(event)) { | ||
| if (entity instanceof Goat goat) { | ||
| goat.ram(target); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return "make " + entities.toString(event, debug) + " ram " + target.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package ch.njol.skript.effects; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.doc.*; | ||
| import ch.njol.skript.lang.Effect; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.entity.Enderman; | ||
| import org.bukkit.entity.Goat; | ||
| import org.bukkit.entity.LivingEntity; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Name("Make Entity Scream") | ||
| @Description("Make a goat or enderman start or stop screaming.") | ||
| @Example(""" | ||
| make last spawned goat start screaming | ||
| force last spawned goat to stop screaming | ||
| """ | ||
| ) | ||
| @Example(""" | ||
| make {_enderman} scream | ||
| force {_enderman} to stop screaming | ||
| """ | ||
| ) | ||
| @RequiredPlugins("Paper (endermen)") | ||
| @Since("INSERT VERSION") | ||
| public class EffScreaming extends Effect { | ||
|
|
||
| private static final boolean SUPPORTS_ENDERMAN = Skript.methodExists(Enderman.class, "setScreaming", boolean.class); | ||
|
|
||
| static { | ||
| Skript.registerEffect(EffScreaming.class, | ||
| "make %livingentities% (start screaming|scream)", | ||
| "force %livingentities% to (start screaming|scream)", | ||
| "make %livingentities% stop screaming", | ||
| "force %livingentities% to stop screaming"); | ||
| } | ||
|
|
||
| private Expression<LivingEntity> entities; | ||
| private boolean scream; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| //noinspection unchecked | ||
| entities = (Expression<LivingEntity>) exprs[0]; | ||
| scream = matchedPattern <= 1; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected void execute(Event event) { | ||
| for (LivingEntity entity : entities.getArray(event)) { | ||
| if (entity instanceof Goat goat) { | ||
| goat.setScreaming(scream); | ||
| } else if (SUPPORTS_ENDERMAN && entity instanceof Enderman enderman) { | ||
| enderman.setScreaming(scream); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return "make " + entities.toString(event, debug) + (scream ? " start " : " stop ") + "screaming"; | ||
| } | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
src/test/java/org/skriptlang/skript/test/tests/syntaxes/effects/EffGoatHornsTest.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,31 @@ | ||
| package org.skriptlang.skript.test.tests.syntaxes.effects; | ||
|
|
||
| import ch.njol.skript.test.runner.SkriptJUnitTest; | ||
| import org.bukkit.Bukkit; | ||
| import org.bukkit.entity.Goat; | ||
| import org.bukkit.event.block.BlockBreakEvent; | ||
| import org.bukkit.event.world.WorldLoadEvent; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class EffGoatHornsTest extends SkriptJUnitTest { | ||
|
|
||
| static { | ||
| setShutdownDelay(10); | ||
| } | ||
|
|
||
| private Goat goat; | ||
|
|
||
| @Test | ||
| public void test() { | ||
| goat = getTestWorld().spawn(getTestWorld().getSpawnLocation(), Goat.class); | ||
| } | ||
|
|
||
| @After | ||
| public void after() { | ||
| if (goat != null) | ||
| goat.remove(); | ||
| } | ||
|
|
||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.