mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
Replaced All Instances of Random With SplittableRandom
SplittableRandom is faster (negligable) than Random and is also able to recursively return new instances of itself for an even more complex pseudo random generator compared to the default Random supplied by Java.
This commit is contained in:
parent
dec35f76e4
commit
eb9759f2d8
@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
@ -27,7 +27,7 @@ public class Command_bird extends FreedomCommand
|
||||
public EntityType getRandomFish()
|
||||
{
|
||||
List<EntityType> fishTypes = Arrays.asList(EntityType.COD, EntityType.SALMON, EntityType.PUFFERFISH, EntityType.TROPICAL_FISH);
|
||||
Random random = new Random();
|
||||
SplittableRandom random = new SplittableRandom();
|
||||
return fishTypes.get(random.nextInt(fishTypes.size()));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
@ -15,7 +15,7 @@ public class Command_deafen extends FreedomCommand
|
||||
{
|
||||
|
||||
public static final double STEPS = 10.0;
|
||||
private static final Random random = new Random();
|
||||
private static final SplittableRandom random = new SplittableRandom();
|
||||
|
||||
private static Location randomOffset(Location a)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
||||
@ -180,7 +180,7 @@ public class Command_modifyitem extends FreedomCommand
|
||||
}
|
||||
cmpnd.setDouble("Amount", amount);
|
||||
cmpnd.setInt("Operation", 0);
|
||||
Random random = new Random();
|
||||
SplittableRandom random = new SplittableRandom();
|
||||
cmpnd.setIntArray("UUID", new int[]
|
||||
{
|
||||
random.nextInt(),
|
||||
|
@ -10,7 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import javax.security.auth.login.LoginException;
|
||||
@ -292,7 +292,7 @@ public class Discord extends FreedomService
|
||||
public String generateCode(int size)
|
||||
{
|
||||
StringBuilder code = new StringBuilder();
|
||||
Random random = new Random();
|
||||
SplittableRandom random = new SplittableRandom();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
code.append(random.nextInt(10));
|
||||
|
@ -5,7 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
@ -48,7 +48,7 @@ import org.bukkit.util.Vector;
|
||||
public class ItemFun extends FreedomService
|
||||
{
|
||||
|
||||
private final Random random = new Random();
|
||||
private final SplittableRandom random = new SplittableRandom();
|
||||
private final Map<String, List<String>> cooldownTracker = new HashMap<>();
|
||||
private final Map<Player, Float> orientationTracker = new HashMap<>();
|
||||
private final List<UUID> FIRE_BALL_UUIDS = new ArrayList<>();
|
||||
|
@ -2,7 +2,7 @@ package me.totalfreedom.totalfreedommod.fun;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.Set;
|
||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
import me.totalfreedom.totalfreedommod.util.Groups;
|
||||
@ -17,7 +17,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class Trailer extends FreedomService
|
||||
{
|
||||
private final Random random = new Random();
|
||||
private final SplittableRandom random = new SplittableRandom();
|
||||
private final Set<String> trailPlayers = new HashSet<>(); // player name
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
@ -85,7 +85,7 @@ public class FUtil
|
||||
ChatColor.DARK_BLUE,
|
||||
ChatColor.DARK_PURPLE,
|
||||
ChatColor.LIGHT_PURPLE);
|
||||
private static final Random RANDOM = new Random();
|
||||
private static final SplittableRandom RANDOM = new SplittableRandom();
|
||||
private static final String CHARACTER_STRING = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private static final Map<Integer, String> TIMEZONE_LOOKUP = new HashMap<>();
|
||||
public static String DATE_STORAGE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z";
|
||||
@ -721,7 +721,7 @@ public class FUtil
|
||||
|
||||
public static char getRandomCharacter()
|
||||
{
|
||||
return CHARACTER_STRING.charAt(new Random().nextInt(CHARACTER_STRING.length()));
|
||||
return CHARACTER_STRING.charAt(new SplittableRandom().nextInt(CHARACTER_STRING.length()));
|
||||
}
|
||||
|
||||
public static void give(Player player, Material material, String coloredName, int amount, String... lore)
|
||||
|
@ -19,7 +19,7 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -128,7 +128,7 @@ public class CleanroomChunkGenerator extends ChunkGenerator
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkData generateChunkData(World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome)
|
||||
public @NotNull ChunkData generateChunkData(World world, @NotNull SplittableRandom random, int x, int z, @NotNull BiomeGrid biome)
|
||||
{
|
||||
int maxHeight = world.getMaxHeight();
|
||||
if (materials.length > maxHeight)
|
||||
@ -150,7 +150,7 @@ public class CleanroomChunkGenerator extends ChunkGenerator
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getFixedSpawnLocation(World world, @NotNull Random random)
|
||||
public Location getFixedSpawnLocation(World world, @NotNull SplittableRandom random)
|
||||
{
|
||||
if (!world.isChunkLoaded(0, 0))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user