-
-
Notifications
You must be signed in to change notification settings - Fork 449
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
base: dev/feature
Are you sure you want to change the base?
Changes from all commits
a30461f
fdc75a7
0252bb1
3466f83
2e6f17d
2e1aca7
b6a38ce
6f0567f
a419278
c64a3b8
7b6a43a
c017d99
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,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 | ||||||||||
|
Comment on lines
+29
to
+30
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.
Suggested change
to avoid confusion with ravager attack |
||||||||||
| """ | ||||||||||
| ) | ||||||||||
| .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(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,108 @@ | ||||||||
| 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). | ||||||||
| """) | ||||||||
| @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"); | ||||||||
|
Comment on lines
+43
to
+44
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. should use new registration |
||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| @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) { | ||||||||
| if (event instanceof EntityLungeEvent lungeEvent) | ||||||||
| { | ||||||||
|
Comment on lines
+60
to
+61
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.
Suggested change
|
||||||||
| return new Integer[]{lungeEvent.getLungePower()}; | ||||||||
| } | ||||||||
| return new Integer[0]; | ||||||||
| } | ||||||||
|
|
||||||||
| @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) { | ||||||||
| if (!(event instanceof EntityLungeEvent lungeEvent)) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| int deltaValue = delta == null ? 0 : (int) delta[0]; | ||||||||
| int currentValue = lungeEvent.getLungePower(); | ||||||||
| int newValue = switch (mode) { | ||||||||
| case SET -> deltaValue; | ||||||||
| case ADD -> currentValue + deltaValue; | ||||||||
| case REMOVE -> currentValue - deltaValue; | ||||||||
| default -> throw new UnsupportedOperationException("Unsupported change mode: " + mode); | ||||||||
| }; | ||||||||
|
|
||||||||
| lungeEvent.setLungePower(newValue); | ||||||||
| } | ||||||||
|
|
||||||||
| @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"; | ||||||||
| } | ||||||||
|
|
||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.