diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index 442e9b42..e5eb7e9f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -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; diff --git a/eco-util/src/main/java/com/willfp/eco/util/NumberUtils.java b/eco-util/src/main/java/com/willfp/eco/util/NumberUtils.java index e154abec..23e57a75 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/NumberUtils.java +++ b/eco-util/src/main/java/com/willfp/eco/util/NumberUtils.java @@ -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); } /**