feat: typed team settings (cascade per-team → global → default) + in-game GUI
New fr.luc.crcore.team.config module: - TeamSetting<T> (typed, with key/type/default/parser/serializer; factories ofBoolean/ofInt/ofString/ofEnum). - TeamSettings registry: 8 standard settings (FRIENDLY_FIRE, PVP_PROTECTION_SECONDS, MAX_SIZE, MIN_SIZE, RESPAWN_AT_TEAM_SPAWN, TEAM_CHAT_ENABLED, SHOW_TAG_ABOVE_HEAD, TEAM_COLOR_IN_NAME), extensible via register() for game plugins. - TeamConfigService interface with cascade get(team, setting) → per-team override (SQLite) → global YAML → hard default. Persists per- team via TeamRepository.save(), global via YamlConfiguration.save(). - YamlTeamConfigService default impl with bundled crcore-team-config.yml. Storage: - Team.getSettings() Map<String, Object> for per-team overrides. - New SQLite table crcore_team_settings (team_id, key, value, type) with load + write-through persist in SqliteTeamRepository. - Global YAML <plugin>-team-config.yml in dataFolder, auto-created at first boot (template from game plugin's resource of the same name takes priority). New reusable GUI framework fr.luc.crcore.gui: - AbstractInventoryGui (implements InventoryHolder, rebuild() abstract, setButton/setDecoration/clearSlot helpers, onClose hook, openTo()). - GuiClickHandler FunctionalInterface. - GuiListener (single Bukkit listener, detects via getHolder(), ALWAYS cancels clicks even on slots without handlers). - GuiItems builder (named/of/filler + lore/amount/build, '&' color codes translated). Concrete settings GUIs (fr.luc.crcore.team.config.gui): - AbstractSettingsGui base renderer: 27 slots, settings in row 2, booleans = LIME_DYE / GRAY_DYE toggle, integers = BOOK with left +1 / right -1 (shift × 10), strings/enums display-only. - GlobalSettingsGui: writes to YAML on each change. - TeamSettingsGui: writes to per-team overrides, "override active" flag in lore when value differs from global, "Reset all overrides" footer button. New /core team settings [team] subcommand: - No arg → GlobalSettingsGui (perm crcore.team.settings.global). - With arg → TeamSettingsGui (perm crcore.team.settings). - Player-only (Bukkit needs HumanEntity to open inventory). - Lives under /core team to stay modular (objective: split into modules later; everything team-related under /core team). CRCore: buildTeamConfigService() override point, teamConfig()/getTeamConfig() getters, GuiListener.registerOn(plugin) at enable(). CoreCommand, TeamGroupSubCommand and CoreReloadSubCommand extended to receive TeamConfigService. /core reload now reloads messages + broadcasts + team-config. Docs: new section 10 "Paramètres d'équipe", new decisions logged, setup.md tree updated, two new diagrams (team-config + gui). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
@startuml team-config-class-diagram
|
||||
title CR-Core — Team config (class diagram, cascade per-team → global → default)
|
||||
|
||||
skinparam classAttributeIconSize 0
|
||||
hide empty members
|
||||
|
||||
package "fr.luc.crcore.team.config" {
|
||||
|
||||
class "TeamSetting<T>" as TeamSetting <<final>> {
|
||||
- key: String
|
||||
- type: Class<T>
|
||||
- defaultValue: T
|
||||
- kind: Kind
|
||||
- parser: Function<Object,T>
|
||||
- serializer: Function<T,Object>
|
||||
--
|
||||
+ {static} ofBoolean(key, default): TeamSetting<Boolean>
|
||||
+ {static} ofInt(key, default): TeamSetting<Integer>
|
||||
+ {static} ofString(key, default): TeamSetting<String>
|
||||
+ {static} ofEnum(key, default): TeamSetting<E>
|
||||
--
|
||||
+ parse(raw): T
|
||||
+ serialize(value): Object
|
||||
+ getKey() / getType() / getDefaultValue() / getKind()
|
||||
}
|
||||
|
||||
enum "TeamSetting.Kind" as Kind {
|
||||
BOOLEAN
|
||||
INTEGER
|
||||
STRING
|
||||
ENUM
|
||||
}
|
||||
TeamSetting +-- Kind
|
||||
|
||||
class TeamSettings <<utility>> {
|
||||
+ {static} FRIENDLY_FIRE: TeamSetting<Boolean>
|
||||
+ {static} PVP_PROTECTION_SECONDS: TeamSetting<Integer>
|
||||
+ {static} MAX_SIZE: TeamSetting<Integer>
|
||||
+ {static} MIN_SIZE: TeamSetting<Integer>
|
||||
+ {static} RESPAWN_AT_TEAM_SPAWN: TeamSetting<Boolean>
|
||||
+ {static} TEAM_CHAT_ENABLED: TeamSetting<Boolean>
|
||||
+ {static} SHOW_TAG_ABOVE_HEAD: TeamSetting<Boolean>
|
||||
+ {static} TEAM_COLOR_IN_NAME: TeamSetting<Boolean>
|
||||
--
|
||||
+ {static} register(setting): void
|
||||
+ {static} get(key): Optional<TeamSetting<?>>
|
||||
+ {static} all(): Collection<TeamSetting<?>>
|
||||
}
|
||||
TeamSettings ..> TeamSetting
|
||||
|
||||
interface TeamConfigService {
|
||||
+ get(team, setting): T
|
||||
+ getGlobal(setting): T
|
||||
+ setPerTeam(team, setting, value): void
|
||||
+ resetPerTeam(team, setting): void
|
||||
+ setGlobal(setting, value): void
|
||||
+ reload(): void
|
||||
+ hasPerTeamOverride(team, setting): boolean
|
||||
+ getGlobalSnapshot(): Map<TeamSetting<?>, Object>
|
||||
+ getGlobalFileName(): Optional<String>
|
||||
}
|
||||
|
||||
package "fr.luc.crcore.team.config.impl" {
|
||||
class YamlTeamConfigService {
|
||||
- plugin: JavaPlugin
|
||||
- teamRepository: TeamRepository
|
||||
- userFile: File
|
||||
- globalValues: Map<String, Object>
|
||||
--
|
||||
- ensureUserFile(): void
|
||||
- rebuildGlobalValues(): void
|
||||
- persistGlobals(): void
|
||||
}
|
||||
YamlTeamConfigService ..|> TeamConfigService
|
||||
}
|
||||
|
||||
TeamConfigService ..> TeamSetting : reads/writes
|
||||
}
|
||||
|
||||
package "fr.luc.crcore.team" {
|
||||
class Team {
|
||||
- settings: Map<String, Object>
|
||||
+ getSettings(): Map<String, Object>
|
||||
}
|
||||
}
|
||||
|
||||
package "fr.luc.crcore.team.config.gui" {
|
||||
abstract class AbstractSettingsGui {
|
||||
- rebuild() : peint la grille
|
||||
# {abstract} getCurrentValue(setting): T
|
||||
# {abstract} onChange(setting, newValue): void
|
||||
# isOverride(setting): boolean
|
||||
# renderFooter(): void
|
||||
}
|
||||
class GlobalSettingsGui
|
||||
class TeamSettingsGui
|
||||
GlobalSettingsGui --|> AbstractSettingsGui
|
||||
TeamSettingsGui --|> AbstractSettingsGui
|
||||
AbstractSettingsGui --|> "fr.luc.crcore.gui.AbstractInventoryGui"
|
||||
|
||||
GlobalSettingsGui --> TeamConfigService
|
||||
TeamSettingsGui --> TeamConfigService
|
||||
TeamSettingsGui --> Team
|
||||
}
|
||||
|
||||
YamlTeamConfigService --> "fr.luc.crcore.team.TeamRepository" : persists per-team via save()
|
||||
TeamConfigService ..> Team : reads/writes settings map
|
||||
|
||||
note bottom of YamlTeamConfigService
|
||||
Cascade de résolution :
|
||||
1. team.getSettings().get(key) ← override per-team (SQLite)
|
||||
2. globalValues.get(key) ← <plugin>-team-config.yml
|
||||
3. setting.getDefaultValue() ← constante Java
|
||||
|
||||
Le YAML global est ré-écrit à chaque setGlobal() (persistant à crash).
|
||||
Les per-team sont écrits via teamRepository.save(team).
|
||||
end note
|
||||
|
||||
@enduml
|
||||
Reference in New Issue
Block a user