Advertisement
Exception_Prototype

Untitled

Oct 27th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1.     void loadConfig(ConfigurationLoader<CommentedConfigurationNode> localLoader) {
  2.         try {
  3.             TypeSerializerCollection serializers = TypeSerializers.getDefaultSerializers().newChild();
  4.             serializers.registerType(TypeToken.of(Message.class), new MessageSerializer());
  5.             ConfigurationOptions options = ConfigurationOptions.defaults().setSerializers(serializers);
  6.             this.node = localLoader.load(options);
  7.             List<Message> list = this.node.getList(TypeToken.of(Message.class));
  8.             if (list != null) {
  9.                 this.messages.addAll(list);
  10.             }
  11.         } catch (IOException | ObjectMappingException e) {
  12.             this.logger.warn("Error load from default config!", e);
  13.         }
  14.     }
  15.  
  16.     void saveConfig(ConfigurationLoader<CommentedConfigurationNode> localLoader) {
  17.         List<Message> list = new ArrayList<>(this.messages);
  18.         try {
  19.             this.node.setComment("");
  20.             this.node.getNode("messages").setValue(new TypeToken<List<Message>>() {}, list);
  21.             localLoader.save(this.node);
  22.         } catch (ObjectMappingException | IOException e) {
  23.             this.logger.warn("Error saving to default config!", e);
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement