Search in sources :

Example 11 with ConfigurationNode

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

the class LumberjackJobSet 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 12 with ConfigurationNode

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

the class CrateRewardHolderParser method toConfig.

public static ConfigurationNode toConfig(CrateRewardHolder holder) {
    //pretty much just for conversion
    ConfigurationNode toOverwrite = HoconConfigurationLoader.builder().build().createEmptyNode();
    toOverwrite.setValue(itemToNode(holder.getDisplayItem()));
    ConfigurationNode hd = toOverwrite.getNode("huskydata");
    if (holder.getReward().getReward() instanceof String) {
        hd.getNode("reward", "overrideRewardName").setValue(holder.getReward().getRewardName());
        hd.getNode("reward", "command").setValue(holder.getReward().getReward());
        hd.getNode("reward", "type").setValue("command");
    } else {
        if (holder.isDispRewardSimilar()) {
            if (holder.getDisplayItem().getQuantity() != ((ItemStack) holder.getReward().getReward()).getQuantity()) {
                // we are overriding the count, but not the item! :)
                hd.getNode("reward", "overrideCount").setValue(((ItemStack) holder.getReward().getReward()).getQuantity());
            }
        } else {
            hd.getNode("reward", "overrideItem").setValue(itemToNode((ItemStack) holder.getReward().getReward()));
        }
        String checkAgainst;
        if (holder.getDisplayItem().get(Keys.DISPLAY_NAME).isPresent()) {
            checkAgainst = holder.getDisplayItem().get(Keys.DISPLAY_NAME).get().toPlain();
        } else {
            checkAgainst = holder.getDisplayItem().getItem().getName();
        }
        if (!checkAgainst.equals(holder.getReward().getRewardName())) {
            hd.getNode("reward", "overrideRewardName").setValue(holder.getReward().getRewardName());
        }
        hd.getNode("reward", "type").setValue("item");
    }
    hd.getNode("weight").setValue(holder.getChance());
    return toOverwrite;
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 13 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project Almura by AlmuraDev.

the class ServerPageManager method savePage.

public void savePage(Page page, boolean notify) {
    checkNotNull(page);
    final Path path = this.pageRoot.resolve(page.getId() + GuideConfig.EXT_CONFIG_PAGE);
    final ConfigurationLoader<CommentedConfigurationNode> loader = this.createLoader(path);
    final ConfigurationNode rootNode = loader.createEmptyNode();
    rootNode.getNode(GuideConfig.INDEX).setValue(page.getIndex());
    rootNode.getNode(GuideConfig.NAME).setValue(page.getName());
    final ConfigurationNode lastModifiedNode = rootNode.getNode(GuideConfig.LastModified.LAST_MODIFIED);
    lastModifiedNode.getNode(GuideConfig.LastModified.MODIFIER).setValue(page.getLastModifier().toString());
    lastModifiedNode.getNode(GuideConfig.LastModified.TIME).setValue(page.getLastModified().toString());
    final ConfigurationNode createdNode = rootNode.getNode(GuideConfig.Created.CREATED);
    createdNode.getNode(GuideConfig.Created.CREATOR).setValue(page.getCreator().toString());
    createdNode.getNode(GuideConfig.Created.TIME).setValue(page.getCreated().toString());
    // Packet sends up as sectional, since I am a nice guy I'll let them save as ampersand
    rootNode.getNode(GuideConfig.CONTENT).setValue(Page.asFriendlyText(page.getContent()));
    if (notify) {
        for (final Player player : this.game.getServer().getOnlinePlayers()) {
            if (player.hasPermission("almura.guide.page." + page.getId())) {
                manager.sendPopupNotification(player, Text.of("Guide Update"), Text.of("The Guide: (" + page.getName() + ") has been updated!"), 10);
            }
        }
    }
    try {
        loader.save(rootNode);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) Player(org.spongepowered.api.entity.living.player.Player) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) IOException(java.io.IOException)

Example 14 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project Almura by AlmuraDev.

the class ServerPageManager method loadPages.

private boolean loadPages() throws IOException {
    this.pages.clear();
    if (Files.notExists(this.configRoot)) {
        Files.createDirectories(this.configRoot);
    }
    if (Files.notExists(this.pageRoot)) {
        Files.createDirectories(this.pageRoot);
    }
    final PageWalker pageWalker = new PageWalker(this.logger);
    Files.walkFileTree(this.pageRoot, pageWalker);
    pageWalker.found.forEach((pageFile) -> {
        final ConfigurationLoader<CommentedConfigurationNode> loader = this.createLoader(pageFile);
        try {
            final String id = pageFile.getFileName().toString().split("\\.")[0];
            final ConfigurationNode rootNode = loader.load();
            final int index = rootNode.getNode(GuideConfig.INDEX).getInt(0);
            final String name = rootNode.getNode(GuideConfig.NAME).getString(id);
            final String title = rootNode.getNode(GuideConfig.TITLE).getString("");
            final ConfigurationNode lastModifiedNode = rootNode.getNode(GuideConfig.LastModified.LAST_MODIFIED);
            final String lastModifiedModifierRaw = lastModifiedNode.getNode(GuideConfig.LastModified.MODIFIER).getString("");
            UUID lastModifiedModifier;
            try {
                lastModifiedModifier = UUID.fromString(lastModifiedModifierRaw);
            } catch (Exception ex) {
                lastModifiedModifier = new UUID(0L, 0L);
            }
            final String lastModifiedTimeRaw = lastModifiedNode.getString(GuideConfig.LastModified.TIME);
            Instant lastModifiedTime;
            try {
                lastModifiedTime = Instant.parse(lastModifiedTimeRaw);
            } catch (Exception ex) {
                lastModifiedTime = Instant.now();
            }
            final ConfigurationNode createdNode = rootNode.getNode(GuideConfig.Created.CREATED);
            final String createdCreatorRaw = createdNode.getNode(GuideConfig.Created.CREATOR).getString("");
            UUID createdCreator;
            try {
                createdCreator = UUID.fromString(createdCreatorRaw);
            } catch (Exception ex) {
                createdCreator = new UUID(0L, 0L);
            }
            final String createdTimeRaw = lastModifiedNode.getString(GuideConfig.Created.TIME);
            Instant createdTime;
            try {
                createdTime = Instant.parse(createdTimeRaw);
            } catch (Exception ex) {
                createdTime = Instant.now();
            }
            final String content = rootNode.getNode(GuideConfig.CONTENT).getString("");
            final Page page = new Page(id, createdCreator, createdTime);
            page.setIndex(index);
            page.setName(name);
            page.setLastModifier(lastModifiedModifier);
            page.setLastModified(lastModifiedTime);
            page.setContent(content);
            this.logger.info("Loaded '" + id + "' page.");
            this.pages.put(id, page);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    this.logger.info("Loaded " + this.pages.size() + " page(s).");
    return true;
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Instant(java.time.Instant) IOException(java.io.IOException) UUID(java.util.UUID) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 15 with ConfigurationNode

use of ninja.leaping.configurate.ConfigurationNode in project Almura by AlmuraDev.

the class MultiTypeContentLoader method entry.

@Nullable
private Entry<T, C, B> entry(final String namespace, final T type, final Path path) {
    @Nullable final ConfigurationNode config = this.config(path);
    if (config != null) {
        final B builder = this.builder(type);
        final String id = this.configureBuilder(namespace, path, builder);
        return new Entry<>(id, type, builder, path, config);
    }
    return null;
}
Also used : ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) Nullable(javax.annotation.Nullable) Nullable(javax.annotation.Nullable)

Aggregations

ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)18 CommentedConfigurationNode (ninja.leaping.configurate.commented.CommentedConfigurationNode)5 IOException (java.io.IOException)4 Text (org.spongepowered.api.text.Text)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 GsonConfigurationLoader (ninja.leaping.configurate.gson.GsonConfigurationLoader)2 DoubleRange (com.almuradev.toolbox.util.math.DoubleRange)1 TEAccount (com.erigitic.config.TEAccount)1 TECurrency (com.erigitic.config.TECurrency)1 JsonParser (com.google.gson.JsonParser)1 BigDecimal (java.math.BigDecimal)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Instant (java.time.Instant)1 Map (java.util.Map)1 UUID (java.util.UUID)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 ItemEnchantment (org.spongepowered.api.data.meta.ItemEnchantment)1 Player (org.spongepowered.api.entity.living.player.Player)1