Skip to content

Commit

Permalink
improve config (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodedSakura committed Jul 20, 2023
1 parent 09ba97c commit e0e9f4f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.0

* Improve config ([#5](https://github.com/BlossomMods/BlossomBack/issues/5))

# 2.0.3

* Update CI
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,4 +15,4 @@ yarn_mappings=build.1
loader_version=0.14.21

# Dependencies
blossomlib_version=2.5.1
blossomlib_version=2.5.2
28 changes: 19 additions & 9 deletions src/main/java/dev/codedsakura/blossom/back/BlossomBack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

Expand Down Expand Up @@ -66,16 +78,14 @@ private int runLastDeath(CommandContext<ServerCommandSource> 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
);
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/dev/codedsakura/blossom/back/BlossomBackConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit e0e9f4f

Please sign in to comment.