当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurationLoader类代码示例

本文整理汇总了Java中ninja.leaping.configurate.loader.ConfigurationLoader的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationLoader类的具体用法?Java ConfigurationLoader怎么用?Java ConfigurationLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConfigurationLoader类属于ninja.leaping.configurate.loader包,在下文中一共展示了ConfigurationLoader类的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);
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:25,代码来源:Config.java

示例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();
    }
}
 
开发者ID:Aquerr,项目名称:EagleFactions,代码行数:22,代码来源:PowerService.java

示例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;
}
 
开发者ID:Aquerr,项目名称:EagleFactions,代码行数:22,代码来源:PowerService.java

示例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();
    }
}
 
开发者ID:Aquerr,项目名称:EagleFactions,代码行数:19,代码来源:PowerService.java

示例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();
    }
}
 
开发者ID:Aquerr,项目名称:EagleFactions,代码行数:19,代码来源:PowerService.java

示例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();
    }
}
 
开发者ID:Aquerr,项目名称:EagleFactions,代码行数:27,代码来源:PlayerService.java

示例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;
    }
}
 
开发者ID:NucleusPowered,项目名称:Phonon,代码行数:28,代码来源:Phonon.java

示例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;
    }
}
 
开发者ID:Time6628,项目名称:CatClearLag,代码行数:17,代码来源:ConfigLoader.java

示例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;
    }
}
 
开发者ID:Time6628,项目名称:CatClearLag,代码行数:17,代码来源:ConfigLoader.java

示例10: loadDefault

import ninja.leaping.configurate.loader.ConfigurationLoader; //导入依赖的package包/类
@Override
protected void loadDefault() {
	if (!this.isNewDirs()) return;
	
	String collection = this.name.split("/")[0];
	Optional<Asset> asset = this.plugin.getPluginContainer().getAsset("collections/" + collection + ".conf");
	if (!asset.isPresent()) {
		this.plugin.getELogger().debug("Asset 'collections/" + collection + ".conf' not found");
		return;
	}
	
	URL jarConfigFile = asset.get().getUrl();
	ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setURL(jarConfigFile).build();
	try {
		this.getNode().setValue(loader.load());
		this.save(true);
	} catch (IOException e) {}
}
 
开发者ID:EverCraft,项目名称:EverPermissions,代码行数:19,代码来源:EConfigSubjectStorage.java

示例11: init

import ninja.leaping.configurate.loader.ConfigurationLoader; //导入依赖的package包/类
public static void init() {
    Logger logger = WebAPI.getLogger();

    logger.info("Loading users...");
    Tuple<ConfigurationLoader, ConfigurationNode> tup =
            Util.loadWithDefaults(configFileName, "defaults/" + configFileName);
    loader = tup.getFirst();
    config = tup.getSecond();

    users.clear();

    try {
        Map<Object, ? extends ConfigurationNode> nodes = config.getNode("users").getChildrenMap();
        for (Map.Entry<Object, ? extends ConfigurationNode> entry : nodes.entrySet()) {
            UserPermission perm = entry.getValue().getValue(TypeToken.of(UserPermission.class));
            users.put(perm.getUsername(), perm);
        }
    } catch (ObjectMappingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:22,代码来源:Users.java

示例12: 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

示例13: 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

示例14: 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

示例15: ProvidedModuleContainer

import ninja.leaping.configurate.loader.ConfigurationLoader; //导入依赖的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));
}
 
开发者ID:NucleusPowered,项目名称:QuickStartModuleLoader,代码行数:38,代码来源:ProvidedModuleContainer.java


注:本文中的ninja.leaping.configurate.loader.ConfigurationLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。