Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dev.zach.zoraspixelmon;
- import java.io.IOException;
- import java.util.UUID;
- import org.spongepowered.api.entity.living.player.Player;
- import org.spongepowered.api.util.TypeTokens;
- import com.google.common.reflect.TypeToken;
- import dev.zach.levelsystem.LevelManager;
- import dev.zach.levelsystem.PlayerLevel;
- import ninja.leaping.configurate.ConfigurationNode;
- import ninja.leaping.configurate.SimpleConfigurationNode;
- import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
- import ninja.leaping.configurate.objectmapping.ObjectMapper;
- import ninja.leaping.configurate.objectmapping.ObjectMappingException;
- import ninja.leaping.configurate.objectmapping.Setting;
- public class Config {
- private ObjectMapper<Config>.BoundInstance configMapper;
- private HoconConfigurationLoader loader;
- private ConfigurationNode node;
- public Config(HoconConfigurationLoader loader) {
- this.loader = loader;
- try {
- this.configMapper = ObjectMapper.forObject(this);
- } catch (ObjectMappingException e) {
- e.printStackTrace();
- }
- this.load();
- }
- public void save() {
- try {
- SimpleConfigurationNode out = SimpleConfigurationNode.root();
- this.configMapper.serialize(out);
- this.loader.save(out);
- } catch (ObjectMappingException | IOException e) {
- e.printStackTrace();
- }
- }
- public void load() {
- try {
- this.configMapper.populate(this.loader.load());
- } catch (ObjectMappingException | IOException e) {
- e.printStackTrace();
- }
- }
- public ConfigurationNode getNode() {
- return node;
- }
- public void doConfig(Player player) {
- UUID uuid = player.getUniqueId();
- PlayerLevel playerLevel = LevelManager.playerLevelList.get(uuid);
- int level = playerLevel.getLevel();
- int xp = playerLevel.getExp();
- try {
- ConfigurationNode node = loader.load();
- node.getNode("Players", "Level", uuid).setValue(TypeTokens.INTEGER_TOKEN, level);
- node.getNode("Players", "XP", uuid).setValue(TypeTokens.INTEGER_TOKEN, xp);
- loader.save(node);
- } catch (IOException | ObjectMappingException e) {
- e.printStackTrace();
- }
- }
- public int readConfigLevel(Player player, ConfigurationNode value) {
- UUID uuid = player.getUniqueId();
- int level = value.getNode("Players", "Level", uuid).getInt();
- return level;
- }
- public int readConfigExp(Player player, ConfigurationNode value) {
- UUID uuid = player.getUniqueId();
- int xp = value.getNode("Players", "XP", uuid).getInt();
- return xp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement