-
-
Notifications
You must be signed in to change notification settings - Fork 438
Feature/exprfuseticks #8499
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
Feature/exprfuseticks #8499
Changes from all commits
75ad421
d42e478
f6baaf7
bfb718d
bf1850e
d99420b
33dbaf9
9da96e6
a510817
e692e61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,117 @@ | ||||
| package ch.njol.skript.expressions; | ||||
|
|
||||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||||
| import ch.njol.skript.doc.Description; | ||||
| import ch.njol.skript.doc.Example; | ||||
| import ch.njol.skript.doc.Name; | ||||
| import ch.njol.skript.doc.Since; | ||||
| import ch.njol.skript.expressions.base.SimplePropertyExpression; | ||||
| import ch.njol.skript.lang.Expression; | ||||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||||
| import ch.njol.skript.util.Timespan; | ||||
| import ch.njol.skript.util.Timespan.TimePeriod; | ||||
| import ch.njol.util.Kleenean; | ||||
| import ch.njol.util.coll.CollectionUtils; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.Creeper; | ||||
| import org.bukkit.entity.TNTPrimed; | ||||
| import org.bukkit.event.Event; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
|
|
||||
| @Name("Entity Fuse Duration") | ||||
| @Description("Get or set how long until a Creeper/Primed TNT explodes. For Creepers, the fuse time will be 0 seconds and if set it will be ticking down even if the entity is not currently in exploding animation.") | ||||
| @Example("send \"Run! That guy is going to explode in %fuse ticks of player's target%\"") | ||||
| @Example("send the max fuse ticks of target") | ||||
| @Since("INSERT VERSION") | ||||
| public class ExprFuseTicks extends SimplePropertyExpression<Entity, Timespan> { | ||||
|
|
||||
| static { | ||||
| register(ExprFuseTicks.class, Timespan.class, "[:max[imum]] fuse (duration|length)", "entities"); | ||||
| } | ||||
|
|
||||
| private boolean max; | ||||
|
|
||||
| @Override | ||||
| public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||||
| max = (parseResult.hasTag("max")); | ||||
| return super.init(expressions, matchedPattern, isDelayed, parseResult); | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public @Nullable Timespan convert(Entity entity) { | ||||
| if (entity instanceof Creeper creeper) { | ||||
| return new Timespan(TimePeriod.TICK, (max ? creeper.getMaxFuseTicks() : creeper.getFuseTicks())); | ||||
| } | ||||
| if (entity instanceof TNTPrimed tntprimed) { | ||||
| return new Timespan(TimePeriod.TICK, tntprimed.getFuseTicks()); | ||||
| } | ||||
| return 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.
Suggested change
|
||||
|
|
||||
| @Override | ||||
| public Class<?> @Nullable [] acceptChange(ChangeMode mode) { | ||||
| if (max) { | ||||
| Skript.error("The maximum fuse length of an entity cannot be changed."); | ||||
| return null; | ||||
| } | ||||
| return switch (mode) { | ||||
| case ADD, SET, REMOVE -> CollectionUtils.array(Timespan.class); | ||||
| case RESET, DELETE -> CollectionUtils.array(); | ||||
| default -> null; | ||||
| }; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public void change(Event event, Object @Nullable [] delta, ChangeMode mode) { | ||||
| Entity[] entities = getExpr().getArray(event); | ||||
| int change = delta == null ? 0 : (int) ((Timespan) delta[0]).getAs(Timespan.TimePeriod.TICK); | ||||
| switch (mode) { | ||||
| case REMOVE: | ||||
| change = -change; | ||||
|
|
||||
| case ADD: | ||||
| for (Entity entity : entities) | ||||
| if (entity instanceof Creeper creeper) { | ||||
| creeper.setFuseTicks(creeper.getFuseTicks() + change); | ||||
| } else if (entity instanceof TNTPrimed tntprimed) { | ||||
| tntprimed.setFuseTicks(tntprimed.getFuseTicks() + change); | ||||
|
Comment on lines
+76
to
+78
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. Are there any concerns about setting to negative values or invalid values? if so, a clamp/min/max is needed. |
||||
| } | ||||
|
|
||||
| break; | ||||
| case SET: | ||||
| for (Entity entity : entities) | ||||
| if (entity instanceof Creeper creeper) { | ||||
| creeper.setMaxFuseTicks(change); | ||||
| creeper.setFuseTicks(change); | ||||
|
Comment on lines
+85
to
+86
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. Why are we setting the max here? I thought the max couldn't be changed?
Author
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. it appears it can be changed https://jd.papermc.io/paper/1.21.11/org/bukkit/entity/Creeper.html#setMaxFuseTicks(int)
Author
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. it may not be needed but I think it is
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. well right now every time i try to set the max, it will error. Then when i set the normal fuse time, it will change both normal and max? Shouldn't which one it sets be dependent on which syntax I used? |
||||
| } else if (entity instanceof TNTPrimed tntprimed) { | ||||
| tntprimed.setFuseTicks(change); | ||||
| } | ||||
| break; | ||||
|
|
||||
| case DELETE: | ||||
| case RESET: | ||||
| for (Entity entity : entities) | ||||
| if (entity instanceof Creeper creeper) { | ||||
| creeper.setFuseTicks(creeper.getMaxFuseTicks()); | ||||
| } else if (entity instanceof TNTPrimed tntprimed) { | ||||
| tntprimed.setFuseTicks(80); | ||||
| } | ||||
|
|
||||
| break; | ||||
| default: | ||||
| assert false; | ||||
| } | ||||
| } | ||||
|
|
||||
| @Override | ||||
| public Class<Timespan> getReturnType() { | ||||
| return Timespan.class; | ||||
| } | ||||
|
|
||||
| @Override | ||||
| protected String getPropertyName() { | ||||
| return "fuse duration"; | ||||
| } | ||||
|
|
||||
| } | ||||
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.
not a valid example according to the syntax pattern