diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f09676..716bf31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.1.0 + +* Improve config ([#5](https://github.com/BlossomMods/BlossomBack/issues/5)) + # 2.0.3 * Update CI diff --git a/README.md b/README.md index 54a5ca0..d53ebee 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,7 @@ the mod at least once. ### TeleportProps -`teleportation`: [TeleportationConfig](https://github.com/BlossomMods/BlossomLib/blob/main/README.md#teleportationconfig) -- +`teleportation`: [TeleportationConfig](https://github.com/BlossomMods/BlossomLib/blob/main/README.md#teleportationconfig) - teleportation settings `standStill`: int - (seconds), how long the player has to stand still before being teleported `cooldown`: int - (seconds), how long the player has to wait after teleporting using this command, before being able to diff --git a/gradle.properties b/gradle.properties index 030d60a..18f109a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Mod Properties -mod_version=2.0.3 +mod_version=2.1.0 supported_versions=1.20;1.20.1 maven_group=dev.codedsakura.blossom mod_slug=BlossomBack @@ -15,4 +15,4 @@ yarn_mappings=build.1 loader_version=0.14.21 # Dependencies -blossomlib_version=2.5.1 +blossomlib_version=2.5.2 diff --git a/src/main/java/dev/codedsakura/blossom/back/BlossomBack.java b/src/main/java/dev/codedsakura/blossom/back/BlossomBack.java index 72ea73f..298878e 100644 --- a/src/main/java/dev/codedsakura/blossom/back/BlossomBack.java +++ b/src/main/java/dev/codedsakura/blossom/back/BlossomBack.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.codedsakura.blossom.lib.BlossomLib; +import dev.codedsakura.blossom.lib.config.BlossomConfig; import dev.codedsakura.blossom.lib.config.ConfigManager; import dev.codedsakura.blossom.lib.permissions.Permissions; import dev.codedsakura.blossom.lib.teleport.TeleportUtils; @@ -29,12 +30,23 @@ public class BlossomBack implements ModInitializer { @Override public void onInitialize() { + if (CONFIG.lastDeath == null) { + LOGGER.trace("updating config from 2.0.3 to ^2.1.0"); + // make new config act as similar as it was previously + CONFIG.lastDeath = new BlossomBackConfig().lastDeath; + CONFIG.lastDeath.enabled = true; + BlossomConfig.save(CONFIG, "BlossomBack.json"); + ConfigManager.refresh(BlossomBackConfig.class); + } + BlossomLib.addCommand(literal("back") - .requires(Permissions.require("blossom.back", true)) + .requires(Permissions.require("blossom.back", true) + .and(p -> CONFIG.back.enabled)) .executes(this::runBack)); BlossomLib.addCommand(literal("lastdeath") - .requires(Permissions.require("blossom.last-death", false)) + .requires(Permissions.require("blossom.last-death", true) + .and(p -> CONFIG.lastDeath.enabled)) .executes(this::runLastDeath)); } @@ -66,16 +78,14 @@ private int runLastDeath(CommandContext ctx) throws Command var destination = deaths.get(player.getUuid()); - LOGGER.trace("back {} ({}) to {}", player.getEntityName(), player.getUuid(), destination); - - boolean joinedConfig = CONFIG.lastDeath == null; + LOGGER.trace("back (death) {} ({}) to {}", player.getEntityName(), player.getUuid(), destination); if (destination != null) { TeleportUtils.teleport( - joinedConfig ? CONFIG.back.teleportation : CONFIG.lastDeath.teleportation, - joinedConfig ? CONFIG.back.standStill : CONFIG.lastDeath.standStill, - joinedConfig ? CONFIG.back.cooldown : CONFIG.lastDeath.cooldown, - joinedConfig ? BlossomBack.class : BlossomLastDeath.class, + CONFIG.lastDeath.teleportation, + CONFIG.lastDeath.standStill, + CONFIG.lastDeath.cooldown, + CONFIG.separateCooldowns ? BlossomLastDeath.class : BlossomBack.class, player, () -> destination ); diff --git a/src/main/java/dev/codedsakura/blossom/back/BlossomBackConfig.java b/src/main/java/dev/codedsakura/blossom/back/BlossomBackConfig.java index 33076f9..5fd2818 100644 --- a/src/main/java/dev/codedsakura/blossom/back/BlossomBackConfig.java +++ b/src/main/java/dev/codedsakura/blossom/back/BlossomBackConfig.java @@ -2,23 +2,34 @@ import dev.codedsakura.blossom.lib.teleport.TeleportConfig; -import org.jetbrains.annotations.Nullable; public class BlossomBackConfig { static class TeleportProps { + boolean enabled = true; + TeleportConfig teleportation = null; - int standStill; - int cooldown; + int standStill = 5; + int cooldown = 120; + + TeleportProps() { + // For default values in GSON serialization + } - public TeleportProps(int standStill, int cooldown) { + public TeleportProps(boolean enabled, int standStill, int cooldown) { + this.enabled = enabled; this.standStill = standStill; this.cooldown = cooldown; } } - TeleportProps back = new TeleportProps(5, 120); - @Nullable - TeleportProps lastDeath = null; + TeleportProps back = new TeleportProps(true, 5, 120); + + TeleportProps lastDeath = new TeleportProps(false, 5, 120); + + boolean separateCooldowns = false; + + boolean persistBack = false; + boolean persistLastDeath = false; }