Advertisement
Guest User

Untitled

a guest
Dec 6th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. package dev.zach.zoraspixelmon;
  2.  
  3. import java.io.IOException;
  4. import java.util.UUID;
  5.  
  6. import org.spongepowered.api.entity.living.player.Player;
  7. import org.spongepowered.api.util.TypeTokens;
  8.  
  9. import com.google.common.reflect.TypeToken;
  10.  
  11. import dev.zach.levelsystem.LevelManager;
  12. import dev.zach.levelsystem.PlayerLevel;
  13. import ninja.leaping.configurate.ConfigurationNode;
  14. import ninja.leaping.configurate.SimpleConfigurationNode;
  15. import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
  16. import ninja.leaping.configurate.objectmapping.ObjectMapper;
  17. import ninja.leaping.configurate.objectmapping.ObjectMappingException;
  18. import ninja.leaping.configurate.objectmapping.Setting;
  19.  
  20. public class Config {
  21.  
  22. private ObjectMapper<Config>.BoundInstance configMapper;
  23. private HoconConfigurationLoader loader;
  24. private ConfigurationNode node;
  25.  
  26. public Config(HoconConfigurationLoader loader) {
  27. this.loader = loader;
  28. try {
  29. this.configMapper = ObjectMapper.forObject(this);
  30. } catch (ObjectMappingException e) {
  31. e.printStackTrace();
  32. }
  33.  
  34. this.load();
  35. }
  36.  
  37. public void save() {
  38. try {
  39. SimpleConfigurationNode out = SimpleConfigurationNode.root();
  40. this.configMapper.serialize(out);
  41. this.loader.save(out);
  42. } catch (ObjectMappingException | IOException e) {
  43. e.printStackTrace();
  44. }
  45. }
  46.  
  47. public void load() {
  48. try {
  49. this.configMapper.populate(this.loader.load());
  50. } catch (ObjectMappingException | IOException e) {
  51. e.printStackTrace();
  52. }
  53. }
  54.  
  55. public ConfigurationNode getNode() {
  56. return node;
  57. }
  58.  
  59. public void doConfig(Player player) {
  60.  
  61. UUID uuid = player.getUniqueId();
  62.  
  63. PlayerLevel playerLevel = LevelManager.playerLevelList.get(uuid);
  64. int level = playerLevel.getLevel();
  65. int xp = playerLevel.getExp();
  66.  
  67. try {
  68. ConfigurationNode node = loader.load();
  69. node.getNode("Players", "Level", uuid).setValue(TypeTokens.INTEGER_TOKEN, level);
  70. node.getNode("Players", "XP", uuid).setValue(TypeTokens.INTEGER_TOKEN, xp);
  71. loader.save(node);
  72. } catch (IOException | ObjectMappingException e) {
  73. e.printStackTrace();
  74. }
  75. }
  76.  
  77. public int readConfigLevel(Player player, ConfigurationNode value) {
  78.  
  79. UUID uuid = player.getUniqueId();
  80. int level = value.getNode("Players", "Level", uuid).getInt();
  81. return level;
  82.  
  83. }
  84.  
  85. public int readConfigExp(Player player, ConfigurationNode value) {
  86.  
  87. UUID uuid = player.getUniqueId();
  88. int xp = value.getNode("Players", "XP", uuid).getInt();
  89. return xp;
  90.  
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement