Search in sources :

Example 1 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project TotalEconomy by Erigitic.

the class TEJobManager method reloadJobsConfig.

/**
     * Reloads the job configuration file. Can be used for initial creation of the configuration file
     * or for simply reloading it.
     *
     * @return boolean Was the reload successful?
     */
public boolean reloadJobsConfig() {
    try {
        jobsConfig = jobsLoader.load();
        ConfigurationNode jobsNode = jobsConfig.getNode("jobs");
        if (!jobsFile.exists()) {
            for (Job j : defaultJobsArr) {
                j.populateNode(jobsNode);
            }
            jobsConfig.getNode("salarydelay").setValue(300);
            jobsLoader.save(jobsConfig);
        }
        // Loop through each job node in the configuration file, create a TEJob object from it, and store in a HashMap
        jobsNode.getChildrenMap().forEach((k, jobNode) -> {
            if (jobNode != null) {
                TEJob job = new TEJob(jobNode);
                if (job.isValid()) {
                    jobsMap.put(job.getName(), job);
                }
            }
        });
        return true;
    } catch (IOException e) {
        logger.warn("[TE] An error occurred while creating/loading the jobs configuration file!");
        return false;
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) IOException(java.io.IOException)

Example 2 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project TotalEconomy by Erigitic.

the class WarriorJobSet method populateNode.

@Override
public void populateNode(ConfigurationNode node) {
    ConfigurationNode myNode = node.getNode(SETNAME);
    for (String[] a : REWARDS) {
        ConfigurationNode n = myNode.getNode(a[0], a[1]);
        n.getNode("exp").setValue(a[2]);
        n.getNode("money").setValue(a[3]);
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode)

Example 3 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project Skree by Skelril.

the class ItemSerializer method deserializeItemStack.

public static ItemStack deserializeItemStack(JsonElement element) throws IOException {
    try (StringReader source = new StringReader(element.toString())) {
        try (BufferedReader reader = new BufferedReader(source)) {
            GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setSource(() -> reader).build();
            ConfigurationNode node = loader.load();
            return ItemStack.builder().fromContainer(CONFIGURATION_NODE.translate(node)).build();
        }
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) GsonConfigurationLoader(ninja.leaping.configurate.gson.GsonConfigurationLoader)

Example 4 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project Skree by Skelril.

the class ItemSerializer method serializeItemStack.

public static JsonElement serializeItemStack(ItemStack item) throws IOException {
    try (StringWriter sink = new StringWriter()) {
        try (BufferedWriter writer = new BufferedWriter(sink)) {
            GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setSink(() -> writer).build();
            ConfigurationNode node = CONFIGURATION_NODE.translate(item.toContainer());
            loader.save(node);
            return new JsonParser().parse(sink.toString());
        }
    }
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) GsonConfigurationLoader(ninja.leaping.configurate.gson.GsonConfigurationLoader) JsonParser(com.google.gson.JsonParser)

Example 5 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project HuskyCrates-Sponge by codeHusky.

the class CrateRewardHolderParser method itemToNode.

private static ConfigurationNode itemToNode(ItemStack stack) {
    ConfigurationNode node = HoconConfigurationLoader.builder().build().createEmptyNode();
    if (stack.get(Keys.DISPLAY_NAME).isPresent()) {
        node.getNode("name").setValue(TextSerializers.FORMATTING_CODE.serialize(stack.get(Keys.DISPLAY_NAME).get()));
    } else {
        node.getNode("name").setValue(stack.getItem().getName());
    }
    node.getNode("id").setValue(stack.getItem().getId());
    if (stack.get(Keys.ITEM_LORE).isPresent()) {
        ArrayList<Text> lore = (ArrayList<Text>) stack.get(Keys.ITEM_LORE).get();
        if (lore.size() > 0) {
            ArrayList<String> loreStrings = new ArrayList<>();
            for (Text e : lore) {
                loreStrings.add(TextSerializers.FORMATTING_CODE.serialize(e));
            }
            node.getNode("lore").setValue(loreStrings);
        }
    }
    node.getNode("count").setValue(stack.getQuantity());
    if (stack.get(Keys.ITEM_ENCHANTMENTS).isPresent()) {
        List<ItemEnchantment> encs = stack.get(Keys.ITEM_ENCHANTMENTS).get();
        for (ItemEnchantment e : encs) {
            node.getNode("enchants", e.getEnchantment().getId()).setValue(e.getLevel());
        }
    }
    return node;
}
Also used : ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text)

Aggregations

ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)11 IOException (java.io.IOException)2 CommentedConfigurationNode (ninja.leaping.configurate.commented.CommentedConfigurationNode)2 GsonConfigurationLoader (ninja.leaping.configurate.gson.GsonConfigurationLoader)2 Text (org.spongepowered.api.text.Text)2 TEAccount (com.erigitic.config.TEAccount)1 TECurrency (com.erigitic.config.TECurrency)1 JsonParser (com.google.gson.JsonParser)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 ItemEnchantment (org.spongepowered.api.data.meta.ItemEnchantment)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Currency (org.spongepowered.api.service.economy.Currency)1