Fixed random number generation

This commit is contained in:
Auxilor 2020-12-31 13:54:08 +00:00
parent b1aec93025
commit a1c92898ea
2 changed files with 5 additions and 11 deletions

View File

@ -221,8 +221,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
try {
event.getOffers()[2].setCost(NumberUtils.equalIfOver(event.getOffers()[2].getCost(), maxLevel));
} catch (ArrayIndexOutOfBoundsException | NullPointerException ignored) {
}
} catch (ArrayIndexOutOfBoundsException | NullPointerException ignored) { }
if (!SECONDARY_ENCHANTABLE.contains(event.getItem().getType())) {
return;
@ -236,7 +235,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
bonus = 1;
}
double baseLevel = (NumberUtils.randInt(1, 8) + Math.floor((double) bonus / 2) + NumberUtils.randInt(0, bonus));
double baseLevel = NumberUtils.randInt(1, 8) + Math.floor((double) bonus / 2) + NumberUtils.randInt(0, bonus);
int bottomEnchantLevel = (int) Math.ceil(Math.max(baseLevel / 3, 1));
int midEnchantLevel = (int) ((baseLevel * 2) / 3) + 1;

View File

@ -3,16 +3,11 @@ package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import java.text.DecimalFormat;
import java.util.Random;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;
@UtilityClass
public class NumberUtils {
/**
* The RNG to use.
*/
private static final Random RANDOM = new Random();
/**
* Set of roman numerals to look up.
*/
@ -99,7 +94,7 @@ public class NumberUtils {
*/
public int randInt(final int min,
final int max) {
return (int) ((long) min + RANDOM.nextInt() * ((long) max - min + 1));
return ThreadLocalRandom.current().nextInt(min, max + 1);
}
/**
@ -111,7 +106,7 @@ public class NumberUtils {
*/
public double randFloat(final double min,
final double max) {
return RANDOM.nextFloat() * (max - min) + min;
return ThreadLocalRandom.current().nextDouble(min, max);
}
/**