Skip to content
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

Fix location function without world arg #4238

Merged
Merged
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
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