Class LanguageBootstrap

java.lang.Object
dev.ua.theroer.magicutils.bootstrap.LanguageBootstrap

public final class LanguageBootstrap extends Object
Shared language and Messages wiring for platform bootstrap helpers.

Historically every platform bootstrap (Bukkit, Bungee, Velocity, Fabric, NeoForge) duplicated the same eight language flags, their setters, and the apply/close logic. That logic only touches LanguageManager, Messages, LoggerCore and Platform, all of which are visible from core, so it lives here as the single source of truth. Platform builders own an instance and delegate their language setters to it; command, diagnostics, and messaging wiring stay platform-specific because those types differ per platform.

Terminology: a scope is the owner name a plugin/mod registers its messages under (plugin name or mod id).

  • Constructor Details

    • LanguageBootstrap

      public LanguageBootstrap()
      Creates a language bootstrap with the recommended defaults already applied (every flag on, language "en").
  • Method Details

    • language

      public LanguageBootstrap language(String language)
      Sets the default language code to initialize. Blank values are ignored.
      Parameters:
      language - language code (for example, "en")
      Returns:
      this
    • initLanguage

      public LanguageBootstrap initLanguage(boolean initLanguage)
      Toggles automatic language initialization via LanguageManager.init(String).
      Parameters:
      initLanguage - true to initialize the language on build
      Returns:
      this
    • bindLoggerLanguage

      public LanguageBootstrap bindLoggerLanguage(boolean bindLoggerLanguage)
      Toggles binding the language manager to the logger so log output is localized.
      Parameters:
      bindLoggerLanguage - true to set the logger language manager
      Returns:
      this
    • setMessagesManager

      public LanguageBootstrap setMessagesManager(boolean setMessagesManager)
      Toggles setting the global Messages language manager to this plugin/mod's manager.
      Parameters:
      setMessagesManager - true to set the global manager
      Returns:
      this
    • registerMessages

      public LanguageBootstrap registerMessages(boolean registerMessages)
      Toggles registering a scoped Messages manager keyed by the plugin name or mod id.
      Parameters:
      registerMessages - true to register the scope
      Returns:
      this
    • addMagicUtilsMessages

      public LanguageBootstrap addMagicUtilsMessages(boolean addMagicUtilsMessages)
      Toggles adding the bundled MagicUtils default language entries.
      Parameters:
      addMagicUtilsMessages - true to add bundled defaults
      Returns:
      this
    • bindClientLocaleSync

      public LanguageBootstrap bindClientLocaleSync(boolean bindClientLocaleSync)
      Toggles synchronizing a player's language from client locale updates.
      Parameters:
      bindClientLocaleSync - true to bind client locale synchronization
      Returns:
      this
    • translations

      public LanguageBootstrap translations(@Nullable @Nullable Consumer<LanguageManager> translations)
      Registers plugin/mod translations against the language manager on build.
      Parameters:
      translations - translation registrar
      Returns:
      this
    • withRecommendedDefaults

      public LanguageBootstrap withRecommendedDefaults()
      Applies the recommended defaults: every flag enabled. This is already the initial state, so it exists mainly to make intent explicit and to reset a builder that called minimal().
      Returns:
      this
    • minimal

      public LanguageBootstrap minimal()
      Disables all automatic language wiring for callers that manage the LanguageManager and Messages themselves. Leaves language(String) untouched.
      Returns:
      this
    • bindsClientLocaleSync

      public boolean bindsClientLocaleSync()
      Whether client-locale synchronization should be bound on the runtime.
      Returns:
      true when enabled
    • registersMessages

      public boolean registersMessages()
      Whether a scoped messages registration was requested (drives the close hook that unregisters it).
      Returns:
      true when enabled
    • setsMessagesManager

      public boolean setsMessagesManager()
      Whether the global messages manager was set (drives the close hook that clears it).
      Returns:
      true when enabled
    • apply

      public void apply(String scope, LanguageManager languageManager, LoggerCore logger)
      Runs the byte-identical language/messages wiring against a resolved language manager and logger. Mirrors the former per-platform prepare() bodies exactly.
      Parameters:
      scope - owner name (plugin name or mod id) used for the messages scope
      languageManager - resolved language manager
      logger - resolved logger core
    • bindClientLocaleSync

      public void bindClientLocaleSync(MagicRuntime runtime, Platform platform, LanguageManager languageManager)
      Binds client-locale synchronization on the runtime when enabled. Mirrors the former per-platform buildRuntime() block.
      Parameters:
      runtime - managed runtime
      platform - platform adapter
      languageManager - resolved language manager
    • installMessagesCloseHooks

      public void installMessagesCloseHooks(MagicRuntime runtime, String scope, LanguageManager languageManager)
      Installs the messages-related close hooks on the runtime when the corresponding flags are enabled. Mirrors the former per-platform buildRuntime() close blocks.
      Parameters:
      runtime - managed runtime
      scope - owner name (plugin name or mod id) used for the messages scope
      languageManager - resolved language manager