Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.umdio.Dynapts;
- import java.io.File;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.Bukkit;
- import org.bukkit.configuration.InvalidConfigurationException;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.event.Listener;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin { //Extending JavaPlugin so that Bukkit knows its the main class...
- private static Plugin plugin;
- private File configf, specialf, signconff;
- private FileConfiguration config, special, signconf;
- private Connection connection;
- private String host, database, username, password;
- private int port;
- @Override
- public void onEnable() {
- plugin = this;
- registerEvents(this, new SignController());
- //This is where we register our events/commands
- createFiles();
- //MySQL credentials
- host = "gcav.eu";
- port = 3306;
- database = "Dynapts";
- username = "ben";
- password = "GravabitVosmet33";
- connectMySQL();
- }
- public void onDisable() {
- plugin = null;
- //To stop memory leaks
- }
- // ADD MORE OF THESE FOR MORE CONFIGS
- public FileConfiguration getSpecialConfig() {
- return this.special;
- }
- public FileConfiguration getSignConfig() {
- return this.signconf;
- }
- public File getSignConfigF() {
- return this.signconff;
- }
- private void createFiles() {
- configf = new File(getDataFolder(), "config.yml");
- specialf = new File(getDataFolder(), "special.yml");
- signconff = new File(getDataFolder(), "signconf.yml");
- if (!configf.exists()) {
- configf.getParentFile().mkdirs();
- saveResource("config.yml", false);
- }
- if (!specialf.exists()) {
- specialf.getParentFile().mkdirs();
- saveResource("special.yml", false);
- }
- if (!signconff.exists()) {
- signconff.getParentFile().mkdirs();
- saveResource("signconf.yml", false);
- }
- config = new YamlConfiguration();
- special = new YamlConfiguration();
- signconf = new YamlConfiguration();
- try {
- config.load(configf);
- special.load(specialf);
- signconf.load(signconff);
- } catch (IOException | InvalidConfigurationException e) {
- e.printStackTrace();
- }
- }
- //Much easier then registering events in 10 different methods
- public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
- for (Listener listener : listeners) {
- Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
- }
- }
- //To access the plugin variable from other classes
- public static Plugin getPlugin() {
- return plugin;
- }
- public void openConnection() throws SQLException, ClassNotFoundException {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- synchronized (this) {
- if (connection != null && !connection.isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://" + this.host+ ":" + this.port + "/" + this.database, this.username, this.password);
- }
- }
- public void connectMySQL() {
- try {
- openConnection();
- Statement statement = connection.createStatement();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- statement // <----- statement cannot be resolved
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement