Skip to content

Commit

Permalink
Fix location function without world arg (#4238)
Browse files Browse the repository at this point in the history
  • Loading branch information
TPGamesNL authored Aug 30, 2021
1 parent afc6c28 commit d967c55
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import java.util.Calendar;

import ch.njol.skript.lang.function.FunctionEvent;
import ch.njol.skript.lang.function.JavaFunction;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
Expand All @@ -37,6 +39,7 @@
import ch.njol.util.Math2;
import ch.njol.util.StringUtils;
import ch.njol.util.coll.CollectionUtils;
import org.eclipse.jdt.annotation.Nullable;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -311,7 +314,7 @@ public World[] executeSimple(Object[][] params) {

// the location expression doesn't work, so why not make a function for the same purpose
// FIXME document on ExprLocation as well
Functions.registerFunction(new SimpleJavaFunction<Location>("location", new Parameter[] {
Functions.registerFunction(new JavaFunction<Location>("location", new Parameter[] {
new Parameter<>("x", DefaultClasses.NUMBER, true, null),
new Parameter<>("y", DefaultClasses.NUMBER, true, null),
new Parameter<>("z", DefaultClasses.NUMBER, true, null),
Expand All @@ -320,9 +323,15 @@ public World[] executeSimple(Object[][] params) {
new Parameter<>("pitch", DefaultClasses.NUMBER, true, new SimpleLiteral<Number>(0, true))
}, DefaultClasses.LOCATION, true) {
@Override
public Location[] executeSimple(Object[][] params) {
@Nullable
public Location[] execute(FunctionEvent<?> e, Object[][] params) {
for (int i : new int[] {0, 1, 2, 4, 5}) {
if (params[i] == null || params[i].length == 0 || params[i][0] == null)
return null;
}

World world = params[3].length == 1 ? (World) params[3][0] : Bukkit.getWorlds().get(0); // fallback to main world of server

return new Location[] {new Location(world,
((Number) params[0][0]).doubleValue(), ((Number) params[1][0]).doubleValue(), ((Number) params[2][0]).doubleValue(),
((Number) params[4][0]).floatValue(), ((Number) params[5][0]).floatValue())};
Expand Down

0 comments on commit d967c55

Please sign in to comment.