Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package ru.dreadfaly.reputation;
  2.  
  3. import org.bukkit.configuration.file.FileConfiguration;
  4. import org.bukkit.configuration.file.YamlConfiguration;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import java.util.Set;
  8.  
  9. class Manager
  10. {
  11.     private String            path;
  12.     private FileConfiguration configuration;
  13.     private File              file;
  14.  
  15.     Manager(String path) {
  16.         this.path = path;
  17.         init();
  18.     }
  19.  
  20.     private void init() {
  21.         String root = "plugins/Reputation";
  22.         file = new File(root, path);
  23.  
  24.         if (!file.exists()) {
  25.             if (file.getParentFile().mkdirs()) {
  26.                 try {
  27.                     if (file.createNewFile()) {
  28.                         configuration = YamlConfiguration.loadConfiguration(file);
  29.                     }
  30.                 } catch (IOException e) {
  31.                     e.printStackTrace();
  32.                 }
  33.             }
  34.         }
  35.         configuration = YamlConfiguration.loadConfiguration(file);
  36.     }
  37.  
  38.     boolean write(String path, Object value) {
  39.         boolean state = false;
  40.         configuration.set(path, value);
  41.         try {
  42.             configuration.save(file);
  43.             state = true;
  44.         } catch (IOException e) {
  45.             e.printStackTrace();
  46.         }
  47.         return state;
  48.     }
  49.  
  50.     Object read(String path) {
  51.         return configuration.get(path);
  52.     }
  53.  
  54.     Set<String> getKeys(String path) {
  55.         if (configuration.getConfigurationSection(path) == null) return null;
  56.         return configuration.getConfigurationSection(path).getKeys(false);
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement