Refactor language, kits, and event handling
Major refactor and bugfixes across language loading, kit lifecycle, and event handling:
- LanguageManager: Introduce LangData to hold string and list entries, load YAML lists alongside strings, and centralize retrieval (avoid reloading files at access time).
- GameManager: Use apply {} to configure worldBorder more concisely.
- KitManager.clearAll: Handle offline players by cleaning chargeData without calling lifecycle hooks (onActivate/onDeactivate cannot run for offline players).
- GoblinKit: Track per-player steal BukkitTask, cancel tasks on kit removal, only restore kits if player is still alive, and fix inventory removal by removing cached items and cleaning cache.
- KitEventDispatcher: Use null-safe chaining for victim passive hooks and early-return on non-block-position moves to ignore head-rotation events.
- GameStateListener: Add feastStarted flag placeholder and adjust iron ore handling/messages; add TODO for DB update.
- Extensions: Change legacySerializer visibility to internal.
These changes improve stability around scheduled tasks, offline cleanup, and language list support.
This commit is contained in:
@@ -13,8 +13,13 @@ class LanguageManager(
|
||||
private val plugin: JavaPlugin
|
||||
) {
|
||||
|
||||
private data class LangData(
|
||||
val strings: Map<String, String>,
|
||||
val lists: Map<String, List<String>>
|
||||
)
|
||||
|
||||
// Map: Sprachcode -> (Key -> Nachricht)
|
||||
private val languages = ConcurrentHashMap<String, Map<String, String>>()
|
||||
private val languages = ConcurrentHashMap<String, LangData>()
|
||||
private val miniMessage = MiniMessage.miniMessage()
|
||||
private val defaultLanguage = plugin.config.getString("default.language", "en_US")!!
|
||||
|
||||
@@ -37,12 +42,15 @@ class LanguageManager(
|
||||
val langCode = file.nameWithoutExtension
|
||||
val config = YamlConfiguration.loadConfiguration( file )
|
||||
|
||||
val messages = config.getKeys( true )
|
||||
val strings = config.getKeys( true )
|
||||
.filter { config.isString( it ) }
|
||||
.associateWith { config.getString( it ) }
|
||||
.associateWith { config.getString( it )!! }
|
||||
|
||||
languages[ langCode ] = messages as Map<String, String>
|
||||
plugin.logger.info("Sprache geladen: $langCode (${messages.size} Nachrichten)")
|
||||
val lists = config.getKeys( true )
|
||||
.filter { config.isList( it ) }
|
||||
.associateWith { config.getStringList( it ) }
|
||||
|
||||
languages[ langCode ] = LangData( strings, lists )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +70,14 @@ class LanguageManager(
|
||||
{
|
||||
val locale = player.locale().toString()
|
||||
val langMap = languages[ locale ] ?: languages[ defaultLanguage ]
|
||||
return langMap?.get( key ) ?: "<red>Missing Key: $key</red>"
|
||||
return langMap?.strings?.get( key ) ?: "<red>Missing Key: $key</red>"
|
||||
}
|
||||
|
||||
fun getDefaultRawMessage(
|
||||
key: String
|
||||
): String
|
||||
{
|
||||
return languages[ defaultLanguage ]?.get( key ) ?: "<red>Missing Key: $key</red>"
|
||||
return languages[ defaultLanguage ]?.strings?.get( key ) ?: "<red>Missing Key: $key</red>"
|
||||
}
|
||||
|
||||
fun getRawMessageList(
|
||||
@@ -77,25 +85,17 @@ class LanguageManager(
|
||||
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>" )
|
||||
val locale = player.locale().toString()
|
||||
val data = languages[ locale ] ?: languages[ defaultLanguage ]
|
||||
return data?.lists?.get( key ) ?: listOf( "<red>Missing List: $key</red>" )
|
||||
}
|
||||
|
||||
fun getDefaultRawMessageList(
|
||||
key: String
|
||||
): List<String>
|
||||
{
|
||||
val file = File( plugin.dataFolder, "languages/$defaultLanguage.yml" )
|
||||
val config = YamlConfiguration.loadConfiguration( file )
|
||||
return if (config.contains( key )) config.getStringList( key ) else listOf( "<red>Missing List: $key</red>" )
|
||||
val data = languages[ defaultLanguage ]
|
||||
return data?.lists?.get( key ) ?: listOf( "<red>Missing List: $key</red>" )
|
||||
}
|
||||
|
||||
fun getComponent(
|
||||
@@ -116,7 +116,7 @@ class LanguageManager(
|
||||
placeholders: Map<String, String>
|
||||
): Component
|
||||
{
|
||||
val raw = languages[ defaultLanguage ]?.get( key ) ?: "<red>Missing Key: $key</red>"
|
||||
val raw = languages[ defaultLanguage ]?.strings?.get( key ) ?: "<red>Missing Key: $key</red>"
|
||||
val tags = placeholders.map { (k, v) -> Placeholder.parsed( k, v ) }
|
||||
return miniMessage.deserialize( raw, *tags.toTypedArray() )
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user