本文整理汇总了Java中ninja.leaping.configurate.ConfigurationOptions类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationOptions类的具体用法?Java ConfigurationOptions怎么用?Java ConfigurationOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationOptions类属于ninja.leaping.configurate包,在下文中一共展示了ConfigurationOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
/**
* Loads the given configuration file.
*/
public static void load(Path path) {
System.out.println("Loading config from " + path.toString());
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
loader = HoconConfigurationLoader.builder().setPath(path).build();
configMapper = ObjectMapper.forClass(ObfConfig.class).bindToNew();
node = loader.load(ConfigurationOptions.defaults().setHeader(HEADER));
config = configMapper.populate(node);
configMapper.serialize(node);
loader.save(node);
} catch (Exception e) {
System.err.println("Error loading configuration:");
e.printStackTrace();
}
}
示例2: save
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void save(@NotNull Object object) throws DataHandlingException {
try {
String header = getComments(object.getClass(), true);
CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root(ConfigurationOptions.defaults().setHeader(header));
Object serialized = SerializableConfig.serialize(object, serializerSet);
node = node.setValue(serialized);
if (commentsEnabled) {
node = addComments(FieldMapper.getFieldMap(object.getClass()), node);
}
getLoader().save(node);
} catch (IOException e) {
throw new DataHandlingException(e);
}
}
示例3: createConfig
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
/**
* Creates a config object of the specified type
*
* @param file The {@link Path} where the config file will be created
* @param clazz The {@link Class} of the object that is being retrieved
* @param loader The {@link ConfigurationLoader} that this config will use
* @param <M> The type of object which will be created
* @return The created config object, or null if an exception was thrown
*/
@SuppressWarnings("unchecked")
public <M extends BaseConfig> M createConfig(Path file, Class<M> clazz, ConfigurationLoader loader) {
try {
if (!Files.exists(file)) {
Files.createFile(file);
}
TypeToken<M> token = TypeToken.of(clazz);
ConfigurationNode node = loader.load(ConfigurationOptions.defaults().setObjectMapperFactory(this.factory));
M config = node.getValue(token, clazz.newInstance());
config.init(loader, node, token);
config.save();
return config;
} catch (IOException | ObjectMappingException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
return null;
}
}
示例4: load
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
/**
* Loads the given configuration file.
*/
public static void load(Path path) {
System.out.println("Loading config from " + path.toString());
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
loader = HoconConfigurationLoader.builder().setPath(path).build();
configMapper = ObjectMapper.forClass(ConfigBase.class).bindToNew();
node = loader.load(ConfigurationOptions.defaults().setHeader(HEADER));
config = configMapper.populate(node);
configMapper.serialize(node);
loader.save(node);
} catch (Exception e) {
System.err.println("Error loading configuration:");
e.printStackTrace();
}
}
示例5: loadConfig
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
public boolean loadConfig() {
try {
File file = new File(plugin.getConfigDir(), "catclearlag.conf");
if (!file.exists()) {
file.createNewFile();
}
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setFile(file).build();
CommentedConfigurationNode config = loader.load(ConfigurationOptions.defaults().setObjectMapperFactory(plugin.getFactory()).setShouldCopyDefaults(true));
cclConfig = config.getValue(TypeToken.of(CCLConfig.class), new CCLConfig());
loader.save(config);
return true;
} catch (Exception e) {
plugin.getLogger().error("Could not load config.", e);
return false;
}
}
示例6: loadMessages
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
public boolean loadMessages() {
try {
File file = new File(plugin.getConfigDir(), "messages.conf");
if (!file.exists()) {
file.createNewFile();
}
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setFile(file).build();
CommentedConfigurationNode config = loader.load(ConfigurationOptions.defaults().setObjectMapperFactory(plugin.getFactory()).setShouldCopyDefaults(true));
messagesConfig = config.getValue(TypeToken.of(MessagesConfig.class), new MessagesConfig());
loader.save(config);
return true;
} catch (Exception e) {
plugin.getLogger().error("Could not load config.", e);
return false;
}
}
示例7: NamedConfiguration
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
public NamedConfiguration(String name) {
try {
File conf = new File(Bedrock.getParentDirectory().getAbsolutePath() + "/" + name + ".conf");
boolean fileCreated = false;
if (!conf.exists()) {
conf.createNewFile();
fileCreated = true;
}
configLoader = HoconConfigurationLoader.builder().setFile(conf).build();
if (fileCreated) {
rootNode = configLoader.createEmptyNode(ConfigurationOptions.defaults());
} else {
rootNode = configLoader.load();
}
// Save
save();
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: loadConfigs
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
public void loadConfigs() {
npcs.clear();
//move legacy config
File lc = new File("config/vhop.conf");
if (lc.exists() && lc.isFile()) {
w("Found legacy config, moving config/vshop.conf to config/cshop/vshop.conf");
try {
File nfc = new File("config/vshop/vshop.conf");
nfc.getParentFile().mkdirs();
lc.renameTo(nfc);
} catch (Exception e) {
logger.error("VillagerShops was unable to move your config to the new location - You'll have to do this manually or your shops won't load!");
}
}
ConfigurationOptions options = ConfigurationOptions.defaults().setSerializers(customSerializer);
try {
ConfigurationNode root = configManager.load(options);
npcs = root.getNode("shops").getValue(NPCguardSerializer.tokenListNPCguard);
} catch (Exception e1) {
e1.printStackTrace();
} finally {
if (npcs == null) npcs = new LinkedList<>();
}
}
示例9: ProvidedModuleContainer
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
/**
* Constructs a {@link ModuleContainer} and starts discovery of the modules.
*
* @param configurationLoader The {@link ConfigurationLoader} that contains details of whether the modules should be enabled or not.
* @param moduleEnabler The {@link ModuleEnabler} that contains the logic to enable modules.
* @param loggerProxy The {@link LoggerProxy} that contains methods to send messages to the logger, or any other source.
* @param onPreEnable The {@link Procedure} to run on pre enable, before modules are pre-enabled.
* @param onEnable The {@link Procedure} to run on enable, before modules are pre-enabled.
* @param onPostEnable The {@link Procedure} to run on post enable, before modules are pre-enabled.
* @param modules The {@link Module}s to load.
* @param function The {@link Function} that converts {@link ConfigurationOptions}.
* @param requireAnnotation Whether modules require a {@link ModuleData} annotation.
* @param processDoNotMerge Whether module configs will have {@link NoMergeIfPresent} annotations processed.
* @param moduleSection The name of the section that contains the module enable/disable switches.
* @param moduleSectionHeader The comment header for the "module" section
*
* @throws QuickStartModuleDiscoveryException if there is an error starting the Module Container.
*/
private <N extends ConfigurationNode> ProvidedModuleContainer(ConfigurationLoader<N> configurationLoader,
LoggerProxy loggerProxy,
ModuleEnabler moduleEnabler,
Procedure onPreEnable,
Procedure onEnable,
Procedure onPostEnable,
Set<Module> modules,
Function<ConfigurationOptions, ConfigurationOptions> function,
boolean requireAnnotation,
boolean processDoNotMerge,
@Nullable Function<Module, String> headerProcessor,
@Nullable Function<Class<? extends Module>, String> descriptionProcessor,
String moduleSection,
@Nullable String moduleSectionHeader)
throws QuickStartModuleDiscoveryException {
super(configurationLoader, loggerProxy, moduleEnabler, onPreEnable, onEnable, onPostEnable, function, requireAnnotation, processDoNotMerge,
headerProcessor, descriptionProcessor, moduleSection, moduleSectionHeader);
moduleMap = modules.stream().collect(Collectors.toMap(Module::getClass, v -> v));
}
示例10: DiscoveryModuleContainer
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
/**
* Constructs a {@link ModuleContainer} and starts discovery of the modules.
*
* @param configurationLoader The {@link ConfigurationLoader} that contains details of whether the modules should be enabled or not.
* @param loader The {@link ClassLoader} that contains the classpath in which the modules are located.
* @param packageBase The root name of the package to scan for modules.
* @param constructor The {@link ModuleConstructor} that contains the logic to construct modules.
* @param enabler The {@link ModuleEnabler} that contains the logic to enable modules.
* @param loggerProxy The {@link LoggerProxy} that contains methods to send messages to the logger, or any other source.
* @param onPreEnable The {@link Procedure} to run on pre enable, before modules are pre-enabled.
* @param onEnable The {@link Procedure} to run on enable, before modules are pre-enabled.
* @param onPostEnable The {@link Procedure} to run on post enable, before modules are pre-enabled.
* @param function The {@link Function} that transforms the {@link ConfigurationOptions}.
* @param requiresAnnotation Whether modules require a {@link ModuleData} annotation.
* @param processDoNotMerge Whether module configs will have {@link NoMergeIfPresent} annotations processed.
* @param moduleSection The name of the section that contains the module enable/disable switches.
* @param moduleSectionHeader The comment header for the "module" section
* @param strategy The strategy to use to get classes on the classpath
*
* @throws QuickStartModuleDiscoveryException if there is an error starting the Module Container.
*/
private <N extends ConfigurationNode> DiscoveryModuleContainer(
ConfigurationLoader<N> configurationLoader,
ClassLoader loader,
String packageBase,
ModuleConstructor constructor,
ModuleEnabler enabler,
LoggerProxy loggerProxy,
Procedure onPreEnable,
Procedure onEnable,
Procedure onPostEnable,
Function<ConfigurationOptions, ConfigurationOptions> function,
boolean requiresAnnotation,
boolean processDoNotMerge,
@Nullable Function<Module, String> headerProcessor,
@Nullable Function<Class<? extends Module>, String> descriptionProcessor,
String moduleSection,
@Nullable String moduleSectionHeader,
ThrownBiFunction<String, ClassLoader, Set<Class<?>>, Exception> strategy) throws QuickStartModuleDiscoveryException {
super(configurationLoader, loggerProxy, enabler, onPreEnable, onEnable, onPostEnable, function, requiresAnnotation, processDoNotMerge,
headerProcessor, descriptionProcessor, moduleSection, moduleSectionHeader);
this.classLoader = loader;
this.constructor = constructor;
this.packageLocation = packageBase;
this.strategy = strategy;
}
示例11: loadConfiguration
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
private void loadConfiguration() {
try {
CommentedConfigurationNode node = configManager.load(ConfigurationOptions.defaults().setObjectMapperFactory(objectMapperFactory));
configuration = node.getValue(TypeToken.of(Configuration.class));
if (configuration == null) {
configuration = new Configuration();
configuration.hotPluginsLocations = new ArrayList<>(1);
configuration.hotPluginsLocations.add(new HotPluginsLocation());
configuration.hotPluginsLocations.get(0).classpathLocations = new ArrayList<>(1);
if (!configPath.toFile().exists()) {
objectMapperFactory.getMapper(Configuration.class).bind(configuration).serialize(node);
configManager.save(node);
}
}
} catch (IOException | ObjectMappingException e) {
throw new IllegalArgumentException("Could not load configuration" , e);
}
}
示例12: testSimpleLoading
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
@Test
public void testSimpleLoading() throws IOException {
URL url = getClass().getResource("/example.json");
final Path tempFile = folder.newFile().toPath();
ConfigurationLoader loader = JSONConfigurationLoader.builder()
.setSource(() -> new BufferedReader(new InputStreamReader(url.openStream(), UTF_8)))
.setSink(AtomicFiles.createAtomicWriterFactory(tempFile, UTF_8)).build();
ConfigurationNode node = loader.load(ConfigurationOptions.defaults().setMapFactory(MapFactories.sortedNatural()));
assertEquals("unicorn", node.getNode("test", "op-level").getValue());
assertEquals("dragon", node.getNode("other", "op-level").getValue());
assertEquals("dog park", node.getNode("other", "location").getValue());
/*CommentedConfigurationNode commentNode = SimpleCommentedConfigurationNode.root();
commentNode.getNode("childOne").setValue("a").setComment("Test comment");
commentNode.getNode("childTwo", "something").setValue("b").setComment("Test comment 2");
commentNode.getNode("childTwo", "another").setValue("b").setComment("Test comment 3");
*/
loader.save(node);
assertEquals(Resources.readLines(url, UTF_8), Files
.readAllLines(tempFile, UTF_8));
}
示例13: testBooleansNotShared
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
@Test
public void testBooleansNotShared() throws IOException {
URL url = getClass().getResource("/comments-test.conf");
final Path saveTo = folder.newFile().toPath();
HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
.setPath(saveTo).setURL(url).build();
CommentedConfigurationNode node = loader.createEmptyNode(ConfigurationOptions.defaults());
node.getNode("test", "third").setValue(false).setComment("really?");
node.getNode("test", "apple").setComment("fruit").setValue(false);
node.getNode("test", "donut").setValue(true).setComment("tasty");
node.getNode("test", "guacamole").setValue(true).setComment("and chips?");
loader.save(node);
assertEquals(Resources.readLines(url, UTF_8), Files.readAllLines(saveTo, UTF_8));
}
示例14: Storage
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
public Storage(File configuration, ConfigurationLoader<CommentedConfigurationNode> loader) throws IOException {
this.loader = loader;
if (!configuration.exists()) {
configuration.createNewFile();
this.rootNode = this.loader.load(ConfigurationOptions.defaults().setHeader("For details regarding this configuration file please refer "
+ "to our wiki page <https://github.com/InspireNXE/Enquiry/wiki/>"));
this.loader.save(rootNode);
}
this.rootNode = this.loader.load();
this.registerDefaultNode("engines.bing.auth.account-key", "");
this.registerDefaultNode("engines.bing.options.aliases", ImmutableList.of("bing", "b"));
this.registerDefaultNode("engines.bing.options.style.line-format", "&f${resultNumber}. &d${resultTitle}");
this.registerDefaultNode("engines.duckduckgo.options.aliases", ImmutableList.of("duckduckgo", "ddg", "d"));
this.registerDefaultNode("engines.duckduckgo.options.style.line-format", "&f${resultNumber}. &d${resultTitle}");
this.registerDefaultNode("engines.google.auth.api-key", "");
this.registerDefaultNode("engines.google.auth.search-id", "");
this.registerDefaultNode("engines.google.options.aliases", ImmutableList.of("google", "g"));
this.registerDefaultNode("engines.google.options.style.line-format", "&f${resultNumber}. &d${resultTitle}");
}
示例15: loadMapper
import ninja.leaping.configurate.ConfigurationOptions; //导入依赖的package包/类
private <T> void loadMapper(ObjectMapper<T>.BoundInstance mapper
, ConfigurationLoader<CommentedConfigurationNode> loader) {
CommentedConfigurationNode rootNode;
if (mapper != null) {
try {
rootNode = loader.load(ConfigurationOptions.defaults().setShouldCopyDefaults(true));
//load the config into the object
mapper.populate(rootNode);
//add missing default values
loader.save(rootNode);
} catch (ObjectMappingException objMappingExc) {
logger.error("Error loading the configuration", objMappingExc);
} catch (IOException ioExc) {
logger.error("Error saving the default configuration", ioExc);
}
}
}