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