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 LocationUtil#getSafeDestination NSME on older versions #4708

Merged
merged 3 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.earth2me.essentials.utils;

import com.earth2me.essentials.IEssentials;
import com.google.common.primitives.Ints;
import net.ess3.api.IUser;
import org.bukkit.GameMode;
import org.bukkit.Location;
Expand Down Expand Up @@ -232,12 +231,12 @@ public static Location getSafeDestination(IEssentials ess, final Location loc) t
i++;
if (i >= VOLUME.length) {
x = origX;
y = Ints.constrainToRange(origY + RADIUS, worldMinY, worldMaxY);
y = NumberUtil.constrainToRange(origY + RADIUS, worldMinY, worldMaxY);
z = origZ;
break;
}
x = origX + VOLUME[i].x;
y = Ints.constrainToRange(origY + VOLUME[i].y, worldMinY, worldMaxY);
y = NumberUtil.constrainToRange(origY + VOLUME[i].y, worldMinY, worldMaxY);
z = origZ + VOLUME[i].z;
}
while (isBlockUnsafe(ess, world, x, y, z)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,11 @@ public static boolean isPositiveInt(final String sInt) {
}
return Integer.parseInt(sInt) > 0;
}

/**
* Backport from Guava.
*/
public static int constrainToRange(int value, int min, int max) {
return Math.min(Math.max(value, min), max);
}
}