-
-
Notifications
You must be signed in to change notification settings - Fork 446
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
6
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.
Open
Changes from all commits
Commits
Show all changes
6 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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| 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 ch.njol.skript.registrations.EventConverter; | ||
| import ch.njol.skript.registrations.EventValues; | ||
| import io.papermc.paper.event.entity.EntityLungeEvent; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public class EvtEntityLunge extends SkriptEvent { | ||
|
|
||
| @Nullable | ||
| private Literal<EntityType> entityTypes; | ||
|
|
||
| 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.", | ||
| "Either by using a spear enchanted with the lunge enchantment (e.g. players, skeletons)", | ||
| "or because of a mob's natural lunge attack (e.g. ravagers).", | ||
| "Lunge attack propels entity forward horizontally.") | ||
| .examples("on lunge:", | ||
| "\tset lunge power to 4", | ||
| "on ravager lunge:", | ||
| "\tcancel event" | ||
| ) | ||
| .since("INSERT VERSION"); | ||
|
|
||
| EventValues.registerEventValue(EntityLungeEvent.class, Integer.class, new EventConverter<>() { | ||
| @Override | ||
| public void set(EntityLungeEvent event, Integer value) { | ||
| event.setLungePower(value); | ||
| } | ||
|
|
||
| @Override | ||
| public Integer convert(EntityLungeEvent event) { | ||
| return event.getLungePower(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) { | ||
| entityTypes = (Literal<EntityType>) args[0]; | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean check(Event event) { | ||
| if (!(event instanceof EntityLungeEvent lungeEvent)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (entityTypes == null) { | ||
| return true; | ||
| } | ||
|
|
||
| for (EntityType entityType : entityTypes.getAll()) { | ||
| if (entityType.isInstance(lungeEvent.getEntity())) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| SyntaxStringBuilder builder = new SyntaxStringBuilder(event, debug); | ||
| if (entityTypes != null) { | ||
| builder.append(entityTypes).append(" "); | ||
| } | ||
| builder.append("lunge"); | ||
| return builder.toString(); | ||
| } | ||
|
|
||
| } | ||
104 changes: 104 additions & 0 deletions
104
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,104 @@ | ||
| 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.expressions.base.EventValueExpression; | ||
| import ch.njol.skript.expressions.base.WrapperExpression; | ||
| import ch.njol.skript.lang.*; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| 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)."}) | ||
| @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 WrapperExpression<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"); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
| if (exprs.length != 0) { | ||
| return false; | ||
| } | ||
|
|
||
| setExpr(new EventValueExpression<>(Integer.class)); | ||
| return ((EventValueExpression<Integer>) getExpr()).init(); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable Class<?>[] acceptChange(ChangeMode mode) { | ||
| return switch (mode) { | ||
| case SET, ADD, REMOVE -> CollectionUtils.array(Integer.class); | ||
| default -> null; | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void change(Event event, @Nullable Object[] delta, ChangeMode mode) { | ||
| int deltaValue = delta != null ? (Integer) delta[0] : 0; | ||
| int currentValue = (Integer) getExpr().getSingle(event); | ||
| 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; | ||
|
|
||
| super.getExpr().change(event, CollectionUtils.array(newValue), ChangeMode.SET); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Event>[] supportedEvents() { | ||
| return CollectionUtils.array(EntityLungeEvent.class); | ||
| } | ||
|
|
||
| @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"; | ||
| } | ||
|
|
||
| } |
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,17 @@ | ||
| { | ||
| "name": "paper-26.1.2", | ||
| "resources": [ | ||
| {"source": "server.properties.generic", "target": "server.properties"} | ||
| ], | ||
| "paperDownloads": [ | ||
| { | ||
| "version": "26.1.2", | ||
| "target": "paperclip.jar" | ||
| } | ||
| ], | ||
| "skriptTarget": "plugins/Skript.jar", | ||
| "commandLine": [ | ||
| "-Dcom.mojang.eula.agree=true", | ||
| "-jar", "paperclip.jar", "--nogui" | ||
| ] | ||
| } |
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.