플러그인 설정
설정 파일은 플러그인이 데이터를 저장하고, 서버 관리자가 플러그인의 특정 부분을 통제할 수 있게 합니다. 쉽게 설정 파일을 조작할 수 있도록 Sponge는 Configurate를 이용합니다. 이 페이지들은 설정 파일을 완전히 이용하기 위해 Configurate를 활용하는 방법을 설명합니다.
팁
See the official Configurate wiki to gain more in-depth information about working with its components.
참고
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 소개 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.
빠르게 시작하기
기본 플러그인 설정 만들기
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).
나만의 플러그인 설정 갖기
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
어노테이션의 요소는 sharedRoot
의 boolean 값을 요구합니다. sharedRoot
을 true
로 대입하면 공용 설정 폴더의 경로가 반환됩니다. 이 경우, 당신의 플러그인 설정 파일명은 다음과 같습니다: your_plugin_id.conf
(“your_plugin_id”는 플러그인 ID로 치환됨)
팁
당신의 플러그인 ID를 설정하는 방법은 :doc:`../plugin-class`를 참조하세요.
If you set sharedRoot
to false
, the returned pathname will refer to a file named {pluginname}.conf
in a
directory specific to your plugin.
sharedRoot
를 어떤 값으로 정할지 고려하는 방법:
앞으로 (복잡한 플러그인으로써) 여러 개의 설정 파일을 만들 계획이라면,
false
가 적절합니다.(간단한 플러그인으로써) 한 개의 설정 파일만 가질 계획이라면,
true
가 적절합니다.
You can also obtain a Path
instance pointing to the config directory instead of a particular file. Just
have it injected using the ConfigDir annotation, either with sharedRoot
set to false
for a plugin
specific directory or to true
to get the shared configuration directory.
참고
While it may be possible to get a File
instead of a Path
, Configurate (and Sponge) recommend using Path
.
Example - Field using @DefaultConfig
import java.nio.file.Path;
import com.google.inject.Inject;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.config.DefaultConfig;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.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;
경고
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.
참고
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.