-
-
Notifications
You must be signed in to change notification settings - Fork 447
Add EvtEntityLunge and ExprLungePower #8649
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
vuxeim
wants to merge
12
commits into
SkriptLang:dev/feature
Choose a base branch
from
vuxeim:feature/lunge
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.
+177
−0
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a30461f
chore: bump to 26.1.2
vuxeim fdc75a7
feat: add lunge event
vuxeim 0252bb1
refactor: applying suggested changes
vuxeim 3466f83
refactor: apply two suggestions
vuxeim 2e6f17d
fix: allow optional entitytype
vuxeim 2e1aca7
feat: add/remove syntax for ExprLungePower
vuxeim b6a38ce
Merge branch 'dev/feature' into feature/lunge
vuxeim 6f0567f
apply suggestions, use SimpleExpression
vuxeim a419278
corrected misleading description
vuxeim c64a3b8
Merge branch 'dev/feature' into feature/lunge
APickledWalrus 7b6a43a
refactor: apply suggestions
vuxeim c017d99
possibly the final refactor
vuxeim 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,69 @@ | ||
| 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.lang.SyntaxStringBuilder; | ||
| import io.papermc.paper.event.entity.EntityLungeEvent; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public class EvtEntityLunge extends SkriptEvent { | ||
|
|
||
| static { | ||
| // Since paper 26.1.2 | ||
| if (Skript.classExists("io.papermc.paper.event.entity.EntityLungeEvent")) { | ||
| Skript.registerEvent("Entity Lunge", EvtEntityLunge.class, EntityLungeEvent.class, "[%-entitytypes%] lunge") | ||
| .description("Called when an entity lunges.", | ||
| "Entity can perform lunge attack when holding a spear enchanted with the lunge enchantment.", | ||
| "Lunge attack propels entity forward horizontally.") | ||
| .examples( | ||
| """ | ||
| on lunge: | ||
| set lunge power to 4 | ||
| """, | ||
| """ | ||
| on ravager lunge: | ||
| cancel event | ||
| """ | ||
| ) | ||
| .since("INSERT VERSION"); | ||
| } | ||
| } | ||
|
|
||
| private @Nullable Literal<EntityType> entityTypes; | ||
|
|
||
| @Override | ||
| public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||
| entityTypes = (Literal<EntityType>) args[0]; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Event event) { | ||
| if (entityTypes == null) { | ||
| return true; | ||
| } | ||
|
|
||
| EntityLungeEvent lungeEvent = (EntityLungeEvent) event; | ||
|
|
||
| for (EntityType entityType : entityTypes.getAll()) { | ||
| if (entityType.isInstance(lungeEvent.getEntity())) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return new SyntaxStringBuilder(event, debug) | ||
| .appendIf(entityTypes != null, entityTypes) | ||
| .append("lunge") | ||
| .toString(); | ||
| } | ||
|
|
||
| } | ||
106 changes: 106 additions & 0 deletions
106
src/main/java/ch/njol/skript/expressions/ExprLungePower.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,106 @@ | ||
| package ch.njol.skript.expressions; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||
| import ch.njol.skript.doc.*; | ||
| import ch.njol.skript.lang.*; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.util.SimpleExpression; | ||
| import ch.njol.util.Kleenean; | ||
| import ch.njol.util.coll.CollectionUtils; | ||
| import io.papermc.paper.event.entity.EntityLungeEvent; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Name("Lunge Power") | ||
| @Description(""" | ||
| The power of lunge attack. | ||
| Can be set to modify the distance of the lunge attack. | ||
| Initially, the lunge power is determined by the enchantment level of the lunge enchantment | ||
| of the weapon used to perform the lunge attack (e.g. a spear). | ||
|
vuxeim marked this conversation as resolved.
Outdated
|
||
| """) | ||
| @Example(""" | ||
| on skeleton lunge: | ||
| if the lunge power is 1, 2 or 3: | ||
| broadcast "Normal lunge power" | ||
| else if the lunge power is greater than 3: | ||
| broadcast "Overpowered lunge power" | ||
| """) | ||
| @Example(""" | ||
| on lunge: | ||
| set event-lunge power to 5 | ||
| """) | ||
| @Example(""" | ||
| on player lunge: | ||
| if event-entity has slowness: | ||
| remove 1 from lunge power | ||
| send "Slowed you down a bit" | ||
| """) | ||
| @Since("INSERT VERSION") | ||
| public class ExprLungePower extends SimpleExpression<Integer> implements EventRestrictedSyntax { | ||
|
|
||
| static { | ||
| // Since paper 26.1.2 | ||
| if (Skript.classExists("io.papermc.paper.event.entity.EntityLungeEvent")) { | ||
| Skript.registerExpression(ExprLungePower.class, Integer.class, ExpressionType.SIMPLE, "[the] [event-]lunge power"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Event>[] supportedEvents() { | ||
| return CollectionUtils.array(EntityLungeEvent.class); | ||
| } | ||
|
|
||
| @Override | ||
| public Integer[] get(Event event) { | ||
| EntityLungeEvent lungeEvent = (EntityLungeEvent) event; | ||
| return CollectionUtils.array(lungeEvent.getLungePower()); | ||
|
vuxeim marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| @Override | ||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||
| return switch (mode) { | ||
| case SET, ADD, REMOVE -> CollectionUtils.array(Integer.class); | ||
| default -> null; | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||
| int deltaValue = delta != null ? (Integer) delta[0] : 0; | ||
| int currentValue = ((EntityLungeEvent) event).getLungePower(); | ||
|
vuxeim marked this conversation as resolved.
Outdated
|
||
| Integer newValue = switch (mode) { | ||
| case SET -> deltaValue; | ||
| case ADD -> currentValue + deltaValue; | ||
| case REMOVE -> currentValue - deltaValue; | ||
| default -> null; | ||
| }; | ||
|
|
||
| // It isn't null because the change mode is guaranteed to be either SET, ADD or REMOVE | ||
| assert newValue != null; | ||
|
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. You could also just throw an exception in the default case to avoid having to assert |
||
|
|
||
| EntityLungeEvent lungeEvent = (EntityLungeEvent) event; | ||
| lungeEvent.setLungePower(newValue); | ||
|
vuxeim marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean isSingle() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<Integer> getReturnType() { | ||
| return Integer.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return "lunge power"; | ||
| } | ||
|
|
||
| } | ||
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.