Guest User

Untitled

a guest
Apr 21st, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. package me.Michielo.UltimateStats;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.nio.file.Files;
  7.  
  8. import net.md_5.bungee.api.plugin.Plugin;
  9. import net.md_5.bungee.config.Configuration;
  10. import net.md_5.bungee.config.ConfigurationProvider;
  11. import net.md_5.bungee.config.YamlConfiguration;
  12.  
  13. public class BungeeMain extends Plugin {
  14.  
  15.     @Override
  16.     public void onEnable() {
  17.         getLogger().info("\n \n---=== UltimateStats ===--- \n - Started \n---=== UltimateStats ===--- \n \n");
  18.         // config
  19.         saveDefaultConfig();
  20.     }
  21.    
  22.     @Override
  23.     public void onDisable() {
  24.         getLogger().info("\n \n---=== UltimateStats ===--- \n - Closed \n---=== UltimateStats ===--- \n \n");
  25.     }
  26.    
  27.     public Configuration getConfig() {
  28.         try {
  29.             Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
  30.             return configuration;
  31.         } catch (IOException e) {
  32.             e.printStackTrace();
  33.         }
  34.         return null;
  35.     }
  36.    
  37.     public void saveConfig() {
  38.         try {
  39.             ConfigurationProvider.getProvider(YamlConfiguration.class).save(getConfig(), new File(getDataFolder(), "config.yml"));
  40.         } catch (IOException e) {
  41.             e.printStackTrace();
  42.         }
  43.     }
  44.    
  45.     private void saveDefaultConfig() {
  46.         if (!getDataFolder().exists())
  47.             getDataFolder().mkdir();
  48.         File file = new File(getDataFolder(), "config.yml");
  49.         if (!file.exists()) {
  50.             try (InputStream in = getResourceAsStream("config.yml")) {
  51.                 Files.copy(in, file.toPath());
  52.             } catch (IOException e) {
  53.                 e.printStackTrace();
  54.             }
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment