Update gradle to 8.14.2, add auto formatting
This commit is contained in:
1 parent
9c6008219b
commit
5e17a5c0c5
15 files changed
+567
-500
No files matched your search
+21
-14
@@ -1,6 +1,8 @@
|
||||
plugins {
|
||||
id("java") // Tell gradle this is a java project.
|
||||
id("java-library") // Import helper for source-based libraries.
|
||||
id("com.diffplug.spotless") version "7.0.4" // Import auto-formatter.
|
||||
id("com.gradleup.shadow") version "8.3.6" // Import shadow API.
|
||||
java // Tell gradle this is a java project.
|
||||
eclipse // Import eclipse plugin for IDE integration.
|
||||
}
|
||||
|
||||
@@ -10,20 +12,17 @@ java {
|
||||
}
|
||||
|
||||
group = "net.trueog.celeste-og" // Declare bundle identifier.
|
||||
|
||||
version = "1.0" // Declare plugin version (will be in .jar).
|
||||
|
||||
val apiVersion = "1.19" // Declare minecraft server target version.
|
||||
|
||||
tasks.named<ProcessResources>("processResources") {
|
||||
val props = mapOf(
|
||||
"version" to version,
|
||||
"apiVersion" to apiVersion
|
||||
)
|
||||
val props = mapOf("version" to version, "apiVersion" to apiVersion)
|
||||
|
||||
inputs.properties(props) // Indicates to rerun if version changes.
|
||||
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
filesMatching("plugin.yml") { expand(props) }
|
||||
from("LICENSE") { // Bundle license into .jars.
|
||||
into("/")
|
||||
}
|
||||
@@ -32,9 +31,7 @@ tasks.named<ProcessResources>("processResources") {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url = uri("https://repo.purpurmc.org/snapshots")
|
||||
}
|
||||
maven { url = uri("https://repo.purpurmc.org/snapshots") }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -54,12 +51,11 @@ tasks.shadowJar {
|
||||
}
|
||||
|
||||
tasks.build {
|
||||
dependsOn(tasks.spotlessApply)
|
||||
dependsOn(tasks.shadowJar)
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
archiveClassifier.set("part")
|
||||
}
|
||||
tasks.jar { archiveClassifier.set("part") }
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.compilerArgs.add("-parameters")
|
||||
@@ -74,3 +70,14 @@ java {
|
||||
vendor = JvmVendorSpec.GRAAL_VM
|
||||
}
|
||||
}
|
||||
|
||||
spotless {
|
||||
java {
|
||||
removeUnusedImports()
|
||||
palantirJavaFormat()
|
||||
}
|
||||
kotlinGradle {
|
||||
ktfmt().kotlinlangStyle().configure { it.setMaxWidth(120) }
|
||||
target("build.gradle.kts", "settings.gradle.kts")
|
||||
}
|
||||
}
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -84,7 +86,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -112,7 +114,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -203,7 +205,7 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
@@ -211,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+4
-2
@@ -13,6 +13,8 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -68,11 +70,11 @@ goto fail
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@@ -2,60 +2,62 @@ package net.trueog.celeste;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.trueog.celeste.config.CelesteConfig;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import net.trueog.celeste.config.CelesteConfig;
|
||||
|
||||
public class Astronomer extends BukkitRunnable {
|
||||
|
||||
private final Celeste celeste;
|
||||
private final Celeste celeste;
|
||||
|
||||
public Astronomer(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
public Astronomer(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (celeste.getServer().getOnlinePlayers().size() == 0) {
|
||||
return;
|
||||
}
|
||||
List<World> worlds = celeste.getServer().getWorlds();
|
||||
for (World world : worlds) {
|
||||
CelesteConfig config = celeste.configManager.getConfigForWorld(world.getName());
|
||||
if (!celeste.configManager.doesWorldHaveOverrides(world.getName())
|
||||
&& !world.getEnvironment().equals(World.Environment.NORMAL)) {
|
||||
// Ensure that Celeste only runs on normal worlds unless override is specified in config
|
||||
continue;
|
||||
}
|
||||
if (world.getPlayers().size() == 0) {
|
||||
continue;
|
||||
}
|
||||
if (!(world.getTime() >= config.beginSpawningStarsTime && world.getTime() <= config.endSpawningStarsTime)) {
|
||||
continue;
|
||||
}
|
||||
if (world.hasStorm()) {
|
||||
continue;
|
||||
}
|
||||
public void run() {
|
||||
if (celeste.getServer().getOnlinePlayers().size() == 0) {
|
||||
return;
|
||||
}
|
||||
List<World> worlds = celeste.getServer().getWorlds();
|
||||
for (World world : worlds) {
|
||||
CelesteConfig config = celeste.configManager.getConfigForWorld(world.getName());
|
||||
if (!celeste.configManager.doesWorldHaveOverrides(world.getName())
|
||||
&& !world.getEnvironment().equals(World.Environment.NORMAL)) {
|
||||
// Ensure that Celeste only runs on normal worlds unless override is specified in config
|
||||
continue;
|
||||
}
|
||||
if (world.getPlayers().size() == 0) {
|
||||
continue;
|
||||
}
|
||||
if (!(world.getTime() >= config.beginSpawningStarsTime && world.getTime() <= config.endSpawningStarsTime)) {
|
||||
continue;
|
||||
}
|
||||
if (world.hasStorm()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double shootingStarChance;
|
||||
double fallingStarChance;
|
||||
if (config.newMoonMeteorShower && (world.getFullTime() / 24000) % 8 == 4) {
|
||||
shootingStarChance = config.shootingStarsPerMinuteMeteorShower / 120d;
|
||||
fallingStarChance = config.fallingStarsPerMinuteMeteorShower / 120d;
|
||||
} else {
|
||||
shootingStarChance = config.shootingStarsPerMinute / 120d;
|
||||
fallingStarChance = config.fallingStarsPerMinute / 120d;
|
||||
}
|
||||
double shootingStarChance;
|
||||
double fallingStarChance;
|
||||
if (config.newMoonMeteorShower && (world.getFullTime() / 24000) % 8 == 4) {
|
||||
shootingStarChance = config.shootingStarsPerMinuteMeteorShower / 120d;
|
||||
fallingStarChance = config.fallingStarsPerMinuteMeteorShower / 120d;
|
||||
} else {
|
||||
shootingStarChance = config.shootingStarsPerMinute / 120d;
|
||||
fallingStarChance = config.fallingStarsPerMinute / 120d;
|
||||
}
|
||||
|
||||
if (config.shootingStarsEnabled && new Random().nextDouble() <= shootingStarChance) {
|
||||
CelestialSphere.createShootingStar(celeste,
|
||||
world.getPlayers().get(new Random().nextInt(world.getPlayers().size())));
|
||||
}
|
||||
if (config.fallingStarsEnabled && new Random().nextDouble() <= fallingStarChance) {
|
||||
CelestialSphere.createFallingStar(celeste,
|
||||
world.getPlayers().get(new Random().nextInt(world.getPlayers().size())));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config.shootingStarsEnabled && new Random().nextDouble() <= shootingStarChance) {
|
||||
CelestialSphere.createShootingStar(
|
||||
celeste,
|
||||
world.getPlayers()
|
||||
.get(new Random().nextInt(world.getPlayers().size())));
|
||||
}
|
||||
if (config.fallingStarsEnabled && new Random().nextDouble() <= fallingStarChance) {
|
||||
CelestialSphere.createFallingStar(
|
||||
celeste,
|
||||
world.getPlayers()
|
||||
.get(new Random().nextInt(world.getPlayers().size())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,37 @@
|
||||
package net.trueog.celeste;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import net.trueog.celeste.commands.CommandCeleste;
|
||||
import net.trueog.celeste.commands.CommandFallingStar;
|
||||
import net.trueog.celeste.commands.CommandShootingStar;
|
||||
import net.trueog.celeste.config.CelesteConfigManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class Celeste extends JavaPlugin {
|
||||
|
||||
public CelesteConfigManager configManager = new CelesteConfigManager(this);
|
||||
public CelesteConfigManager configManager = new CelesteConfigManager(this);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.saveDefaultConfig();
|
||||
@Override
|
||||
public void onEnable() {
|
||||
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();
|
||||
|
||||
BukkitRunnable stargazingTask = new Astronomer(this);
|
||||
stargazingTask.runTaskTimer(this, 0, 10);
|
||||
BukkitRunnable stargazingTask = new Astronomer(this);
|
||||
stargazingTask.runTaskTimer(this, 0, 10);
|
||||
}
|
||||
|
||||
}
|
||||
public void reload() {
|
||||
reloadConfig();
|
||||
configManager.processConfigs();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
reloadConfig();
|
||||
configManager.processConfigs();
|
||||
}
|
||||
|
||||
public static void getLogger(String message) {
|
||||
|
||||
Bukkit.getLogger().info("[Celeste-OG]" + message);
|
||||
|
||||
}
|
||||
public static void getLogger(String message) {
|
||||
|
||||
Bukkit.getLogger().info("[Celeste-OG]" + message);
|
||||
}
|
||||
}
|
||||
@@ -3,90 +3,116 @@ package net.trueog.celeste;
|
||||
import java.math.RoundingMode;
|
||||
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) {
|
||||
createShootingStar(celeste, player, true);
|
||||
}
|
||||
public static void createShootingStar(Celeste celeste, Player player) {
|
||||
createShootingStar(celeste, player, true);
|
||||
}
|
||||
|
||||
public static void createShootingStar(Celeste celeste, Player player, boolean approximate) {
|
||||
createShootingStar(celeste, player.getLocation(), approximate);
|
||||
}
|
||||
public static void createShootingStar(Celeste celeste, Player player, boolean approximate) {
|
||||
createShootingStar(celeste, player.getLocation(), approximate);
|
||||
}
|
||||
|
||||
public static void createShootingStar(Celeste celeste, Location location) {
|
||||
createShootingStar(celeste, location, true);
|
||||
}
|
||||
public static void createShootingStar(Celeste celeste, Location location) {
|
||||
createShootingStar(celeste, location, true);
|
||||
}
|
||||
|
||||
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);
|
||||
if (approximate) {
|
||||
starLocation = new Location(location.getWorld(), location.getX() + x, y, location.getZ() + z);
|
||||
} else {
|
||||
starLocation = new Location(location.getWorld(), location.getX(), y, location.getZ());
|
||||
}
|
||||
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;
|
||||
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, starLocation, 0, direction.getX(),
|
||||
direction.getY(), direction.getZ(), speed, null, true);
|
||||
if (new Random().nextDouble() >= 0.5) {
|
||||
location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, starLocation, 0, direction.getX(),
|
||||
direction.getY(), direction.getZ(), speed, null, true);
|
||||
}
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger().info("Shooting star at " + stringifyLocation(starLocation) + " in world " + starLocation.getWorld().getName());
|
||||
}
|
||||
}
|
||||
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);
|
||||
if (approximate) {
|
||||
starLocation = new Location(location.getWorld(), location.getX() + x, y, location.getZ() + z);
|
||||
} else {
|
||||
starLocation = new Location(location.getWorld(), location.getX(), y, location.getZ());
|
||||
}
|
||||
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;
|
||||
location.getWorld()
|
||||
.spawnParticle(
|
||||
Particle.FIREWORKS_SPARK,
|
||||
starLocation,
|
||||
0,
|
||||
direction.getX(),
|
||||
direction.getY(),
|
||||
direction.getZ(),
|
||||
speed,
|
||||
null,
|
||||
true);
|
||||
if (new Random().nextDouble() >= 0.5) {
|
||||
location.getWorld()
|
||||
.spawnParticle(
|
||||
Particle.EXPLOSION_NORMAL,
|
||||
starLocation,
|
||||
0,
|
||||
direction.getX(),
|
||||
direction.getY(),
|
||||
direction.getZ(),
|
||||
speed,
|
||||
null,
|
||||
true);
|
||||
}
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger()
|
||||
.info("Shooting star at " + stringifyLocation(starLocation) + " in world "
|
||||
+ starLocation.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static void createFallingStar(Celeste celeste, Player player) {
|
||||
createFallingStar(celeste, player, true);
|
||||
}
|
||||
public static void createFallingStar(Celeste celeste, Player player) {
|
||||
createFallingStar(celeste, player, true);
|
||||
}
|
||||
|
||||
public static void createFallingStar(Celeste celeste, Player player, boolean approximate) {
|
||||
createFallingStar(celeste, player.getLocation(), approximate);
|
||||
}
|
||||
public static void createFallingStar(Celeste celeste, Player player, boolean approximate) {
|
||||
createFallingStar(celeste, player.getLocation(), approximate);
|
||||
}
|
||||
|
||||
public static void createFallingStar(Celeste celeste, final Location location) {
|
||||
createFallingStar(celeste, location, true);
|
||||
}
|
||||
public static void createFallingStar(Celeste celeste, final Location location) {
|
||||
createFallingStar(celeste, location, true);
|
||||
}
|
||||
|
||||
public static void createFallingStar(Celeste celeste, final Location location, boolean approximate) {
|
||||
Location target = location;
|
||||
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);
|
||||
target = new Location(location.getWorld(), location.getX() + x, location.getY(), location.getZ() + z);
|
||||
}
|
||||
BukkitRunnable fallingStarTask = new FallingStar(celeste, target);
|
||||
fallingStarTask.runTaskTimer(celeste, 0, 1);
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger().info("Falling star at " + stringifyLocation(target) + " in world " + target.getWorld().getName());
|
||||
}
|
||||
}
|
||||
public static void createFallingStar(Celeste celeste, final Location location, boolean approximate) {
|
||||
Location target = location;
|
||||
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);
|
||||
target = new Location(location.getWorld(), location.getX() + x, location.getY(), location.getZ() + z);
|
||||
}
|
||||
BukkitRunnable fallingStarTask = new FallingStar(celeste, target);
|
||||
fallingStarTask.runTaskTimer(celeste, 0, 1);
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger()
|
||||
.info("Falling star at " + stringifyLocation(target) + " in world "
|
||||
+ target.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private static String stringifyLocation(Location location) {
|
||||
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());
|
||||
}
|
||||
private static String stringifyLocation(Location location) {
|
||||
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 org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
@@ -12,93 +12,124 @@ 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;
|
||||
private final Location location;
|
||||
private final Location dropLoc;
|
||||
private final CelesteConfig config;
|
||||
private double y = 256;
|
||||
private boolean soundPlayed = false;
|
||||
private boolean lootDropped = false;
|
||||
private int sparkTimer;
|
||||
private final Celeste celeste;
|
||||
private final Location location;
|
||||
private final Location dropLoc;
|
||||
private final CelesteConfig config;
|
||||
private double y = 256;
|
||||
private boolean soundPlayed = false;
|
||||
private boolean lootDropped = false;
|
||||
private int sparkTimer;
|
||||
|
||||
public FallingStar(Celeste celeste, Location location) {
|
||||
this.celeste = celeste;
|
||||
this.location = location;
|
||||
config = celeste.configManager.getConfigForWorld(location.getWorld().getName());
|
||||
sparkTimer = config.fallingStarsSparkTime;
|
||||
dropLoc = new Location(location.getWorld(), location.getX(),
|
||||
location.getWorld().getHighestBlockAt(location).getY() + 1, location.getZ());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
double step = 1;
|
||||
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location.getX(), y, location.getZ(),
|
||||
0, 0, new Random().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);
|
||||
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);
|
||||
}
|
||||
if (config.fallingStarsSoundEnabled && !soundPlayed && y <= dropLoc.getY() + 75) {
|
||||
location.getWorld().playSound(dropLoc, Sound.BLOCK_BELL_RESONATE, (float) config.fallingStarsVolume, 0.5f);
|
||||
soundPlayed = true;
|
||||
}
|
||||
if (y <= dropLoc.getY()) {
|
||||
if (!lootDropped) {
|
||||
// Note that both simple loot and loot tables will drop if both are configured because why not
|
||||
if (config.fallingStarSimpleLoot != null && config.fallingStarSimpleLoot.entries.size() > 0) {
|
||||
ItemStack drop = new ItemStack(Material.valueOf(config.fallingStarSimpleLoot.getRandom()), 1);
|
||||
location.getWorld().dropItem(dropLoc, drop);
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger().info("Spawned simple falling star loot");
|
||||
}
|
||||
}
|
||||
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",
|
||||
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("Spawned falling star loot from loot table '" + config.fallingStarLootTable + "'");
|
||||
}
|
||||
}
|
||||
if (config.fallingStarsExperience > 0) {
|
||||
ExperienceOrb orb = (ExperienceOrb) dropLoc.getWorld().spawnEntity(dropLoc, EntityType.EXPERIENCE_ORB);
|
||||
orb.setExperience(config.fallingStarsExperience);
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger().info("Dropping experience orbs with value " + config.fallingStarsExperience);
|
||||
}
|
||||
}
|
||||
lootDropped = true;
|
||||
}
|
||||
if (y % (step * 5) == 0) {
|
||||
location.getWorld().spawnParticle(Particle.LAVA, dropLoc,
|
||||
0, 0, new Random().nextDouble(), 0,
|
||||
1, null, true);
|
||||
}
|
||||
sparkTimer--;
|
||||
if (sparkTimer <= 0) {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
y -= step;
|
||||
}
|
||||
public FallingStar(Celeste celeste, Location location) {
|
||||
this.celeste = celeste;
|
||||
this.location = location;
|
||||
config = celeste.configManager.getConfigForWorld(location.getWorld().getName());
|
||||
sparkTimer = config.fallingStarsSparkTime;
|
||||
dropLoc = new Location(
|
||||
location.getWorld(),
|
||||
location.getX(),
|
||||
location.getWorld().getHighestBlockAt(location).getY() + 1,
|
||||
location.getZ());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
double step = 1;
|
||||
location.getWorld()
|
||||
.spawnParticle(
|
||||
Particle.FIREWORKS_SPARK,
|
||||
location.getX(),
|
||||
y,
|
||||
location.getZ(),
|
||||
0,
|
||||
0,
|
||||
new Random().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);
|
||||
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);
|
||||
}
|
||||
if (config.fallingStarsSoundEnabled && !soundPlayed && y <= dropLoc.getY() + 75) {
|
||||
location.getWorld().playSound(dropLoc, Sound.BLOCK_BELL_RESONATE, (float) config.fallingStarsVolume, 0.5f);
|
||||
soundPlayed = true;
|
||||
}
|
||||
if (y <= dropLoc.getY()) {
|
||||
if (!lootDropped) {
|
||||
// Note that both simple loot and loot tables will drop if both are configured because why not
|
||||
if (config.fallingStarSimpleLoot != null && config.fallingStarSimpleLoot.entries.size() > 0) {
|
||||
ItemStack drop = new ItemStack(Material.valueOf(config.fallingStarSimpleLoot.getRandom()), 1);
|
||||
location.getWorld().dropItem(dropLoc, drop);
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger().info("Spawned simple falling star loot");
|
||||
}
|
||||
}
|
||||
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",
|
||||
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("Spawned falling star loot from loot table '" + config.fallingStarLootTable
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
if (config.fallingStarsExperience > 0) {
|
||||
ExperienceOrb orb =
|
||||
(ExperienceOrb) dropLoc.getWorld().spawnEntity(dropLoc, EntityType.EXPERIENCE_ORB);
|
||||
orb.setExperience(config.fallingStarsExperience);
|
||||
if (celeste.getConfig().getBoolean("debug")) {
|
||||
celeste.getLogger()
|
||||
.info("Dropping experience orbs with value " + config.fallingStarsExperience);
|
||||
}
|
||||
}
|
||||
lootDropped = true;
|
||||
}
|
||||
if (y % (step * 5) == 0) {
|
||||
location.getWorld()
|
||||
.spawnParticle(Particle.LAVA, dropLoc, 0, 0, new Random().nextDouble(), 0, 1, null, true);
|
||||
}
|
||||
sparkTimer--;
|
||||
if (sparkTimer <= 0) {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
y -= step;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,42 @@
|
||||
package net.trueog.celeste.commands;
|
||||
|
||||
import net.trueog.celeste.Celeste;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.trueog.celeste.Celeste;
|
||||
|
||||
public class CommandCeleste implements CommandExecutor {
|
||||
|
||||
Celeste celeste;
|
||||
Celeste celeste;
|
||||
|
||||
public CommandCeleste(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||
if (sender.hasPermission("celeste.reload")) {
|
||||
celeste.reload();
|
||||
sender.sendMessage("Celeste has been reloaded");
|
||||
} else {
|
||||
sender.sendMessage("You do not have permission to use this command");
|
||||
}
|
||||
return true;
|
||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("info")) {
|
||||
String version = "1.0";
|
||||
if (sender.hasPermission("celeste.info")) {
|
||||
sender.sendMessage("Celeste-OG" + version);
|
||||
sender.sendMessage("Shooting stars: " + (celeste.getConfig().getBoolean("shooting-stars-enabled") ? "Enabled" : "Disabled"));
|
||||
sender.sendMessage("Falling stars: " + (celeste.getConfig().getBoolean("falling-stars-enabled") ? "Enabled" : "Disabled"));
|
||||
sender.sendMessage("Meteor showers: " + (celeste.getConfig().getBoolean("new-moon-meteor-shower") ? "Enabled" : "Disabled"));
|
||||
} else {
|
||||
sender.sendMessage("You do not have permission to use this command");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public CommandCeleste(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||
if (sender.hasPermission("celeste.reload")) {
|
||||
celeste.reload();
|
||||
sender.sendMessage("Celeste has been reloaded");
|
||||
} else {
|
||||
sender.sendMessage("You do not have permission to use this command");
|
||||
}
|
||||
return true;
|
||||
} else if (args.length == 1 && args[0].equalsIgnoreCase("info")) {
|
||||
String version = "1.0";
|
||||
if (sender.hasPermission("celeste.info")) {
|
||||
sender.sendMessage("Celeste-OG" + version);
|
||||
sender.sendMessage("Shooting stars: "
|
||||
+ (celeste.getConfig().getBoolean("shooting-stars-enabled") ? "Enabled" : "Disabled"));
|
||||
sender.sendMessage("Falling stars: "
|
||||
+ (celeste.getConfig().getBoolean("falling-stars-enabled") ? "Enabled" : "Disabled"));
|
||||
sender.sendMessage("Meteor showers: "
|
||||
+ (celeste.getConfig().getBoolean("new-moon-meteor-shower") ? "Enabled" : "Disabled"));
|
||||
} else {
|
||||
sender.sendMessage("You do not have permission to use this command");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,40 @@
|
||||
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;
|
||||
Celeste celeste;
|
||||
|
||||
public CommandFallingStar(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length > 0) {
|
||||
if (Bukkit.getPlayer(args[0]) == null) {
|
||||
sender.sendMessage("\u00a7cError: Player not found.");
|
||||
return true;
|
||||
}
|
||||
CelestialSphere.createFallingStar(celeste, Bukkit.getPlayer(args[0]), false);
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
CelestialSphere.createFallingStar(celeste, player, false);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String message = this.celeste.getConfig().getString("falling-stars-summon-text");
|
||||
if (message != null) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public CommandFallingStar(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length > 0) {
|
||||
if (Bukkit.getPlayer(args[0]) == null) {
|
||||
sender.sendMessage("\u00a7cError: Player not found.");
|
||||
return true;
|
||||
}
|
||||
CelestialSphere.createFallingStar(celeste, Bukkit.getPlayer(args[0]), false);
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
CelestialSphere.createFallingStar(celeste, player, false);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String message = this.celeste.getConfig().getString("falling-stars-summon-text");
|
||||
if (message != null) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,40 @@
|
||||
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;
|
||||
Celeste celeste;
|
||||
|
||||
public CommandShootingStar(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length > 0) {
|
||||
if (Bukkit.getPlayer(args[0]) == null) {
|
||||
sender.sendMessage("\u00a7cError: Player not found.");
|
||||
return true;
|
||||
}
|
||||
CelestialSphere.createShootingStar(celeste, Bukkit.getPlayer(args[0]), false);
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
CelestialSphere.createShootingStar(celeste, player, false);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String message = this.celeste.getConfig().getString("shooting-stars-summon-text");
|
||||
if (message != null) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public CommandShootingStar(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length > 0) {
|
||||
if (Bukkit.getPlayer(args[0]) == null) {
|
||||
sender.sendMessage("\u00a7cError: Player not found.");
|
||||
return true;
|
||||
}
|
||||
CelestialSphere.createShootingStar(celeste, Bukkit.getPlayer(args[0]), false);
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
CelestialSphere.createShootingStar(celeste, player, false);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String message = this.celeste.getConfig().getString("shooting-stars-summon-text");
|
||||
if (message != null) {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,113 +1,115 @@
|
||||
package net.trueog.celeste.config;
|
||||
|
||||
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 {
|
||||
public boolean newMoonMeteorShower;
|
||||
public int beginSpawningStarsTime;
|
||||
public int endSpawningStarsTime;
|
||||
public boolean newMoonMeteorShower;
|
||||
public int beginSpawningStarsTime;
|
||||
public int endSpawningStarsTime;
|
||||
|
||||
public boolean shootingStarsEnabled;
|
||||
public double shootingStarsPerMinute;
|
||||
public double shootingStarsPerMinuteMeteorShower;
|
||||
public int shootingStarsMinHeight;
|
||||
public int shootingStarsMaxHeight;
|
||||
public boolean shootingStarsEnabled;
|
||||
public double shootingStarsPerMinute;
|
||||
public double shootingStarsPerMinuteMeteorShower;
|
||||
public int shootingStarsMinHeight;
|
||||
public int shootingStarsMaxHeight;
|
||||
|
||||
public boolean fallingStarsEnabled;
|
||||
public double fallingStarsPerMinute;
|
||||
public double fallingStarsPerMinuteMeteorShower;
|
||||
public int fallingStarsRadius;
|
||||
public boolean fallingStarsSoundEnabled;
|
||||
public double fallingStarsVolume;
|
||||
public int fallingStarsSparkTime;
|
||||
public int fallingStarsExperience;
|
||||
public WeightedRandomBag<String> fallingStarSimpleLoot;
|
||||
public String fallingStarLootTable;
|
||||
public boolean fallingStarsEnabled;
|
||||
public double fallingStarsPerMinute;
|
||||
public double fallingStarsPerMinuteMeteorShower;
|
||||
public int fallingStarsRadius;
|
||||
public boolean fallingStarsSoundEnabled;
|
||||
public double fallingStarsVolume;
|
||||
public int fallingStarsSparkTime;
|
||||
public int fallingStarsExperience;
|
||||
public WeightedRandomBag<String> fallingStarSimpleLoot;
|
||||
public String fallingStarLootTable;
|
||||
|
||||
public CelesteConfig(ConfigurationSection section) {
|
||||
// Used to build the global config
|
||||
buildFromConfigurationSection(section);
|
||||
}
|
||||
public CelesteConfig(ConfigurationSection section) {
|
||||
// Used to build the global config
|
||||
buildFromConfigurationSection(section);
|
||||
}
|
||||
|
||||
public CelesteConfig(ConfigurationSection section, CelesteConfig globalConfig) {
|
||||
// Used to build per-world configs
|
||||
buildFromConfigurationSectionWithGlobal(section, globalConfig);
|
||||
}
|
||||
public CelesteConfig(ConfigurationSection section, CelesteConfig globalConfig) {
|
||||
// Used to build per-world configs
|
||||
buildFromConfigurationSectionWithGlobal(section, globalConfig);
|
||||
}
|
||||
|
||||
private void buildFromConfigurationSection(ConfigurationSection section) {
|
||||
newMoonMeteorShower = section.getBoolean("new-moon-meteor-shower");
|
||||
beginSpawningStarsTime = section.getInt("begin-spawning-stars-time");
|
||||
endSpawningStarsTime = section.getInt("end-spawning-stars-time");
|
||||
private void buildFromConfigurationSection(ConfigurationSection section) {
|
||||
newMoonMeteorShower = section.getBoolean("new-moon-meteor-shower");
|
||||
beginSpawningStarsTime = section.getInt("begin-spawning-stars-time");
|
||||
endSpawningStarsTime = section.getInt("end-spawning-stars-time");
|
||||
|
||||
shootingStarsEnabled = section.getBoolean("shooting-stars-enabled");
|
||||
shootingStarsPerMinute = section.getDouble("shooting-stars-per-minute");
|
||||
shootingStarsPerMinuteMeteorShower = section.getDouble("shooting-stars-per-minute-during-meteor-showers");
|
||||
shootingStarsMinHeight = section.getInt("shooting-stars-min-height");
|
||||
shootingStarsMaxHeight = section.getInt("shooting-stars-max-height");
|
||||
shootingStarsEnabled = section.getBoolean("shooting-stars-enabled");
|
||||
shootingStarsPerMinute = section.getDouble("shooting-stars-per-minute");
|
||||
shootingStarsPerMinuteMeteorShower = section.getDouble("shooting-stars-per-minute-during-meteor-showers");
|
||||
shootingStarsMinHeight = section.getInt("shooting-stars-min-height");
|
||||
shootingStarsMaxHeight = section.getInt("shooting-stars-max-height");
|
||||
|
||||
fallingStarsEnabled = section.getBoolean("falling-stars-enabled");
|
||||
fallingStarsPerMinute = section.getDouble("falling-stars-per-minute");
|
||||
fallingStarsPerMinuteMeteorShower = section.getDouble("falling-stars-per-minute-during-meteor-showers");
|
||||
fallingStarsRadius = section.getInt("falling-stars-radius");
|
||||
fallingStarsSoundEnabled = section.getBoolean("falling-stars-sound-enabled");
|
||||
fallingStarsVolume = section.getDouble("falling-stars-volume");
|
||||
fallingStarsSparkTime = section.getInt("falling-stars-spark-time");
|
||||
fallingStarsExperience = section.getInt("falling-stars-experience");
|
||||
fallingStarsEnabled = section.getBoolean("falling-stars-enabled");
|
||||
fallingStarsPerMinute = section.getDouble("falling-stars-per-minute");
|
||||
fallingStarsPerMinuteMeteorShower = section.getDouble("falling-stars-per-minute-during-meteor-showers");
|
||||
fallingStarsRadius = section.getInt("falling-stars-radius");
|
||||
fallingStarsSoundEnabled = section.getBoolean("falling-stars-sound-enabled");
|
||||
fallingStarsVolume = section.getDouble("falling-stars-volume");
|
||||
fallingStarsSparkTime = section.getInt("falling-stars-spark-time");
|
||||
fallingStarsExperience = section.getInt("falling-stars-experience");
|
||||
|
||||
fallingStarLootTable = section.getString("falling-stars-loot-table");
|
||||
if (section.isSet("falling-stars-loot")) {
|
||||
fallingStarSimpleLoot = calculateSimpleLoot(section.getConfigurationSection("falling-stars-loot"));
|
||||
}
|
||||
}
|
||||
fallingStarLootTable = section.getString("falling-stars-loot-table");
|
||||
if (section.isSet("falling-stars-loot")) {
|
||||
fallingStarSimpleLoot = calculateSimpleLoot(section.getConfigurationSection("falling-stars-loot"));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildFromConfigurationSectionWithGlobal(ConfigurationSection section, CelesteConfig globalConfig) {
|
||||
newMoonMeteorShower = section.getBoolean("new-moon-meteor-shower", globalConfig.newMoonMeteorShower);
|
||||
beginSpawningStarsTime = section.getInt("begin-spawning-stars-time", globalConfig.beginSpawningStarsTime);
|
||||
endSpawningStarsTime = section.getInt("end-spawning-stars-time", globalConfig.endSpawningStarsTime);
|
||||
private void buildFromConfigurationSectionWithGlobal(ConfigurationSection section, CelesteConfig globalConfig) {
|
||||
newMoonMeteorShower = section.getBoolean("new-moon-meteor-shower", globalConfig.newMoonMeteorShower);
|
||||
beginSpawningStarsTime = section.getInt("begin-spawning-stars-time", globalConfig.beginSpawningStarsTime);
|
||||
endSpawningStarsTime = section.getInt("end-spawning-stars-time", globalConfig.endSpawningStarsTime);
|
||||
|
||||
shootingStarsEnabled = section.getBoolean("shooting-stars-enabled", globalConfig.shootingStarsEnabled);
|
||||
shootingStarsPerMinute = section.getDouble("shooting-stars-per-minute", globalConfig.shootingStarsPerMinute);
|
||||
shootingStarsPerMinuteMeteorShower = section.getDouble("shooting-stars-per-minute-during-meteor-showers", globalConfig.shootingStarsPerMinuteMeteorShower);
|
||||
shootingStarsMinHeight = section.getInt("shooting-stars-min-height", globalConfig.shootingStarsMinHeight);
|
||||
shootingStarsMaxHeight = section.getInt("shooting-stars-max-height", globalConfig.shootingStarsMaxHeight);
|
||||
shootingStarsEnabled = section.getBoolean("shooting-stars-enabled", globalConfig.shootingStarsEnabled);
|
||||
shootingStarsPerMinute = section.getDouble("shooting-stars-per-minute", globalConfig.shootingStarsPerMinute);
|
||||
shootingStarsPerMinuteMeteorShower = section.getDouble(
|
||||
"shooting-stars-per-minute-during-meteor-showers", globalConfig.shootingStarsPerMinuteMeteorShower);
|
||||
shootingStarsMinHeight = section.getInt("shooting-stars-min-height", globalConfig.shootingStarsMinHeight);
|
||||
shootingStarsMaxHeight = section.getInt("shooting-stars-max-height", globalConfig.shootingStarsMaxHeight);
|
||||
|
||||
fallingStarsEnabled = section.getBoolean("falling-stars-enabled", globalConfig.fallingStarsEnabled);
|
||||
fallingStarsPerMinute = section.getDouble("falling-stars-per-minute", globalConfig.fallingStarsPerMinute);
|
||||
fallingStarsPerMinuteMeteorShower = section.getDouble("falling-stars-per-minute-during-meteor-showers", globalConfig.fallingStarsPerMinuteMeteorShower);
|
||||
fallingStarsRadius = section.getInt("falling-stars-radius", globalConfig.fallingStarsRadius);
|
||||
fallingStarsSoundEnabled = section.getBoolean("falling-stars-sound-enabled", globalConfig.fallingStarsSoundEnabled);
|
||||
fallingStarsVolume = section.getDouble("falling-stars-volume", globalConfig.fallingStarsVolume);
|
||||
fallingStarsSparkTime = section.getInt("falling-stars-spark-time", globalConfig.fallingStarsSparkTime);
|
||||
fallingStarsExperience = section.getInt("falling-stars-experience", globalConfig.fallingStarsExperience);
|
||||
fallingStarsEnabled = section.getBoolean("falling-stars-enabled", globalConfig.fallingStarsEnabled);
|
||||
fallingStarsPerMinute = section.getDouble("falling-stars-per-minute", globalConfig.fallingStarsPerMinute);
|
||||
fallingStarsPerMinuteMeteorShower = section.getDouble(
|
||||
"falling-stars-per-minute-during-meteor-showers", globalConfig.fallingStarsPerMinuteMeteorShower);
|
||||
fallingStarsRadius = section.getInt("falling-stars-radius", globalConfig.fallingStarsRadius);
|
||||
fallingStarsSoundEnabled =
|
||||
section.getBoolean("falling-stars-sound-enabled", globalConfig.fallingStarsSoundEnabled);
|
||||
fallingStarsVolume = section.getDouble("falling-stars-volume", globalConfig.fallingStarsVolume);
|
||||
fallingStarsSparkTime = section.getInt("falling-stars-spark-time", globalConfig.fallingStarsSparkTime);
|
||||
fallingStarsExperience = section.getInt("falling-stars-experience", globalConfig.fallingStarsExperience);
|
||||
|
||||
if (section.isSet("falling-stars-loot") || section.isSet("falling-stars-loot-table")) {
|
||||
// Ensure that neither type of loot is inherited from the global config if any overrides are used
|
||||
// This means that even if the global config sets simple loot and the world config overrides just loot
|
||||
// table, the end result will be a config with the loot table set and the simple table empty
|
||||
fallingStarLootTable = section.getString("falling-stars-loot-table");
|
||||
if (section.isSet("falling-stars-loot")) {
|
||||
fallingStarSimpleLoot = calculateSimpleLoot(section.getConfigurationSection("falling-stars-loot"));
|
||||
}
|
||||
} else {
|
||||
fallingStarLootTable = globalConfig.fallingStarLootTable;
|
||||
fallingStarSimpleLoot = globalConfig.fallingStarSimpleLoot;
|
||||
}
|
||||
}
|
||||
if (section.isSet("falling-stars-loot") || section.isSet("falling-stars-loot-table")) {
|
||||
// Ensure that neither type of loot is inherited from the global config if any overrides are used
|
||||
// This means that even if the global config sets simple loot and the world config overrides just loot
|
||||
// table, the end result will be a config with the loot table set and the simple table empty
|
||||
fallingStarLootTable = section.getString("falling-stars-loot-table");
|
||||
if (section.isSet("falling-stars-loot")) {
|
||||
fallingStarSimpleLoot = calculateSimpleLoot(section.getConfigurationSection("falling-stars-loot"));
|
||||
}
|
||||
} else {
|
||||
fallingStarLootTable = globalConfig.fallingStarLootTable;
|
||||
fallingStarSimpleLoot = globalConfig.fallingStarSimpleLoot;
|
||||
}
|
||||
}
|
||||
|
||||
public WeightedRandomBag<String> calculateSimpleLoot(ConfigurationSection loot) {
|
||||
WeightedRandomBag<String> fallingStarDrops = new WeightedRandomBag<>();
|
||||
for (String key : loot.getKeys(false)) {
|
||||
try {
|
||||
Material.valueOf(key.toUpperCase());
|
||||
fallingStarDrops.addEntry(key.toUpperCase(), loot.getDouble(key));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Celeste.getLogger("Error: Item with name " + key.toUpperCase() + " does not exist, skipping");
|
||||
}
|
||||
}
|
||||
return fallingStarDrops;
|
||||
}
|
||||
public WeightedRandomBag<String> calculateSimpleLoot(ConfigurationSection loot) {
|
||||
WeightedRandomBag<String> fallingStarDrops = new WeightedRandomBag<>();
|
||||
for (String key : loot.getKeys(false)) {
|
||||
try {
|
||||
Material.valueOf(key.toUpperCase());
|
||||
fallingStarDrops.addEntry(key.toUpperCase(), loot.getDouble(key));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Celeste.getLogger("Error: Item with name " + key.toUpperCase() + " does not exist, skipping");
|
||||
}
|
||||
}
|
||||
return fallingStarDrops;
|
||||
}
|
||||
}
|
||||
@@ -2,58 +2,60 @@ package net.trueog.celeste.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.trueog.celeste.Celeste;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import net.trueog.celeste.Celeste;
|
||||
|
||||
public class CelesteConfigManager {
|
||||
|
||||
private final Celeste celeste;
|
||||
private final Map<String, CelesteConfig> worldConfigs = new HashMap<>();
|
||||
private CelesteConfig globalConfig;
|
||||
private final Celeste celeste;
|
||||
private final Map<String, CelesteConfig> worldConfigs = new HashMap<>();
|
||||
private CelesteConfig globalConfig;
|
||||
|
||||
public CelesteConfigManager(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
public CelesteConfigManager(Celeste celeste) {
|
||||
this.celeste = celeste;
|
||||
}
|
||||
|
||||
public void processConfigs() {
|
||||
this.worldConfigs.clear();
|
||||
FileConfiguration config = this.celeste.getConfig();
|
||||
globalConfig = new CelesteConfig(config);
|
||||
ConfigurationSection worlds = config.getConfigurationSection("world-overrides");
|
||||
if (worlds != null) {
|
||||
for (String world : worlds.getKeys(false)) {
|
||||
ConfigurationSection worldSettings = worlds.getConfigurationSection(world);
|
||||
if (worldSettings == null) {
|
||||
this.celeste.getLogger().severe("Your world override config for world '" + world + "' is malformed, please review example configs at https://github.com/IdreesInc/Celeste");
|
||||
continue;
|
||||
}
|
||||
CelesteConfig worldConfig = new CelesteConfig(worldSettings, globalConfig);
|
||||
worldConfigs.put(world, worldConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void processConfigs() {
|
||||
this.worldConfigs.clear();
|
||||
FileConfiguration config = this.celeste.getConfig();
|
||||
globalConfig = new CelesteConfig(config);
|
||||
ConfigurationSection worlds = config.getConfigurationSection("world-overrides");
|
||||
if (worlds != null) {
|
||||
for (String world : worlds.getKeys(false)) {
|
||||
ConfigurationSection worldSettings = worlds.getConfigurationSection(world);
|
||||
if (worldSettings == null) {
|
||||
this.celeste
|
||||
.getLogger()
|
||||
.severe(
|
||||
"Your world override config for world '" + world
|
||||
+ "' is malformed, please review example configs at https://github.com/IdreesInc/Celeste");
|
||||
continue;
|
||||
}
|
||||
CelesteConfig worldConfig = new CelesteConfig(worldSettings, globalConfig);
|
||||
worldConfigs.put(world, worldConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config for the given world name (case-sensitive) or the global config if no overrides have been added
|
||||
* @param worldName The name of the world
|
||||
* @return The config that applies to the given world
|
||||
*/
|
||||
public CelesteConfig getConfigForWorld(String worldName) {
|
||||
CelesteConfig config = worldConfigs.get(worldName);
|
||||
if (config == null) {
|
||||
config = globalConfig;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
/**
|
||||
* Get the config for the given world name (case-sensitive) or the global config if no overrides have been added
|
||||
* @param worldName The name of the world
|
||||
* @return The config that applies to the given world
|
||||
*/
|
||||
public CelesteConfig getConfigForWorld(String worldName) {
|
||||
CelesteConfig config = worldConfigs.get(worldName);
|
||||
if (config == null) {
|
||||
config = globalConfig;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the world has been configured with specific overrides in the config file
|
||||
* @return Whether the specified world's configuration has been modified
|
||||
*/
|
||||
public boolean doesWorldHaveOverrides(String worldName) {
|
||||
return worldConfigs.containsKey(worldName);
|
||||
}
|
||||
/**
|
||||
* Check whether the world has been configured with specific overrides in the config file
|
||||
* @return Whether the specified world's configuration has been modified
|
||||
*/
|
||||
public boolean doesWorldHaveOverrides(String worldName) {
|
||||
return worldConfigs.containsKey(worldName);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package net.trueog.celeste.utilities;
|
||||
//From https://gamedev.stackexchange.com/a/162987
|
||||
// From https://gamedev.stackexchange.com/a/162987
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -7,31 +7,31 @@ import java.util.Random;
|
||||
|
||||
public class WeightedRandomBag<T extends Object> {
|
||||
|
||||
private class Entry {
|
||||
double accumulatedWeight;
|
||||
T object;
|
||||
}
|
||||
private class Entry {
|
||||
double accumulatedWeight;
|
||||
T object;
|
||||
}
|
||||
|
||||
public List<Entry> entries = new ArrayList<Entry>();
|
||||
private double accumulatedWeight;
|
||||
private Random rand = new Random();
|
||||
public List<Entry> entries = new ArrayList<Entry>();
|
||||
private double accumulatedWeight;
|
||||
private Random rand = new Random();
|
||||
|
||||
public void addEntry(T object, double weight) {
|
||||
accumulatedWeight += weight;
|
||||
Entry e = new Entry();
|
||||
e.object = object;
|
||||
e.accumulatedWeight = accumulatedWeight;
|
||||
entries.add(e);
|
||||
}
|
||||
public void addEntry(T object, double weight) {
|
||||
accumulatedWeight += weight;
|
||||
Entry e = new Entry();
|
||||
e.object = object;
|
||||
e.accumulatedWeight = accumulatedWeight;
|
||||
entries.add(e);
|
||||
}
|
||||
|
||||
public T getRandom() {
|
||||
double r = rand.nextDouble() * accumulatedWeight;
|
||||
for (Entry entry: entries) {
|
||||
if (entry.accumulatedWeight >= r) {
|
||||
return entry.object;
|
||||
}
|
||||
}
|
||||
// Should only happen when there are no entries
|
||||
return null;
|
||||
}
|
||||
public T getRandom() {
|
||||
double r = rand.nextDouble() * accumulatedWeight;
|
||||
for (Entry entry : entries) {
|
||||
if (entry.accumulatedWeight >= r) {
|
||||
return entry.object;
|
||||
}
|
||||
}
|
||||
// Should only happen when there are no entries
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user