Skip to content

Commit 84326cf

Browse files
authored
Fix LocationUtil#getSafeDestination NSME on older versions (#4708)
Fixes a NoSuchMethodError from old guava versions in old MC versions. Fixes #4703
1 parent 6850842 commit 84326cf

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.earth2me.essentials.utils;
22

33
import com.earth2me.essentials.IEssentials;
4-
import com.google.common.primitives.Ints;
54
import net.ess3.api.IUser;
65
import org.bukkit.GameMode;
76
import org.bukkit.Location;
@@ -232,12 +231,12 @@ public static Location getSafeDestination(IEssentials ess, final Location loc) t
232231
i++;
233232
if (i >= VOLUME.length) {
234233
x = origX;
235-
y = Ints.constrainToRange(origY + RADIUS, worldMinY, worldMaxY);
234+
y = NumberUtil.constrainToRange(origY + RADIUS, worldMinY, worldMaxY);
236235
z = origZ;
237236
break;
238237
}
239238
x = origX + VOLUME[i].x;
240-
y = Ints.constrainToRange(origY + VOLUME[i].y, worldMinY, worldMaxY);
239+
y = NumberUtil.constrainToRange(origY + VOLUME[i].y, worldMinY, worldMaxY);
241240
z = origZ + VOLUME[i].z;
242241
}
243242
while (isBlockUnsafe(ess, world, x, y, z)) {

Essentials/src/main/java/com/earth2me/essentials/utils/NumberUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,11 @@ public static boolean isPositiveInt(final String sInt) {
119119
}
120120
return Integer.parseInt(sInt) > 0;
121121
}
122+
123+
/**
124+
* Backport from Guava.
125+
*/
126+
public static int constrainToRange(int value, int min, int max) {
127+
return Math.min(Math.max(value, min), max);
128+
}
122129
}

0 commit comments

Comments
 (0)