mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
profiles: replace ignoreNextReload with AtomicInteger
When creating a new controls profile, the profile somehow gets reloaded as soon as a config option changes. The reload (from file) hook is then invoked multiple times because of a race condition.
This commit is contained in:
parent
bbf445d82b
commit
b0390fbfa6
@ -178,7 +178,7 @@ interface ProfileManager<T : Profile> {
|
||||
val jsonString = Jackson.MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(data)
|
||||
|
||||
val file = getPath(profile.name).toFile()
|
||||
profile.ignoreNextReload = true
|
||||
profile.ignoreReloads.incrementAndGet()
|
||||
FileUtil.safeSaveToFile(file, jsonString)
|
||||
profile.saved = true
|
||||
} catch (exception: Exception) {
|
||||
@ -259,8 +259,8 @@ interface ProfileManager<T : Profile> {
|
||||
fun watchProfile(profileName: String, path: File = getPath(profileName).toFile()) {
|
||||
FileWatcherService.register(FileWatcher(path.toPath(), arrayOf(StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE)) { _, it ->
|
||||
val profile = profiles[profileName] ?: return@FileWatcher
|
||||
if (profile.ignoreNextReload) {
|
||||
profile.ignoreNextReload = false
|
||||
if (profile.ignoreReloads.get() > 0) {
|
||||
profile.ignoreReloads.decrementAndGet()
|
||||
return@FileWatcher
|
||||
}
|
||||
try {
|
||||
|
@ -17,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.fasterxml.jackson.annotation.JsonMerge
|
||||
import com.fasterxml.jackson.annotation.OptBoolean
|
||||
import de.bixilon.minosoft.config.profile.ProfileManager
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
interface Profile {
|
||||
@get:JsonMerge(OptBoolean.FALSE)
|
||||
@ -29,5 +30,5 @@ interface Profile {
|
||||
@get:JsonIgnore var saved: Boolean
|
||||
@get:JsonIgnore val initializing: Boolean
|
||||
@get:JsonIgnore var reloading: Boolean
|
||||
@get:JsonIgnore var ignoreNextReload: Boolean // used for saving and not instantly reloading
|
||||
@get:JsonIgnore var ignoreReloads: AtomicInteger// used for saving and not instantly reloading
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager.latestVersion
|
||||
import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for accounts
|
||||
@ -41,7 +42,7 @@ class AccountProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -22,6 +22,7 @@ import de.bixilon.minosoft.config.profile.profiles.audio.AudioProfileManager.lat
|
||||
import de.bixilon.minosoft.config.profile.profiles.audio.gui.GuiC
|
||||
import de.bixilon.minosoft.config.profile.profiles.audio.types.TypesC
|
||||
import de.bixilon.minosoft.config.profile.profiles.audio.volume.VolumeC
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for audio
|
||||
@ -34,7 +35,7 @@ class AudioProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -22,6 +22,7 @@ import de.bixilon.minosoft.config.profile.profiles.block.BlockProfileManager.lat
|
||||
import de.bixilon.minosoft.config.profile.profiles.block.outline.OutlineC
|
||||
import de.bixilon.minosoft.config.profile.profiles.block.rendering.RenderingC
|
||||
import de.bixilon.minosoft.data.world.World
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for block rendering
|
||||
@ -34,7 +35,7 @@ class BlockProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -24,6 +24,7 @@ import de.bixilon.minosoft.config.profile.profiles.connection.ConnectionProfileM
|
||||
import de.bixilon.minosoft.config.profile.profiles.connection.signature.SignatureC
|
||||
import de.bixilon.minosoft.config.profile.profiles.connection.skin.SkinC
|
||||
import de.bixilon.minosoft.data.entities.entities.player.Arms
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for connection
|
||||
@ -36,7 +37,7 @@ class ConnectionProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -23,6 +23,7 @@ import de.bixilon.minosoft.config.profile.profiles.controls.ControlsProfileManag
|
||||
import de.bixilon.minosoft.config.profile.profiles.controls.interaction.InteractionC
|
||||
import de.bixilon.minosoft.config.profile.profiles.controls.mouse.MouseC
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for controls
|
||||
@ -35,7 +36,7 @@ class ControlsProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -19,6 +19,7 @@ import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate
|
||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfileManager.latestVersion
|
||||
import de.bixilon.minosoft.config.profile.profiles.entity.hitbox.HitboxC
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for entity
|
||||
@ -31,7 +32,7 @@ class EntityProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -22,6 +22,7 @@ import de.bixilon.minosoft.config.profile.profiles.eros.general.GeneralC
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.server.ServerC
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.text.TextC
|
||||
import de.bixilon.minosoft.config.profile.profiles.eros.theme.ThemeC
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for Eros
|
||||
@ -34,7 +35,7 @@ class ErosProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -23,6 +23,7 @@ import de.bixilon.minosoft.config.profile.profiles.gui.chat.ChatC
|
||||
import de.bixilon.minosoft.config.profile.profiles.gui.confirmation.ConfirmationC
|
||||
import de.bixilon.minosoft.config.profile.profiles.gui.hud.HudC
|
||||
import de.bixilon.minosoft.config.profile.profiles.gui.sign.SignC
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for gui (rendering)
|
||||
@ -35,7 +36,7 @@ class GUIProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -20,6 +20,7 @@ import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate
|
||||
import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.other.OtherProfileManager.latestVersion
|
||||
import de.bixilon.minosoft.config.profile.profiles.other.log.LogC
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for various things that do not fit in any other profile
|
||||
@ -32,7 +33,7 @@ class OtherProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -22,6 +22,7 @@ import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.latestVersion
|
||||
import de.bixilon.minosoft.config.profile.profiles.particle.types.TypesC
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for particle
|
||||
@ -34,7 +35,7 @@ class ParticleProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -29,6 +29,7 @@ import de.bixilon.minosoft.config.profile.profiles.rendering.movement.MovementC
|
||||
import de.bixilon.minosoft.config.profile.profiles.rendering.overlay.OverlayC
|
||||
import de.bixilon.minosoft.config.profile.profiles.rendering.performance.PerformanceC
|
||||
import de.bixilon.minosoft.config.profile.profiles.rendering.sky.SkyC
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for general rendering
|
||||
@ -41,7 +42,7 @@ class RenderingProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
@ -21,6 +21,7 @@ import de.bixilon.minosoft.config.profile.profiles.Profile
|
||||
import de.bixilon.minosoft.config.profile.profiles.resources.ResourcesProfileManager.latestVersion
|
||||
import de.bixilon.minosoft.config.profile.profiles.resources.assets.AssetsC
|
||||
import de.bixilon.minosoft.config.profile.profiles.resources.source.SourceC
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
/**
|
||||
* Profile for resources
|
||||
@ -33,7 +34,7 @@ class ResourcesProfile(
|
||||
private set
|
||||
override var reloading: Boolean = false
|
||||
override var saved: Boolean = true
|
||||
override var ignoreNextReload: Boolean = false
|
||||
override var ignoreReloads = AtomicInteger()
|
||||
override val version: Int = latestVersion
|
||||
override var description by StringDelegate(this, description ?: "")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user