Remove legacy modules, add language & scoreboard
Large refactor removing many legacy subsystems (abilities, kit system, database repos, recraft, world manager, extensive config classes, lunar/luckperms integrations and various listeners/commands). Introduces a lightweight LanguageManager, AntiRunningManager, ScoreboardManager, ConnectListener and a SoupListener; simplifies the main SpeedHG plugin to initialize these components and register the connection listener. Build changes: update Gradle wrapper to 8.10, remove paperweight and several external dependencies, add fr.mrmicky:fastboard and simplify shadowJar/build task configuration. Adds default language resource (languages/en_US.yml) and updates plugin/config resources. Purpose: simplify and decouple the plugin, reduce dependency surface and prepare for a leaner, modular rewrite.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package club.mcscrims.speedhg.config
|
||||
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
|
||||
import org.bukkit.configuration.file.YamlConfiguration
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.plugin.java.JavaPlugin
|
||||
import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
class LanguageManager(
|
||||
private val plugin: JavaPlugin
|
||||
) {
|
||||
|
||||
// Map: Sprachcode -> (Key -> Nachricht)
|
||||
private val languages = ConcurrentHashMap<String, Map<String, String>>()
|
||||
private val miniMessage = MiniMessage.miniMessage()
|
||||
private val defaultLanguage = plugin.config.getString("default.language", "en_US")!!
|
||||
|
||||
init {
|
||||
loadLanguages()
|
||||
}
|
||||
|
||||
fun loadLanguages()
|
||||
{
|
||||
languages.clear()
|
||||
val folder = File( plugin.dataFolder, "languages" )
|
||||
|
||||
if ( !folder.exists() ) {
|
||||
folder.mkdirs()
|
||||
createDefault("de_DE")
|
||||
createDefault("en_US")
|
||||
}
|
||||
|
||||
folder.walk().filter { it.extension == "yml" }.forEach { file ->
|
||||
val langCode = file.nameWithoutExtension
|
||||
val config = YamlConfiguration.loadConfiguration( file )
|
||||
|
||||
val messages = config.getKeys( true )
|
||||
.filter { config.isString( it ) }
|
||||
.associateWith { config.getString( it ) }
|
||||
|
||||
languages[ langCode ] = messages as Map<String, String>
|
||||
plugin.logger.info("Sprache geladen: $langCode (${messages.size} Nachrichten)")
|
||||
}
|
||||
}
|
||||
|
||||
private fun createDefault(
|
||||
locale: String
|
||||
) {
|
||||
val fileName = "languages/$locale.yml"
|
||||
if (plugin.getResource( fileName ) != null) {
|
||||
plugin.saveResource( fileName, false )
|
||||
}
|
||||
}
|
||||
|
||||
fun getRawMessage(
|
||||
player: Player,
|
||||
key: String
|
||||
): String
|
||||
{
|
||||
val locale = player.locale().toString()
|
||||
val langMap = languages[ locale ] ?: languages[ defaultLanguage ]
|
||||
return langMap?.get( key ) ?: "<red>Missing Key: $key</red>"
|
||||
}
|
||||
|
||||
fun getRawMessageList(
|
||||
player: Player,
|
||||
key: String
|
||||
): List<String>
|
||||
{
|
||||
var locale = player.locale().toString()
|
||||
val langMap = languages[ locale ]
|
||||
|
||||
if ( langMap == null ) {
|
||||
locale = defaultLanguage
|
||||
}
|
||||
|
||||
val file = File( plugin.dataFolder, "languages/$locale.yml" )
|
||||
val config = YamlConfiguration.loadConfiguration( file )
|
||||
return if (config.contains( key )) config.getStringList( key ) else listOf("<red>Missing List: $key</red>")
|
||||
}
|
||||
|
||||
fun getComponent(
|
||||
player: Player,
|
||||
key: String,
|
||||
placeholders: Map<String, String>
|
||||
): Component
|
||||
{
|
||||
val raw = getRawMessage( player, key )
|
||||
val tags = placeholders.map { (k, v) -> Placeholder.parsed( k, v ) }
|
||||
return miniMessage.deserialize( raw, *tags.toTypedArray() )
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user