package io.github.bi0qaw.biosphere.expression; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; import io.github.bi0qaw.biosphere.util.LocationLib; import io.github.bi0qaw.biosphere.util.VectorLib; import org.bukkit.Location; import org.bukkit.event.Event; import javax.annotation.Nullable; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.util.SimpleExpression; import ch.njol.util.Kleenean; import org.bukkit.util.Vector; @Name("Location Cube") @Description("Creates a list of locations in the shape of a cube (only the corners!). To get a list of locations including the cube edges use cube outline.") @Examples("show happy villager at cube at player's head with radius 1") public class ExprLocationCube extends SimpleExpression{ private Expression locations; private Expression radius; @Override public Class getReturnType() { return Location.class; } @Override public boolean isSingle() { return false; } @SuppressWarnings("unchecked") @Override public boolean init(Expression[] expr, int arg1, Kleenean arg2, ParseResult arg3) { locations = (Expression) expr[0]; radius = (Expression) expr[1]; return true; } @Override public String toString(@Nullable Event arg0, boolean arg1) { return "cube at " + locations.toString(arg0, arg1) + " with radius " + radius.toString(arg0, arg1); } @Override @Nullable protected Location[] get(Event e) { double r = radius.getSingle(e).doubleValue(); return LocationLib.getCube(locations.getArray(e), r); } }