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]);
}
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations