Guest User

Untitled

a guest
Dec 6th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public class Config {
  2.  
  3. private ObjectMapper<Config>.BoundInstance configMapper;
  4. private HoconConfigurationLoader loader;
  5. private ConfigurationNode node;
  6.  
  7. public Config(HoconConfigurationLoader loader) {
  8. this.loader = loader;
  9. try {
  10. this.configMapper = ObjectMapper.forObject(this);
  11. } catch (ObjectMappingException e) {
  12. e.printStackTrace();
  13. }
  14.  
  15. this.load();
  16. }
  17.  
  18. public void save() {
  19. try {
  20. SimpleConfigurationNode out = SimpleConfigurationNode.root();
  21. this.configMapper.serialize(out);
  22. this.loader.save(out);
  23. } catch (ObjectMappingException | IOException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27.  
  28. public void load() {
  29. try {
  30. this.configMapper.populate(this.loader.load());
  31. } catch (ObjectMappingException | IOException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35.  
  36. public ConfigurationNode getNode() {
  37. return node;
  38. }
  39.  
  40. public void doConfig(Player player) {
  41.  
  42. UUID uuid = player.getUniqueId();
  43. //String suuid = uuid.toString();
  44. PlayerLevel playerLevel = LevelManager.playerLevelList.get(uuid);
  45. int level = playerLevel.getLevel();
  46. int xp = playerLevel.getExp();
  47.  
  48. try {
  49. ConfigurationNode node = loader.load();
  50. node.getNode("Players", "Level", uuid).setValue(TypeTokens.INTEGER_TOKEN, level);
  51. node.getNode("Players", "XP", uuid).setValue(TypeTokens.INTEGER_TOKEN, xp);
  52. loader.save(node);
  53. } catch (IOException | ObjectMappingException e) {
  54. e.printStackTrace();
  55. }
  56. }
  57.  
  58. }
Add Comment
Please, Sign In to add comment