-
-
Notifications
You must be signed in to change notification settings - Fork 416
Adds interaction entity syntaxes #8291
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
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,12 @@ | ||
| package org.skriptlang.skript.bukkit.interactions; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class InteractionModule { | ||
|
|
||
| public static void load() throws IOException { | ||
| Skript.getAddonInstance().loadClasses("org.skriptlang.skript.bukkit.interactions", "elements"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||
| package org.skriptlang.skript.bukkit.interactions.elements.conditions; | ||||||||
|
|
||||||||
| import ch.njol.skript.conditions.base.PropertyCondition; | ||||||||
| 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.SkriptParser; | ||||||||
| import ch.njol.skript.lang.Expression; | ||||||||
| import ch.njol.util.Kleenean; | ||||||||
| import org.bukkit.entity.Entity; | ||||||||
| import org.bukkit.entity.Interaction; | ||||||||
|
|
||||||||
| @Name("Is Responsive") | ||||||||
| @Description({ | ||||||||
| "Checks whether an interaction entity is responsive" | ||||||||
| }) | ||||||||
| @Examples({ | ||||||||
| "if last spawned interaction is responsive:", "if last spawned interaction is unresponsive:" | ||||||||
| }) | ||||||||
| @Since("INSERT VERSION") | ||||||||
| public class CondIsResponsive extends PropertyCondition<Entity> { | ||||||||
|
|
||||||||
| static { | ||||||||
| register(CondIsResponsive.class, "(responsive|1¦unresponsive)", "entities"); | ||||||||
| } | ||||||||
|
|
||||||||
| private boolean isNegated; | ||||||||
|
|
||||||||
| @Override | ||||||||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||||||||
| isNegated = parseResult.mark == 1; | ||||||||
| return super.init(exprs, matchedPattern, isDelayed, parseResult); | ||||||||
|
Comment on lines
+32
to
+33
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. isnegated is going to be overridden here by the propertycondition init() |
||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| public boolean check(Entity entity) { | ||||||||
| if (entity instanceof Interaction i) { | ||||||||
| return !isNegated == i.isResponsive(); | ||||||||
| } | ||||||||
| return false; | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| protected String getPropertyName() { | ||||||||
| return isNegated ? "unresponsive" : "responsive"; | ||||||||
| } | ||||||||
|
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
|
||||||||
| } | ||||||||
|
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
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||||
| package org.skriptlang.skript.bukkit.interactions.elements.expressions; | ||||||||
|
|
||||||||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||||||||
| 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.expressions.base.SimplePropertyExpression; | ||||||||
| import org.bukkit.entity.Entity; | ||||||||
| import org.bukkit.entity.Interaction; | ||||||||
| import org.bukkit.event.Event; | ||||||||
| import org.jetbrains.annotations.Nullable; | ||||||||
|
|
||||||||
|
|
||||||||
| @Name("Interaction Height") | ||||||||
| @Description({ | ||||||||
| "Returns the interaction height of an interaction entity" | ||||||||
|
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. explain what the interaction height is |
||||||||
| }) | ||||||||
| @Examples({ | ||||||||
| "set interaction height of last spawned interaction to 5.3" | ||||||||
| }) | ||||||||
| @Since("INSERT VERSION") | ||||||||
| public class ExprInteractionHeight extends SimplePropertyExpression<Entity, Number> { | ||||||||
|
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. this should probably be a type property but that edit can be done in a later pr that adds the property |
||||||||
|
|
||||||||
| static { | ||||||||
| register(ExprInteractionHeight.class, Number.class, "interaction height[s]", "entities"); | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| public @Nullable Number convert(Entity interaction) { | ||||||||
| if (interaction instanceof Interaction i) { | ||||||||
| return i.getInteractionHeight(); | ||||||||
| } | ||||||||
|
|
||||||||
| return null; | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| protected String getPropertyName() { | ||||||||
| return "interaction height"; | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| public Class<? extends Number> getReturnType() { | ||||||||
| return Number.class; | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| @Nullable | ||||||||
| public Class<?>[] acceptChange(final ChangeMode mode) { | ||||||||
| if ((mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.RESET) | ||||||||
| && getExpr().isSingle()) | ||||||||
|
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 single only |
||||||||
| return new Class[] {Number.class}; | ||||||||
| return null; | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException { | ||||||||
|
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. needs updating to modern standards |
||||||||
| assert !(getExpr().getSingle(e) instanceof Interaction) || delta != null; | ||||||||
| final Interaction i = (Interaction) getExpr().getSingle(e); | ||||||||
| if (i == null) | ||||||||
| return; | ||||||||
| float n = ((Number) delta[0]).floatValue(); | ||||||||
|
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. use full variable names please |
||||||||
| switch (mode) { | ||||||||
| case REMOVE: | ||||||||
| i.setInteractionHeight(i.getInteractionHeight() - n); | ||||||||
| break; | ||||||||
| case ADD: | ||||||||
| i.setInteractionHeight(i.getInteractionHeight() + n); | ||||||||
| break; | ||||||||
| case SET: | ||||||||
| i.setInteractionHeight(n); | ||||||||
| break; | ||||||||
| case RESET: | ||||||||
| i.setInteractionHeight(1.0f); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| } | ||||||||
|
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
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||
| package org.skriptlang.skript.bukkit.interactions.elements.expressions; | ||||||
|
|
||||||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||||||
| 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.expressions.base.SimplePropertyExpression; | ||||||
| import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Interaction; | ||||||
| import org.bukkit.event.Event; | ||||||
| import org.jetbrains.annotations.Nullable; | ||||||
|
|
||||||
| @Name("Interaction Responsiveness") | ||||||
| @Description({ | ||||||
| "Returns the responsiveness of an interaction entity" | ||||||
|
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. what's responsiveness |
||||||
| }) | ||||||
| @Examples({ | ||||||
| "set interaction responsiveness of last spawned interaction to false" | ||||||
| }) | ||||||
| @Since("INSERT VERSION") | ||||||
| public class ExprInteractionResponsiveness extends SimplePropertyExpression<Entity, Boolean> { | ||||||
|
|
||||||
| static { | ||||||
| register(ExprInteractionResponsiveness.class, Boolean.class, "interaction Responsiveness[es]", "entities"); | ||||||
|
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
Should this even be an expression? Seems more appropriate as an effect + condition. |
||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public @Nullable Boolean convert(Entity interaction) { | ||||||
| if (interaction instanceof Interaction i) { | ||||||
| return i.isResponsive(); | ||||||
| } | ||||||
|
|
||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| protected String getPropertyName() { | ||||||
| return "interaction responsiveness"; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public Class<? extends Boolean> getReturnType() { | ||||||
| return Boolean.class; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| @Nullable | ||||||
| public Class<?>[] acceptChange(final ChangeMode mode) { | ||||||
| if ((mode == ChangeMode.SET || mode == ChangeMode.RESET) | ||||||
| && getExpr().isSingle()) | ||||||
| return new Class[] {Boolean.class}; | ||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException { | ||||||
| assert !(getExpr().getSingle(e) instanceof Interaction) || delta != null; | ||||||
| final Interaction i = (Interaction) getExpr().getSingle(e); | ||||||
| if (i == null) | ||||||
| return; | ||||||
|
Comment on lines
+38
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. fix ordering and code quality |
||||||
| Boolean b = ((Boolean) delta[0]); | ||||||
| switch (mode) { | ||||||
| case SET: | ||||||
| i.setResponsive(b); | ||||||
| break; | ||||||
| case RESET: | ||||||
| i.setResponsive(true); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package org.skriptlang.skript.bukkit.interactions.elements.expressions; | ||
|
|
||
| import ch.njol.skript.classes.Changer.ChangeMode; | ||
| 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.expressions.base.SimplePropertyExpression; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.entity.Interaction; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
|
|
||
| @Name("Interaction Width") | ||
| @Description({ | ||
| "Returns the interaction width of an interaction entity" | ||
| }) | ||
| @Examples({ | ||
| "set interaction width of last spawned interaction to 5.3" | ||
| }) | ||
| @Since("INSERT VERSION") | ||
| public class ExprInteractionWidth extends SimplePropertyExpression<Entity, Number> { | ||
|
|
||
| static { | ||
| register(ExprInteractionWidth.class, Number.class, "interaction width[s]", "entities"); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable Number convert(Entity interaction) { | ||
| if (interaction instanceof Interaction i) { | ||
| return i.getInteractionWidth(); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return "interaction width"; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Number> getReturnType() { | ||
| return Number.class; | ||
| } | ||
|
|
||
| @Override | ||
| @Nullable | ||
| public Class<?>[] acceptChange(final ChangeMode mode) { | ||
| if ((mode == ChangeMode.SET || mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.RESET) | ||
| && getExpr().isSingle()) | ||
| return new Class[] {Number.class}; | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException { | ||
| assert !(getExpr().getSingle(e) instanceof Interaction) || delta != null; | ||
| final Interaction i = (Interaction) getExpr().getSingle(e); | ||
| if (i == null) | ||
| return; | ||
| float n = ((Number) delta[0]).floatValue(); | ||
| switch (mode) { | ||
| case REMOVE: | ||
| i.setInteractionWidth(i.getInteractionWidth() - n); | ||
| break; | ||
| case ADD: | ||
| i.setInteractionWidth(i.getInteractionWidth() + n); | ||
| break; | ||
| case SET: | ||
| i.setInteractionWidth(n); | ||
| break; | ||
| case RESET: | ||
| i.setInteractionWidth(1.0f); | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package org.skriptlang.skript.bukkit.interactions.elements.expressions; | ||
|
|
||
| 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.expressions.base.SimplePropertyExpression; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser; | ||
| import ch.njol.skript.util.Date; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.entity.Interaction; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| @Name("Last Interaction Date") | ||
| @Description({ | ||
| "Returns the date of the last attack (left click), or interaction (right click) on an interaction entity" | ||
| }) | ||
| @Examples({ | ||
| "if last interaction date of last spawned interaction < 5 seconds ago" | ||
| }) | ||
| @Since("INSERT VERSION") | ||
| public class ExprLastInteractionDate extends SimplePropertyExpression<Entity, Date> { | ||
|
|
||
| static { | ||
| register(ExprLastInteractionDate.class, Date.class, "last (attack|1¦interaction) date", "entities"); | ||
| } | ||
|
|
||
| private boolean interaction; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
| interaction = parseResult.mark == 1; | ||
| return super.init(exprs, matchedPattern, isDelayed, parseResult); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public @Nullable Date convert(Entity entity) { | ||
| if (entity instanceof Interaction i) { | ||
| if (interaction) { | ||
| return new Date(i.getLastInteraction().getTimestamp()); | ||
| } else { | ||
| return new Date(i.getLastAttack().getTimestamp()); | ||
| } | ||
|
|
||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getPropertyName() { | ||
| return "last attack/interaction date"; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Date> getReturnType() { | ||
| return Date.class; | ||
| } | ||
| } |
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.
responsive to what? what does this mean?