Improve code quality

This commit is contained in:
NotAlexNoyle committed 2026-03-26 11:34:25 -04:00
1 parent 569730a8e2
commit dfaa19b376
12 files changed
+202 -173

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@ kotlin { jvmToolchain(17) }
/* ----------------------------- Metadata ------------------------------ */
group = "net.trueog.celeste-og" // Declare bundle identifier.
version = "1.0" // Declare plugin version (will be in .jar).
version = "1.1" // Declare plugin version (will be in .jar).
val apiVersion = "1.19" // Declare minecraft server target version.
@@ -10,131 +10,131 @@ import net.trueog.celeste.config.CelesteConfig;
public class Astronomer extends BukkitRunnable {
private final Celeste celeste;
private final Celeste celeste;
public Astronomer(Celeste celeste) {
public Astronomer(Celeste celeste) {
this.celeste = celeste;
this.celeste = celeste;
}
}
@Override
public void run() {
@Override
public void run() {
if (celeste.getServer().getOnlinePlayers().isEmpty()) {
if (celeste.getServer().getOnlinePlayers().isEmpty()) {
return;
return;
}
}
final List<World> worlds = celeste.getServer().getWorlds();
for (World world : worlds) {
final List<World> worlds = celeste.getServer().getWorlds();
for (World world : worlds) {
float multiplier = 1;
float multiplier = 1;
final CelesteConfig config = celeste.configManager.getConfigForWorld(world.getName());
if (!celeste.configManager.doesWorldHaveOverrides(world.getName())
&& world.getEnvironment() != World.Environment.NORMAL) {
final CelesteConfig config = celeste.configManager.getConfigForWorld(world.getName());
if (!celeste.configManager.doesWorldHaveOverrides(world.getName())
&& world.getEnvironment() != World.Environment.NORMAL)
{
// Ensure that Celeste-OG only runs on normal worlds unless override is specified
// in config
continue;
// Ensure that Celeste-OG only runs on normal worlds unless override is
// specified
// in config
continue;
}
}
if (world.getPlayers().size() == 0) {
if (world.getPlayers().size() == 0) {
continue;
continue;
}
}
if (!(world.getTime() >= config.beginSpawningStarsTime && world.getTime() <= config.endSpawningStarsTime)) {
if (!(world.getTime() >= config.beginSpawningStarsTime && world.getTime() <= config.endSpawningStarsTime)) {
if (!config.starsDaylight) {
if (!config.starsDaylight) {
continue;
continue;
}
}
multiplier = config.dayMultiplier;
multiplier = config.dayMultiplier;
}
}
if (world.hasStorm()) {
if (world.hasStorm()) {
continue;
continue;
}
}
final double shootingStarChance;
final double fallingStarChance;
final double shootingStarsPerMin;
final double fallingStarPerMin;
double adaptiveShootingStarsChance = 0;
double adaptiveFallingStarsChance = 0;
if (config.adaptiveShootingStars != 0) {
final double shootingStarChance;
final double fallingStarChance;
final double shootingStarsPerMin;
final double fallingStarPerMin;
double adaptiveShootingStarsChance = 0;
double adaptiveFallingStarsChance = 0;
if (config.adaptiveShootingStars != 0) {
if (config.adaptiveGlobalPlayerCount) {
if (config.adaptiveGlobalPlayerCount) {
adaptiveShootingStarsChance = (celeste.getServer().getOnlinePlayers().size()
/ config.adaptiveShootingStars) * 0.1;
adaptiveShootingStarsChance = (celeste.getServer().getOnlinePlayers().size()
/ config.adaptiveShootingStars) * 0.1;
}
else {
} else {
adaptiveShootingStarsChance = (world.getPlayers().size() / config.adaptiveShootingStars) * 0.1;
adaptiveShootingStarsChance = (world.getPlayers().size() / config.adaptiveShootingStars) * 0.1;
}
}
}
}
if (config.adaptiveFallingStars != 0) {
if (config.adaptiveFallingStars != 0) {
if (config.adaptiveGlobalPlayerCount) {
if (config.adaptiveGlobalPlayerCount) {
adaptiveFallingStarsChance = (celeste.getServer().getOnlinePlayers().size()
/ config.adaptiveFallingStars) * 0.1;
adaptiveFallingStarsChance = (celeste.getServer().getOnlinePlayers().size()
/ config.adaptiveFallingStars) * 0.1;
} else {
} else {
adaptiveFallingStarsChance = (world.getPlayers().size() / config.adaptiveFallingStars) * 0.1;
adaptiveFallingStarsChance = (world.getPlayers().size() / config.adaptiveFallingStars) * 0.1;
}
}
}
}
if (config.newMoonMeteorShower && (world.getFullTime() / 24000) % 8 == 4) {
if (config.newMoonMeteorShower && (world.getFullTime() / 24000) % 8 == 4) {
shootingStarsPerMin = adaptiveShootingStarsChance + config.shootingStarsPerMinuteMeteorShower;
fallingStarPerMin = (adaptiveFallingStarsChance + config.fallingStarsPerMinuteMeteorShower)
* multiplier;
shootingStarsPerMin = adaptiveShootingStarsChance + config.shootingStarsPerMinuteMeteorShower;
fallingStarPerMin = (adaptiveFallingStarsChance + config.fallingStarsPerMinuteMeteorShower)
* multiplier;
}
else {
} else {
shootingStarsPerMin = adaptiveShootingStarsChance + config.shootingStarsPerMinute;
fallingStarPerMin = (adaptiveFallingStarsChance + config.fallingStarsPerMinute) * multiplier;
shootingStarsPerMin = adaptiveShootingStarsChance + config.shootingStarsPerMinute;
fallingStarPerMin = (adaptiveFallingStarsChance + config.fallingStarsPerMinute) * multiplier;
}
}
shootingStarChance = shootingStarsPerMin / 120d;
fallingStarChance = fallingStarPerMin / 120d;
if (config.shootingStarsEnabled && new SecureRandom().nextDouble() <= shootingStarChance) {
shootingStarChance = shootingStarsPerMin / 120d;
fallingStarChance = fallingStarPerMin / 120d;
if (config.shootingStarsEnabled && new SecureRandom().nextDouble() <= shootingStarChance) {
CelestialSphere.createShootingStar(celeste,
world.getPlayers().get(new SecureRandom().nextInt(world.getPlayers().size())));
CelestialSphere.createShootingStar(celeste,
world.getPlayers().get(new SecureRandom().nextInt(world.getPlayers().size())));
}
}
if (config.fallingStarsEnabled && new SecureRandom().nextDouble() <= fallingStarChance) {
if (config.fallingStarsEnabled && new SecureRandom().nextDouble() <= fallingStarChance) {
CelestialSphere.createFallingStar(celeste,
world.getPlayers().get(new SecureRandom().nextInt(world.getPlayers().size())));
CelestialSphere.createFallingStar(celeste,
world.getPlayers().get(new SecureRandom().nextInt(world.getPlayers().size())));
}
}
}
}
}
}
}
+18 -18
View File
@@ -11,34 +11,34 @@ import net.trueog.celeste.config.CelesteConfigManager;
public class Celeste extends JavaPlugin {
public CelesteConfigManager configManager = new CelesteConfigManager(this);
public CelesteConfigManager configManager = new CelesteConfigManager(this);
@Override
public void onEnable() {
@Override
public void onEnable() {
this.saveDefaultConfig();
this.saveDefaultConfig();
this.getCommand("celeste").setExecutor(new CommandCeleste(this));
this.getCommand("shootingstar").setExecutor(new CommandShootingStar(this));
this.getCommand("fallingstar").setExecutor(new CommandFallingStar(this));
configManager.processConfigs();
this.getCommand("celeste").setExecutor(new CommandCeleste(this));
this.getCommand("shootingstar").setExecutor(new CommandShootingStar(this));
this.getCommand("fallingstar").setExecutor(new CommandFallingStar(this));
configManager.processConfigs();
final BukkitRunnable stargazingTask = new Astronomer(this);
stargazingTask.runTaskTimer(this, 0, 10);
final BukkitRunnable stargazingTask = new Astronomer(this);
stargazingTask.runTaskTimer(this, 0, 10);
}
}
public void reload() {
public void reload() {
reloadConfig();
configManager.processConfigs();
reloadConfig();
configManager.processConfigs();
}
}
public static void getLogger(String message) {
public static void getLogger(String message) {
Bukkit.getLogger().info("[Celeste-OG]" + message);
Bukkit.getLogger().info("[Celeste-OG]" + message);
}
}
}
@@ -1,15 +1,18 @@
package net.trueog.celeste;
import java.math.RoundingMode;
import java.security.SecureRandom;
import java.text.DecimalFormat;
import java.util.Random;
import net.trueog.celeste.config.CelesteConfig;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import net.trueog.celeste.config.CelesteConfig;
public class CelestialSphere {
public static void createShootingStar(Celeste celeste, Player player) {
@@ -32,14 +35,15 @@ public class CelestialSphere {
public static void createShootingStar(Celeste celeste, Location location, boolean approximate) {
Location starLocation;
CelesteConfig config = celeste.configManager.getConfigForWorld(location.getWorld().getName());
double w = 100 * Math.sqrt(new Random().nextDouble());
double t = 2d * Math.PI * new Random().nextDouble();
double x = w * Math.cos(t);
double range = Math.max(0, config.shootingStarsMaxHeight - config.shootingStarsMinHeight);
double y = Math.max(new Random().nextDouble() * range + config.shootingStarsMinHeight, location.getY() + 50);
double z = w * Math.sin(t);
final Location starLocation;
final CelesteConfig config = celeste.configManager.getConfigForWorld(location.getWorld().getName());
final double w = 100 * Math.sqrt(new SecureRandom().nextDouble());
final double t = 2d * Math.PI * new SecureRandom().nextDouble();
final double x = w * Math.cos(t);
final double range = Math.max(0, config.shootingStarsMaxHeight - config.shootingStarsMinHeight);
final double y = Math.max(new SecureRandom().nextDouble() * range + config.shootingStarsMinHeight,
location.getY() + 50);
final double z = w * Math.sin(t);
if (approximate) {
starLocation = new Location(location.getWorld(), location.getX() + x, y, location.getZ() + z);
@@ -50,13 +54,13 @@ public class CelestialSphere {
}
Vector direction = new Vector(new Random().nextDouble() * 2 - 1, new Random().nextDouble() * -0.75d,
final Vector direction = new Vector(new Random().nextDouble() * 2 - 1, new Random().nextDouble() * -0.75d,
new Random().nextDouble() * 2 - 1);
direction.normalize();
double speed = new Random().nextDouble() * 2 + 0.75;
final double speed = new SecureRandom().nextDouble() * 2 + 0.75;
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, starLocation, 0, direction.getX(), direction.getY(),
direction.getZ(), speed, null, true);
if (new Random().nextDouble() >= 0.5) {
if (new SecureRandom().nextDouble() >= 0.5) {
location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, starLocation, 0, direction.getX(),
direction.getY(), direction.getZ(), speed, null, true);
@@ -93,19 +97,20 @@ public class CelestialSphere {
public static void createFallingStar(Celeste celeste, final Location location, boolean approximate) {
Location target = location;
CelesteConfig config = celeste.configManager.getConfigForWorld(location.getWorld().getName());
final CelesteConfig config = celeste.configManager.getConfigForWorld(location.getWorld().getName());
if (approximate) {
double fallingStarRadius = config.fallingStarsRadius;
double w = fallingStarRadius * Math.sqrt(new Random().nextDouble());
double t = 2d * Math.PI * new Random().nextDouble();
double x = w * Math.cos(t);
double z = w * Math.sin(t);
final double fallingStarRadius = config.fallingStarsRadius;
final double w = fallingStarRadius * Math.sqrt(new SecureRandom().nextDouble());
final double t = 2d * Math.PI * new SecureRandom().nextDouble();
final double x = w * Math.cos(t);
final double z = w * Math.sin(t);
target = new Location(location.getWorld(), location.getX() + x, location.getY(), location.getZ() + z);
}
BukkitRunnable fallingStarTask = new FallingStar(celeste, target);
final BukkitRunnable fallingStarTask = new FallingStar(celeste, target);
fallingStarTask.runTaskTimer(celeste, 0, 1);
if (celeste.getConfig().getBoolean("debug")) {
@@ -118,11 +123,13 @@ public class CelestialSphere {
private static String stringifyLocation(Location location) {
DecimalFormat format = new DecimalFormat("##.00");
final DecimalFormat format = new DecimalFormat("##.00");
format.setRoundingMode(RoundingMode.HALF_UP);
return "x: " + format.format(location.getX()) + " y: " + format.format(location.getY()) + " z: "
+ format.format(location.getZ());
}
}
}
@@ -1,7 +1,7 @@
package net.trueog.celeste;
import java.util.Random;
import net.trueog.celeste.config.CelesteConfig;
import java.security.SecureRandom;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
@@ -12,6 +12,8 @@ import org.bukkit.entity.ExperienceOrb;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import net.trueog.celeste.config.CelesteConfig;
public class FallingStar extends BukkitRunnable {
private final Celeste celeste;
@@ -35,17 +37,21 @@ public class FallingStar extends BukkitRunnable {
}
@Override
public void run() {
double step = 2; // Speed of fall increased to compensate for increased height.
// Speed of fall increased to compensate for increased height.
final double step = 2;
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location.getX(), y, location.getZ(), 0, 0,
new Random().nextDouble(), 0, 0.2, null, true);
new SecureRandom().nextDouble(), 0, 0.2, null, true);
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location.getX(),
y + new Random().nextDouble() * step, location.getZ(), 0, 0, -1, 0, 1, null, true);
y + new SecureRandom().nextDouble() * step, location.getZ(), 0, 0, -1, 0, 1, null, true);
if (y % (step * 2) == 0) {
location.getWorld().spawnParticle(Particle.LAVA, location.getX(), y + new Random().nextDouble(),
location.getZ(), 0, 0, new Random().nextDouble(), 0, 0.2, null, true);
location.getWorld().spawnParticle(Particle.LAVA, location.getX(), y + new SecureRandom().nextDouble(),
location.getZ(), 0, 0, new SecureRandom().nextDouble(), 0, 0.2, null, true);
}
@@ -64,7 +70,7 @@ public class FallingStar extends BukkitRunnable {
// because why not
if (config.fallingStarSimpleLoot != null && config.fallingStarSimpleLoot.entries.size() > 0) {
ItemStack drop = new ItemStack(Material.valueOf(config.fallingStarSimpleLoot.getRandom()), 1);
final ItemStack drop = new ItemStack(Material.valueOf(config.fallingStarSimpleLoot.getRandom()), 1);
location.getWorld().dropItem(dropLoc, drop);
if (celeste.getConfig().getBoolean("debug")) {
@@ -77,12 +83,14 @@ public class FallingStar extends BukkitRunnable {
if (config.fallingStarLootTable != null) {
// Armor stands are used as markers are not compatible with 1.14
Entity marker = dropLoc.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
String command = String.format("execute at %s run loot spawn %s %s %s loot %s",
final Entity marker = dropLoc.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
final String command = "execute at %s run loot spawn %s %s %s loot %s".formatted(
marker.getUniqueId(), dropLoc.getX(), dropLoc.getY(), dropLoc.getZ(),
config.fallingStarLootTable);
celeste.getServer().dispatchCommand(celeste.getServer().getConsoleSender(), command);
marker.remove();
if (celeste.getConfig().getBoolean("debug")) {
celeste.getLogger().info(
@@ -94,9 +102,11 @@ public class FallingStar extends BukkitRunnable {
if (config.fallingStarsExperience > 0) {
ExperienceOrb orb = (ExperienceOrb) dropLoc.getWorld().spawnEntity(dropLoc,
final ExperienceOrb orb = (ExperienceOrb) dropLoc.getWorld().spawnEntity(dropLoc,
EntityType.EXPERIENCE_ORB);
orb.setExperience(config.fallingStarsExperience);
if (celeste.getConfig().getBoolean("debug")) {
celeste.getLogger()
@@ -112,8 +122,8 @@ public class FallingStar extends BukkitRunnable {
if (y % (step * 5) == 0) {
location.getWorld().spawnParticle(Particle.LAVA, dropLoc, 0, 0, new Random().nextDouble(), 0, 1, null,
true);
location.getWorld().spawnParticle(Particle.LAVA, dropLoc, 0, 0, new SecureRandom().nextDouble(), 0, 1,
null, true);
}
@@ -130,4 +140,4 @@ public class FallingStar extends BukkitRunnable {
}
}
}
@@ -1,12 +1,14 @@
package net.trueog.celeste.commands;
import net.trueog.celeste.Celeste;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import java.util.List;
import net.trueog.celeste.Celeste;
public class CommandCeleste implements CommandExecutor {
@@ -18,9 +20,10 @@ public class CommandCeleste implements CommandExecutor {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
if (args.length == 1 && StringUtils.equalsIgnoreCase(args[0], "reload")) {
if (sender.hasPermission("celeste.reload")) {
@@ -35,12 +38,12 @@ public class CommandCeleste implements CommandExecutor {
return true;
} else if (args.length == 1 && args[0].equalsIgnoreCase("info")) {
} else if (args.length == 1 && StringUtils.equalsIgnoreCase(args[0], "info")) {
if (sender.hasPermission("celeste.info")) {
double fallingStarRate = 0;
double adaptiveFallingStars = celeste.getConfig().getDouble("adaptive-falling-stars");
final double adaptiveFallingStars = celeste.getConfig().getDouble("adaptive-falling-stars");
if (adaptiveFallingStars != 0) {
if (celeste.getConfig().getBoolean("adaptive-use-global-player-count")) {
@@ -49,11 +52,11 @@ public class CommandCeleste implements CommandExecutor {
} else {
List<World> worlds = celeste.getServer().getWorlds();
final List<World> worlds = celeste.getServer().getWorlds();
double highestRate = 0;
for (World world : worlds) {
double worldRate = (world.getPlayers().size() / adaptiveFallingStars) * 0.1;
final double worldRate = (world.getPlayers().size() / adaptiveFallingStars) * 0.1;
if (highestRate < worldRate) {
highestRate = worldRate;
@@ -70,7 +73,7 @@ public class CommandCeleste implements CommandExecutor {
fallingStarRate = fallingStarRate + celeste.getConfig().getDouble("falling-stars-per-minute");
sender.sendMessage("Celeste-OG v" + celeste.getDescription().getVersion());
sender.sendMessage("Celeste-OG v" + celeste.getPluginMeta().getVersion());
sender.sendMessage("Shooting stars: "
+ (celeste.getConfig().getBoolean("shooting-stars-enabled") ? "Enabled" : "Disabled"));
sender.sendMessage("Falling stars: "
@@ -93,4 +96,4 @@ public class CommandCeleste implements CommandExecutor {
}
}
}
@@ -1,13 +1,14 @@
package net.trueog.celeste.commands;
import net.trueog.celeste.Celeste;
import net.trueog.celeste.CelestialSphere;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.trueog.celeste.Celeste;
import net.trueog.celeste.CelestialSphere;
public class CommandFallingStar implements CommandExecutor {
Celeste celeste;
@@ -18,6 +19,7 @@ public class CommandFallingStar implements CommandExecutor {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length > 0) {
@@ -33,9 +35,8 @@ public class CommandFallingStar implements CommandExecutor {
} else {
if (sender instanceof Player) {
if (sender instanceof Player player) {
Player player = (Player) sender;
CelestialSphere.createFallingStar(celeste, player, false);
} else {
@@ -46,7 +47,7 @@ public class CommandFallingStar implements CommandExecutor {
}
String message = this.celeste.getConfig().getString("falling-stars-summon-text");
final String message = this.celeste.getConfig().getString("falling-stars-summon-text");
if (message != null) {
sender.sendMessage(message);
@@ -57,4 +58,4 @@ public class CommandFallingStar implements CommandExecutor {
}
}
}
@@ -1,13 +1,14 @@
package net.trueog.celeste.commands;
import net.trueog.celeste.Celeste;
import net.trueog.celeste.CelestialSphere;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.trueog.celeste.Celeste;
import net.trueog.celeste.CelestialSphere;
public class CommandShootingStar implements CommandExecutor {
Celeste celeste;
@@ -18,6 +19,7 @@ public class CommandShootingStar implements CommandExecutor {
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length > 0) {
@@ -33,9 +35,8 @@ public class CommandShootingStar implements CommandExecutor {
} else {
if (sender instanceof Player) {
if (sender instanceof Player player) {
Player player = (Player) sender;
CelestialSphere.createShootingStar(celeste, player, false);
} else {
@@ -46,7 +47,7 @@ public class CommandShootingStar implements CommandExecutor {
}
String message = this.celeste.getConfig().getString("shooting-stars-summon-text");
final String message = this.celeste.getConfig().getString("shooting-stars-summon-text");
if (message != null) {
sender.sendMessage(message);
@@ -57,4 +58,4 @@ public class CommandShootingStar implements CommandExecutor {
}
}
}
@@ -1,9 +1,11 @@
package net.trueog.celeste.config;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import net.trueog.celeste.Celeste;
import net.trueog.celeste.utilities.WeightedRandomBag;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
public class CelesteConfig {
@@ -36,14 +38,14 @@ public class CelesteConfig {
public CelesteConfig(ConfigurationSection section) {
// Used to build the global config
// Used to build the global config.
buildFromConfigurationSection(section);
}
public CelesteConfig(ConfigurationSection section, CelesteConfig globalConfig) {
// Used to build per-world configs
// Used to build per-world configs.
buildFromConfigurationSectionWithGlobal(section, globalConfig);
}
@@ -141,24 +143,24 @@ public class CelesteConfig {
public WeightedRandomBag<String> calculateSimpleLoot(ConfigurationSection loot) {
WeightedRandomBag<String> fallingStarDrops = new WeightedRandomBag<>();
for (String key : loot.getKeys(false)) {
final WeightedRandomBag<String> fallingStarDrops = new WeightedRandomBag<>();
loot.getKeys(false).forEach(key -> {
try {
Material.valueOf(key.toUpperCase());
fallingStarDrops.addEntry(key.toUpperCase(), loot.getDouble(key));
Material.valueOf(StringUtils.upperCase(key));
fallingStarDrops.addEntry(StringUtils.upperCase(key), loot.getDouble(key));
} catch (IllegalArgumentException e) {
Celeste.getLogger("Error: Item with name " + key.toUpperCase() + " does not exist, skipping");
Celeste.getLogger("Error: Item with name " + StringUtils.upperCase(key) + " does not exist, skipping");
}
}
});
return fallingStarDrops;
}
}
}
@@ -21,14 +21,16 @@ public class CelesteConfigManager {
public void processConfigs() {
this.worldConfigs.clear();
FileConfiguration config = this.celeste.getConfig();
final FileConfiguration config = this.celeste.getConfig();
globalConfig = new CelesteConfig(config);
ConfigurationSection worlds = config.getConfigurationSection("world-overrides");
final ConfigurationSection worlds = config.getConfigurationSection("world-overrides");
if (worlds != null) {
for (String world : worlds.getKeys(false)) {
ConfigurationSection worldSettings = worlds.getConfigurationSection(world);
final ConfigurationSection worldSettings = worlds.getConfigurationSection(world);
if (worldSettings == null) {
this.celeste.getLogger().severe("Your world override config for world '" + world
@@ -37,7 +39,7 @@ public class CelesteConfigManager {
}
CelesteConfig worldConfig = new CelesteConfig(worldSettings, globalConfig);
final CelesteConfig worldConfig = new CelesteConfig(worldSettings, globalConfig);
worldConfigs.put(world, worldConfig);
}
@@ -78,4 +80,4 @@ public class CelesteConfigManager {
}
}
}
@@ -1,6 +1,7 @@
package net.trueog.celeste.utilities;
// From https://gamedev.stackexchange.com/a/162987
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -14,23 +15,25 @@ public class WeightedRandomBag<T extends Object> {
}
public List<Entry> entries = new ArrayList<Entry>();
public List<Entry> entries = new ArrayList<>();
private double accumulatedWeight;
private Random rand = new Random();
private Random rand = new SecureRandom();
public void addEntry(T object, double weight) {
accumulatedWeight += weight;
Entry e = new Entry();
final Entry e = new Entry();
e.object = object;
e.accumulatedWeight = accumulatedWeight;
entries.add(e);
}
public T getRandom() {
double r = rand.nextDouble() * accumulatedWeight;
final double r = rand.nextDouble() * accumulatedWeight;
for (Entry entry : entries) {
if (entry.accumulatedWeight >= r) {
@@ -41,9 +44,9 @@ public class WeightedRandomBag<T extends Object> {
}
// Should only happen when there are no entries
// Should only happen when there are no entries.
return null;
}
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ end-spawning-stars-time: 23000
shooting-stars-per-minute: 12
shooting-stars-min-height: 160
shooting-stars-max-height: 310
falling-stars-per-minute: 0.2
falling-stars-per-minute: 0.1
falling-stars-max-height: 300
falling-stars-radius: 75
falling-stars-sound-enabled: true