Fix LocationUtil#getSafeDestination NSME on older versions (#4708)

Fixes a NoSuchMethodError from old guava versions in old MC versions.

Fixes #4703
This commit is contained in:
Josh Roy 2021-12-23 06:55:31 -05:00 committed by GitHub
parent 685084219e
commit 84326cf13e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -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;
@ -232,12 +231,12 @@ public final class LocationUtil {
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)) {

View File

@ -119,4 +119,11 @@ public final class NumberUtil {
}
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);
}
}