daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jun 5th, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.umdio.Dynapts;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.configuration.InvalidConfigurationException;
  12. import org.bukkit.configuration.file.FileConfiguration;
  13. import org.bukkit.configuration.file.YamlConfiguration;
  14. import org.bukkit.event.Listener;
  15. import org.bukkit.plugin.Plugin;
  16. import org.bukkit.plugin.java.JavaPlugin;
  17.  
  18. public class Main extends JavaPlugin { //Extending JavaPlugin so that Bukkit knows its the main class...
  19.      
  20.     private static Plugin plugin;
  21.  
  22.    
  23.     private File configf, specialf, signconff;
  24.     private FileConfiguration config, special, signconf;
  25.     private Connection connection;
  26.     private String host, database, username, password;
  27.     private int port;
  28.    
  29.    
  30.    
  31.     @Override
  32.     public void onEnable() {
  33.         plugin = this;
  34.         registerEvents(this, new SignController());
  35.         //This is where we register our events/commands
  36.         createFiles();
  37.        
  38.         //MySQL credentials
  39.         host = "gcav.eu";
  40.         port = 3306;
  41.         database = "Dynapts";
  42.         username = "ben";
  43.         password = "GravabitVosmet33";
  44.        
  45.         connectMySQL();
  46.     }
  47.    
  48.    
  49.     public void onDisable() {
  50.         plugin = null;
  51.         //To stop memory leaks
  52.     }
  53.    
  54.     // ADD MORE OF THESE FOR MORE CONFIGS
  55.    
  56.     public FileConfiguration getSpecialConfig() {
  57.         return this.special;
  58.     }
  59.     public FileConfiguration getSignConfig() {
  60.         return this.signconf;
  61.     }
  62.     public File getSignConfigF() {
  63.         return this.signconff;
  64.     }
  65.    
  66.     private void createFiles() {
  67.  
  68.         configf = new File(getDataFolder(), "config.yml");
  69.         specialf = new File(getDataFolder(), "special.yml");
  70.         signconff = new File(getDataFolder(), "signconf.yml");
  71.  
  72.         if (!configf.exists()) {
  73.             configf.getParentFile().mkdirs();
  74.             saveResource("config.yml", false);
  75.         }
  76.         if (!specialf.exists()) {
  77.             specialf.getParentFile().mkdirs();
  78.             saveResource("special.yml", false);
  79.         }
  80.         if (!signconff.exists()) {
  81.             signconff.getParentFile().mkdirs();
  82.             saveResource("signconf.yml", false);
  83.         }
  84.         config = new YamlConfiguration();
  85.         special = new YamlConfiguration();
  86.         signconf = new YamlConfiguration();
  87.         try {
  88.             config.load(configf);
  89.             special.load(specialf);
  90.             signconf.load(signconff);
  91.         } catch (IOException | InvalidConfigurationException e) {
  92.             e.printStackTrace();
  93.         }
  94.     }
  95.     //Much easier then registering events in 10 different methods
  96.     public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
  97.         for (Listener listener : listeners) {
  98.             Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
  99.         }
  100.     }
  101.  
  102.     //To access the plugin variable from other classes
  103.     public static Plugin getPlugin() {
  104.         return plugin;
  105.     }
  106.    
  107.     public void openConnection() throws SQLException, ClassNotFoundException {
  108.         if (connection != null && !connection.isClosed()) {
  109.             return;
  110.         }
  111.      
  112.         synchronized (this) {
  113.             if (connection != null && !connection.isClosed()) {
  114.                 return;
  115.             }
  116.             Class.forName("com.mysql.jdbc.Driver");
  117.             connection = DriverManager.getConnection("jdbc:mysql://" + this.host+ ":" + this.port + "/" + this.database, this.username, this.password);
  118.         }
  119.     }
  120.    
  121.     public void connectMySQL() {
  122.         try {    
  123.             openConnection();
  124.             Statement statement = connection.createStatement();  
  125.            
  126.         } catch (ClassNotFoundException e) {
  127.             e.printStackTrace();
  128.         } catch (SQLException e) {
  129.             e.printStackTrace();
  130.         }
  131.         statement // <----- statement cannot be resolved
  132.     }
  133.  
  134.  
  135. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top