diff --git a/src/main/java/net/knarcraft/dropper/Dropper.java b/src/main/java/net/knarcraft/dropper/Dropper.java index 948056e..1aa5942 100644 --- a/src/main/java/net/knarcraft/dropper/Dropper.java +++ b/src/main/java/net/knarcraft/dropper/Dropper.java @@ -111,10 +111,10 @@ public final class Dropper extends JavaPlugin { // Reload configuration this.reloadConfig(); - configuration.load(); + this.configuration.load(); // Clear record caches - dropperRecordExpansion.clearCaches(); + this.dropperRecordExpansion.clearCaches(); } @Override @@ -137,6 +137,7 @@ public final class Dropper extends JavaPlugin { instance = this; this.saveDefaultConfig(); this.configuration = new DropperConfiguration(this.getConfig()); + this.configuration.load(); this.playerRegistry = new DropperArenaPlayerRegistry(); this.arenaHandler = new DropperArenaHandler(); this.arenaHandler.loadArenas(); diff --git a/src/main/java/net/knarcraft/dropper/config/DropperConfiguration.java b/src/main/java/net/knarcraft/dropper/config/DropperConfiguration.java index 7c2937d..55f8ff4 100644 --- a/src/main/java/net/knarcraft/dropper/config/DropperConfiguration.java +++ b/src/main/java/net/knarcraft/dropper/config/DropperConfiguration.java @@ -170,10 +170,36 @@ public class DropperConfiguration { this.overrideVerticalVelocity = configuration.getBoolean("overrideVerticalVelocity", true); this.liquidHitBoxDepth = configuration.getDouble("liquidHitBoxDepth", -0.8); this.solidHitBoxDistance = configuration.getDouble("solidHitBoxDistance", 0.2); + sanitizeValues(); loadBlockWhitelist(); } + /** + * Sanitizes configuration values to ensure they are within expected bounds + */ + private void sanitizeValues() { + if (this.liquidHitBoxDepth <= -1 || this.liquidHitBoxDepth > 0) { + this.liquidHitBoxDepth = -0.8; + } + + if (this.solidHitBoxDistance <= 0 || this.solidHitBoxDistance > 1) { + this.solidHitBoxDistance = 0.2; + } + + if (this.horizontalVelocity > 1 || this.horizontalVelocity <= 0) { + this.horizontalVelocity = 1; + } + + if (this.verticalVelocity <= 0 || this.verticalVelocity > 75) { + this.verticalVelocity = 1; + } + + if (this.randomlyInvertedTimer <= 0 || this.randomlyInvertedTimer > 3600) { + this.randomlyInvertedTimer = 7; + } + } + /** * Loads the materials specified in the block whitelist */ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6aaea71..5f1b0cc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -12,7 +12,7 @@ dropper: # (inclusive). horizontalVelocity: 1.0 - # The number of seconds before the randomly inverted game-mode switches between normal and inverted movement + # The number of seconds before the randomly inverted game-mode switches between normal and inverted movement (0, 3600] randomlyInvertedTimer: 7 # Whether grouped dropper arenas must be played in the correct sequence @@ -32,11 +32,11 @@ dropper: # pushing each-other if in the same arena. disableHitCollision: true - # This decides how far inside a non-solid block the player must go before detection triggers. The closer to -1 + # This decides how far inside a non-solid block the player must go before detection triggers (-1, 0). The closer to -1 # it is, the more accurate it will seem to the player, but the likelihood of not detecting the hit increases. liquidHitBoxDepth: -0.8 - # This decides the distance the player must be from a block below them before a hit triggers. If too low, the + # This decides the distance the player must be from a block below them before a hit triggers (0, 1). If too low, the # likelihood of detecting the hit decreases, but it won't look like the player hit the block without being near. solidHitBoxDistance: 0.2