Advertisement
Guest User

Boilerplate Code

a guest
Jan 24th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. public class DatabaseConfig {
  2.     private Plugin plugin;
  3.     private FileConfiguration config;
  4.     private CommandSender sender;
  5.  
  6.     // Fields to retrieve
  7.     private String host;
  8.     private int port;
  9.     private String db;
  10.     private boolean auth;
  11.     private String user;
  12.     private char[] pass;
  13.  
  14.     public DatabaseConfig(Plugin plugin) {
  15.         this.plugin = plugin;
  16.         config = plugin.getConfig();
  17.         sender = plugin.getServer().getConsoleSender();
  18.  
  19.         loadConfig();
  20.     }
  21.  
  22.     public void loadConfig() {
  23.         File configFile = new File(plugin.getDataFolder(), "config.yml");
  24.  
  25.         if(!configFile.exists()) {
  26.             sender.sendMessage("config.yml file not found, using default values");
  27.             sender.sendMessage("Generating default config.yml file.");
  28.             plugin.saveDefaultConfig();
  29.         }
  30.  
  31.         host = config.getString("host", "127.0.0.1");
  32.         port = config.getInt("port", 27017);
  33.         db = config.getString("db", "mydb");
  34.         auth = config.getBoolean("auth", false);
  35.         user = config.getString("user", "user");
  36.         pass = config.getString("pass", "pass").toCharArray();
  37.     }
  38.  
  39.     public String getHost() {
  40.         return host;
  41.     }
  42.  
  43.     public int getPort() {
  44.         return port;
  45.     }
  46.  
  47.     public String getDb() {
  48.         return db;
  49.     }
  50.  
  51.     public boolean hasAuth() {
  52.         return auth;
  53.     }
  54.  
  55.     public String getUser() {
  56.         return user;
  57.     }
  58.  
  59.     public char[] getPass() {
  60.         return pass;
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement