Move math method to new NumberUtils class

This commit is contained in:
Bea 2021-01-10 00:48:10 +01:00
parent b45f7f5a8f
commit ea061e55e6
3 changed files with 22 additions and 14 deletions

View File

@ -4,6 +4,8 @@
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.idea/dictionaries" />
<excludeFolder url="file://$MODULE_DIR$/.idea/libraries" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

View File

@ -5,6 +5,7 @@ import net.mindoverflow.network.uhccore.utils.CommonValues;
import net.mindoverflow.network.uhccore.utils.ConfigEntries; import net.mindoverflow.network.uhccore.utils.ConfigEntries;
import net.mindoverflow.network.uhccore.utils.Debugger; import net.mindoverflow.network.uhccore.utils.Debugger;
import net.mindoverflow.network.uhccore.utils.FileUtils; import net.mindoverflow.network.uhccore.utils.FileUtils;
import net.mindoverflow.network.uhccore.utils.math.NumberUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -47,9 +48,9 @@ public class StartUhcCommand {
for(int i = 0; i < CommonValues.totalTeams; i++) for(int i = 0; i < CommonValues.totalTeams; i++)
{ {
double x = getRandomNumberInRange(borderX - range + 1, borderX + range - 1) + 0.5; double x = NumberUtils.getRandomNumberInRange(borderX - range + 1, borderX + range - 1) + 0.5;
double z = getRandomNumberInRange(borderZ - range + 1, borderZ + range - 1) + 0.5; double z = NumberUtils.getRandomNumberInRange(borderZ - range + 1, borderZ + range - 1) + 0.5;
int y = spawnWorld.getHighestBlockYAt((int) x, (int) z); int y = spawnWorld.getHighestBlockYAt((int) x, (int) z); // todo: this method is shit, ushe the one i already implemented in Factions...
Location loc = new Location(spawnWorld, x, y + 1, z); Location loc = new Location(spawnWorld, x, y + 1, z);
@ -119,15 +120,4 @@ public class StartUhcCommand {
}); });
} }
private static int getRandomNumberInRange(int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
} }

View File

@ -0,0 +1,16 @@
package net.mindoverflow.network.uhccore.utils.math;
import java.util.Random;
public class NumberUtils {
public static int getRandomNumberInRange(int min, int max) {
if (min >= max) {
throw new IllegalArgumentException("max must be greater than min");
}
Random r = new Random();
return r.nextInt((max - min) + 1) + min;
}
}