Eklentileri yapılandırma

Uyarı

These docs were written for SpongeAPI 7 and are likely out of date. If you feel like you can help update them, please submit a PR!

Konfigürasyon dosyaları eklentilerin veriyi depolamasına izin verirken, sunucu yöneticilerinin bir eklentinin belirli bölümleri üzerinde kontrolü kolayca almalarına izin verirler, eğer izin verirseniz. Sponge, yapılandırma dosyalarını kolayca idare etmenize izin vermek için yapılandırma’yı kullanır. Bu sayfalarda yapılandırma dosyalarını tam olarak kullanabilmek için Configurate’in nasıl kullanılacağı açıklanacaktır.

Tüyo

See the official Configurate wiki to gain more in-depth information about working with its components.

Not

Sponge makes use of the HOCON configuration format, a superset of JSON, as the default format for saving configuration files. The rest of this guide will assume you are using HOCON as well. See HOCON’a Giriş more for information regarding the HOCON format. Working with different formats is made relatively similar by the Configurate system, so it should not pose too much of an issue if you use an alternate format instead.

Hızlı başlangıç

Varsayılan eklenti yapılandırması oluşturma

Plugins using SpongeAPI have the option to use one or more configuration files. Configuration files allow plugins to store data, and they allow server administrators to customize plugin options (if applicable).

Varsayılan eklenti yapılandırmanızı getirme

SpongeAPI offers the use of the DefaultConfig annotation on a field or setter method with the type Path to get the default configuration file for your plugin.

If you place the @DefaultConfig annotation on a field with the type ConfigurationLoader<CommentedConfigurationNode> then you can use it to load and save the default config file in the file system. Please keep in mind that the annotated ConfigurationLoader does not use any default config file that you might ship with your jar, unless you explicitly load it.

`` @ DefaultConfig`` açıklaması için bir `` sharedRoot`` boolean gerekir. `` SharedRoot`` öğesini “true`` olarak ayarlarsanız, döndürülen yol adı paylaşılan bir yapılandırma dizininde olacaktır. Bu durumda, eklentinizin yapılandırma dosyası `` your_plugin_id.conf`` olacaktır (“your_plugin_id” in yerine eklentinizin belirtilen kimliğiyle değiştirilir).

Tüyo

Eklenti kimliğinizi yapılandırma hakkında bilgi için: doc: ../ plugin-class.

`` SharedRoot`` öğesini “false`` olarak ayarlarsanız, döndürülen yol adı, eklentinize özgü bir dizinde bulunan” {pluginname}.conf “adlı bir dosyaya başvuracaktır.

`` SharedRoot`` değerini neyin ayarlayacağından emin değilseniz aşağıdakileri göz önünde bulundurun:

  • Gelecekte birden fazla yapılandırma dosyası (karmaşık eklentiler) bulundurmayı planlıyorsanız, değeri “false” olarak ayarlayın.

  • Tek bir yapılandırma dosyasına sahip olmayı planlıyorsanız (daha az karmaşık eklentiler), değeri “true” olarak ayarlayın.

Belirli bir dosya yerine config dizinine işaret eden bir `` Yol`` örneği de elde edebilirsiniz. Sadece: javadoc: ConfigDir açıklaması kullanarak enjekte ettirdiniğiniz, ya` sharedRoot` bir eklentiye özgü dizin için` false` veya paylaşılan yapılandırma dizini elde etmek için` true` olarak ayarlanır.

Not

Yapılandırma ile (ve Sponge) bir “Yol” yerine bir “Dosya” elde etmek mümkün olsa da, “Yol” kullanmanızı öneririz.

** Örnek - Alanı kullanarak ** `` @ DefaultConfig``

import java.nio.file.Path;
import com.google.inject.Inject;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.configurate.CommentedConfigurationNode;
import org.spongepowered.configurate.loader.ConfigurationLoader;

@Inject
@DefaultConfig(sharedRoot = true)
private Path defaultConfig;

@Inject
@DefaultConfig(sharedRoot = true)
private ConfigurationLoader<CommentedConfigurationNode> configManager;

@Inject
@ConfigDir(sharedRoot = false)
private Path privateConfigDir;

Uyarı

When your plugin is running for the first time, returned pathnames for configuration files and directories may not yet exist. If you delegate all reading / writing of files to Configurate, you do not need to worry about non-existent paths as the library will handle them appropriately.

Not

The use of YAML format (https://yaml.org/spec/1.1/) and JSON format (https://www.json.org/) is also supported, but the preferred config format for Sponge plugins is HOCON. Conversion from YAML (or JSON) to HOCON can be automated by using a YAMLConfigurationLoader (or GsonConfigurationLoader) to load the old config and then saving it using a HoconConfigurationLoader.