Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

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?

})
@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
Copy link
Member

Choose a reason for hiding this comment

The 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";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

}
Copy link
Member

Choose a reason for hiding this comment

The 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"
Copy link
Member

Choose a reason for hiding this comment

The 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> {
Copy link
Member

Choose a reason for hiding this comment

The 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())
Copy link
Member

Choose a reason for hiding this comment

The 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 {
Copy link
Member

Choose a reason for hiding this comment

The 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();
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}

}
Copy link
Member

Choose a reason for hiding this comment

The 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"
Copy link
Member

Choose a reason for hiding this comment

The 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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
register(ExprInteractionResponsiveness.class, Boolean.class, "interaction Responsiveness[es]", "entities");
register(ExprInteractionResponsiveness.class, Boolean.class, "interaction responsiveness", "entities");

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
Copy link
Member

Choose a reason for hiding this comment

The 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;
}
}
Loading