-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ live config updates & reload command
- Loading branch information
Showing
14 changed files
with
113 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/de/crightgames/blxckoxymoron/paintball/commands/ReloadConfigCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.crightgames.blxckoxymoron.paintball.commands | ||
|
||
import com.mojang.brigadier.Command | ||
import com.mojang.brigadier.builder.ArgumentBuilder | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal | ||
import com.mojang.brigadier.tree.CommandNode | ||
import de.crightgames.blxckoxymoron.paintball.Paintball | ||
import de.crightgames.blxckoxymoron.paintball.game.Countdown | ||
import de.crightgames.blxckoxymoron.paintball.game.Game | ||
import de.crightgames.blxckoxymoron.paintball.util.ThemeBuilder | ||
import org.bukkit.command.CommandSender | ||
|
||
class ReloadConfigCommand : ArgumentBuilder<CommandSender, ReloadConfigCommand>() { | ||
override fun getThis(): ReloadConfigCommand { | ||
return this | ||
} | ||
|
||
override fun build(): CommandNode<CommandSender> { | ||
return literal<CommandSender>("reloadConfig").executes { ctx -> | ||
if (Game.state == Game.GameState.RUNNING) { | ||
ctx.source.sendMessage(ThemeBuilder.themed( | ||
":RED:Can't reload the config while the game is running::" | ||
)) | ||
return@executes Command.SINGLE_SUCCESS | ||
} | ||
Paintball.INSTANCE.reloadConfig() | ||
Countdown.checkAndStart() | ||
ctx.source.sendMessage(ThemeBuilder.themed( | ||
"Config reloaded" | ||
)) | ||
Command.SINGLE_SUCCESS | ||
}.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 7 additions & 9 deletions
16
src/main/java/de/crightgames/blxckoxymoron/paintball/game/config/GameConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 2 additions & 9 deletions
11
src/main/java/de/crightgames/blxckoxymoron/paintball/game/config/ThemeConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/de/crightgames/blxckoxymoron/paintball/util/ConfigObject.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.crightgames.blxckoxymoron.paintball.util | ||
|
||
import de.crightgames.blxckoxymoron.paintball.Paintball | ||
import org.bukkit.configuration.serialization.ConfigurationSerializable | ||
import org.bukkit.configuration.serialization.ConfigurationSerialization | ||
|
||
abstract class ConfigObject<T : ConfigObject<T>> (private val key: String): ConfigurationSerializable { | ||
companion object { | ||
private var wasRegistered = mutableSetOf<String>() | ||
} | ||
|
||
private fun registerConfigClasses() { | ||
if (wasRegistered.contains(this::class.qualifiedName)) return | ||
|
||
ConfigurationSerialization.registerClass(this::class.java) | ||
additionalConfigClasses.forEach(ConfigurationSerialization::registerClass) | ||
|
||
this::class.qualifiedName?.let { wasRegistered.add(it) } | ||
} | ||
|
||
open val additionalConfigClasses: List<Class<out ConfigurationSerializable>> = emptyList() | ||
|
||
fun load(): T { | ||
registerConfigClasses() | ||
return (Paintball.INSTANCE.config.get(key) as? T ?: this as T) | ||
} | ||
|
||
fun save() { | ||
Paintball.INSTANCE.config.set(key, this) | ||
Paintball.INSTANCE.saveConfig() | ||
} | ||
} |