本文整理汇总了Java中ninja.leaping.configurate.loader.ConfigurationLoader.load方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationLoader.load方法的具体用法?Java ConfigurationLoader.load怎么用?Java ConfigurationLoader.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ninja.leaping.configurate.loader.ConfigurationLoader
的用法示例。
在下文中一共展示了ConfigurationLoader.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Config
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public Config(String name, boolean auto_save) {
this.name = name;
try {
file = new File(GWMCrates.getInstance().getConfigDirectory(), name);
loader = HoconConfigurationLoader.builder().setFile(file).build();
node = loader.load();
if (!file.exists()) {
file.createNewFile();
URL defaultsURL = GWMCrates.class.getResource("/" + name);
ConfigurationLoader<CommentedConfigurationNode> defaultsLoader =
HoconConfigurationLoader.builder().setURL(defaultsURL).build();
ConfigurationNode defaultsNode = defaultsLoader.load();
node.mergeValuesFrom(defaultsNode);
Sponge.getScheduler().createTaskBuilder().delayTicks(1).execute(this::save).
submit(GWMCrates.getInstance());
}
if (auto_save) {
Sponge.getScheduler().createTaskBuilder().async().execute(this::save).
interval(AUTO_SAVE_INTERVAL, TimeUnit.SECONDS).submit(GWMCrates.getInstance());
}
} catch (Exception e) {
GWMCrates.getInstance().getLogger().warn("Failed initialize config \"" + getName() + "\"!", e);
}
}
示例2: addPlayer
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public static void addPlayer(UUID playerUUID)
{
Path playerFile = Paths.get(EagleFactions.getEagleFactions ().getConfigDir().resolve("players") + "/" + playerUUID.toString() + ".conf");
try
{
Files.createFile(playerFile);
ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(playerFile).build();
CommentedConfigurationNode playerNode = configLoader.load();
playerNode.getNode("power").setValue(MainLogic.getStartingPower());
playerNode.getNode("maxpower").setValue(MainLogic.getGlobalMaxPower());
configLoader.save(playerNode);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
示例3: getPlayerMaxPower
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public static BigDecimal getPlayerMaxPower(UUID playerUUID)
{
Path playerFile = Paths.get(EagleFactions.getEagleFactions ().getConfigDir().resolve("players") + "/" + playerUUID.toString() + ".conf");
try
{
ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(playerFile).build();
CommentedConfigurationNode playerNode = configLoader.load();
BigDecimal playerMaxPower = new BigDecimal(playerNode.getNode("maxpower").getString());
return playerMaxPower;
}
catch (Exception exception)
{
exception.printStackTrace();
}
return BigDecimal.ZERO;
}
示例4: setPower
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public static void setPower(UUID playerUUID, BigDecimal power)
{
Path playerFile = Paths.get(EagleFactions.getEagleFactions ().getConfigDir().resolve("players") + "/" + playerUUID.toString() + ".conf");
try
{
ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(playerFile).build();
CommentedConfigurationNode playerNode = configLoader.load();
playerNode.getNode("power").setValue(power);
configLoader.save(playerNode);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
示例5: setMaxPower
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public static void setMaxPower(UUID playerUUID, BigDecimal power)
{
Path playerFile = Paths.get(EagleFactions.getEagleFactions ().getConfigDir().resolve("players") + "/" + playerUUID.toString() + ".conf");
try
{
ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(playerFile).build();
CommentedConfigurationNode playerNode = configLoader.load();
playerNode.getNode("maxpower").setValue(power);
configLoader.save(playerNode);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
示例6: setPlayerChunkPosition
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
public static void setPlayerChunkPosition(UUID playerUUID, Vector3i chunk)
{
Path playerFile = Paths.get(EagleFactions.getEagleFactions ().getConfigDir().resolve("players") + "/" + playerUUID.toString() + ".conf");
try
{
ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(playerFile).build();
CommentedConfigurationNode playerNode = configLoader.load();
if(chunk != null)
{
playerNode.getNode("chunkPosition").setValue(chunk.toString());
}
else
{
playerNode.getNode("chunkPosition").setValue(null);
}
configLoader.save(playerNode);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
示例7: createConfig
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的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;
}
}
示例8: loadConfig
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的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;
}
}
示例9: loadMessages
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的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;
}
}
示例10: reloadConfig
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
private void reloadConfig() throws IOException {
checkConfigDir();
Path configFile = Paths.get(configDir + "/config.conf");
if (Files.notExists(configFile)) {
InputStream defaultConfig = getClass().getResourceAsStream("defaultConfig.conf");
try (FileWriter writer = new FileWriter(configFile.toFile())) {
IOUtils.copy(defaultConfig, writer);
} catch (IOException e) {
e.printStackTrace();
}
}
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(configFile).build();
rootNode = loader.load();
}
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:20,代码来源:SpongeUniversalMinecraftAPI.java
示例11: reloadUserConfig
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
private void reloadUserConfig() throws IOException {
checkConfigDir();
Path usersConfigFile = Paths.get(configDir + "/users.conf");
if (Files.notExists(usersConfigFile)) {
InputStream defaultConfig = getClass().getResourceAsStream("defaultUsers.conf");
try (FileWriter writer = new FileWriter(usersConfigFile.toFile())) {
IOUtils.copy(defaultConfig, writer);
} catch (IOException e) {
e.printStackTrace();
}
}
ConfigurationLoader<CommentedConfigurationNode> usersLoader = HoconConfigurationLoader.builder().setPath(usersConfigFile).build();
usersNode = usersLoader.load();
}
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:20,代码来源:SpongeUniversalMinecraftAPI.java
示例12: testDefaultUsersConfigLoads
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
@Test
public void testDefaultUsersConfigLoads() throws Exception {
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder()
.setPath(Paths.get(getClass().getResource("defaultUsers.conf").toURI()))
.build();
CommentedConfigurationNode root = loader.load();
UsersConfiguration configuration = SpongeConfigurationLoader.loadUsersConfiguration(root);
assertEquals(2, configuration.getUsers().size());
assertEquals(2, configuration.getGroups().size());
GroupSection firstGroup = configuration.getGroups().get(0);
assertEquals("default", firstGroup.getName());
assertEquals(0, firstGroup.getDefaultPermission());
assertEquals(0, firstGroup.getInheritsFrom().size());
assertEquals(3, firstGroup.getPermissions().size());
assertThat(firstGroup.getPermissions(), hasItem(PermissionSection.builder().name("players").value(10).build()));
assertThat(firstGroup.getPermissions(), hasItem(PermissionSection.builder().name("players.get").value(1).build()));
assertThat(firstGroup.getPermissions(), hasItem(PermissionSection.builder().name("uma").value(1).build()));
}
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:23,代码来源:SpongeConfigurationLoaderTest.java
示例13: testSimpleLoading
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的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));
}
示例14: testSimpleLoading
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
@Test
public void testSimpleLoading() throws IOException {
URL url = getClass().getResource("/example.json");
final Path tempFile = folder.newFile().toPath();
ConfigurationLoader<ConfigurationNode> loader = GsonConfigurationLoader.builder()
.setSource(() -> new BufferedReader(new InputStreamReader(url.openStream())))
.setSink(AtomicFiles.createAtomicWriterFactory(tempFile, UTF_8)).setLenient(true).build();
ConfigurationNode node = loader.load(loader.getDefaultOptions().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());
assertTrue(node.getNode("int-val").getValue() instanceof Integer);
assertTrue(node.getNode("double-val").getValue() instanceof Double);
loader.save(node);
assertEquals(Resources.readLines(url, UTF_8), Files.readAllLines(tempFile, UTF_8));
}
示例15: get
import ninja.leaping.configurate.loader.ConfigurationLoader; //导入方法依赖的package包/类
@Override
public ConfigurationNode get() {
ConfigurationNode configNode = null;
if(((SpongeModuleController) moduleWrapper.getOwner()).getConfigurationDirectory() != null) {
try {
File legacyConfig = new File(((SpongeModuleController) moduleWrapper.getOwner()).getConfigurationDirectory(), moduleWrapper.getName() + ".conf");
File config = new File(((SpongeModuleController) moduleWrapper.getOwner()).getConfigurationDirectory(), moduleWrapper.getId()+ ".conf");
if(!moduleWrapper.getName().equals(moduleWrapper.getId()) && legacyConfig.exists()) {
legacyConfig.renameTo(config);
}
if(!config.exists())
config.createNewFile();
ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setFile(config).build();
configNode = configLoader.load(((SpongeModuleController) moduleWrapper.getOwner()).getConfigurationOptions());
} catch (IOException e) {
e.printStackTrace();
}
}
return configNode;
}