2017-11-15 20:14:06 +00:00
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 ch.njol.skript.lang.Expression ;
import ch.njol.skript.lang.SkriptParser.ParseResult ;
import ch.njol.skript.lang.util.SimpleExpression ;
import ch.njol.util.Kleenean ;
2023-03-08 15:33:41 +00:00
import io.github.bi0qaw.biosphere.util.LocationLib ;
import org.bukkit.Location ;
import org.bukkit.event.Event ;
import org.jetbrains.annotations.Nullable ;
2017-11-15 20:14:06 +00:00
@Name ( " Location Link All " )
@Description ( " Creates a list of locations linking multiple locations with lines. The density value controls the amount of points. A higher number increases the amount of points. A density of 1 corresponds to 1 point per block. " )
@Examples ( { " set {_circle::*} to circle at player with radius 5 and density 0.2 " ,
" #gets the points in the shape of a circle around the player " ,
" set {_linked::*} to {_circle::*} linked with density 2 " ,
" #connects all points on the circle with lines " ,
" show happy villager at {_linked::*} " } )
public class ExprLocationLinkAll extends SimpleExpression < Location > {
private Expression < Location > locations ;
private Expression < Number > density ;
@Override
public Class < ? extends Location > 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 < Location > ) expr [ 0 ] ;
density = ( Expression < Number > ) expr [ 1 ] ;
return true ;
}
@Override
public String toString ( @Nullable Event arg0 , boolean arg1 ) {
return locations . toString ( arg0 , arg1 ) + " linked with density " + density . toString ( arg0 , arg1 ) ;
}
@Override
@Nullable
protected Location [ ] get ( Event e ) {
double d = density . getSingle ( e ) . doubleValue ( ) ;
return LocationLib . linkAll ( locations . getArray ( e ) , d ) ;
}
}