Advertisement
Guest User

understand this olllez

a guest
Sep 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. package io.github.thediamondpicks.bans;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.event.Listener;
  5. import org.bukkit.plugin.Plugin;
  6. import org.bukkit.plugin.java.JavaPlugin;
  7. import org.bukkit.scheduler.BukkitRunnable;
  8.  
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13.  
  14. /**
  15.  * Created by TheDiamondPicks on 28/09/2016.
  16.  */
  17. public class Main extends JavaPlugin {
  18.     private Connection connection;
  19.     private String host, database, username, password;
  20.     private int port;
  21.     private static Plugin plugin;
  22.     @Override
  23.     public void onEnable() {
  24.         getCommand("ban").setExecutor(new BanCommand());
  25.         plugin = this;
  26.         host = "jerryandjamy.com";
  27.         port = 3306;
  28.         database = "Bans";
  29.         username = "nanana";
  30.         password = "youthoughtwouldgetthepass";
  31.         try {
  32.             openConnection();
  33.             Statement statement = connection.createStatement();
  34.         } catch (ClassNotFoundException e) {
  35.             e.printStackTrace();
  36.         } catch (SQLException e) {
  37.             e.printStackTrace();
  38.         }
  39.     }
  40.  
  41.     @Override
  42.     public void onDisable() {
  43.         plugin = null; // Prevents mem leaks
  44.     }
  45.     //Much eaisier then registering events in 10 diffirent methods
  46.     public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
  47.         for (Listener listener : listeners) {
  48.             Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
  49.         }
  50.     }
  51.  
  52.     //To access the plugin variable from other classes
  53.     public static Plugin getPlugin() {
  54.         return plugin;
  55.     }
  56.  
  57.     public void openConnection() throws SQLException, ClassNotFoundException {
  58.         if (connection != null && !connection.isClosed()) {
  59.             return;
  60.         }
  61.  
  62.         synchronized (this) {
  63.             if (connection != null && !connection.isClosed()) {
  64.                 return;
  65.             }
  66.             Class.forName("com.mysql.jdbc.Driver");
  67.             connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
  68.         }
  69.     }
  70.     BukkitRunnable r = new BukkitRunnable() {
  71.         public void run() {
  72.             try {
  73.                 openConnection();
  74.                 Statement statement = connection.createStatement();
  75.             } catch(ClassNotFoundException e) {
  76.                 e.printStackTrace();
  77.             } catch(SQLException e) {
  78.                 e.printStackTrace();
  79.             }
  80.         }
  81.     };
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement