Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 1: */ package io.aura.main;
- /* 2: */
- /* 3: */ import java.io.File;
- /* 4: */ import java.io.IOException;
- /* 6: */ import java.sql.Connection;
- /* 7: */ import java.sql.DriverManager;
- /* 8: */ import java.sql.ResultSet;
- /* 9: */ import java.sql.SQLException;
- /* 10: */ import java.sql.Statement;
- /* 11: */ import org.bukkit.Bukkit;
- /* 13: */ import org.bukkit.configuration.file.FileConfiguration;
- /* 15: */ import org.bukkit.configuration.file.YamlConfiguration;
- /* 16: */
- /* 17: */ public class MySQL
- /* 18: */ {
- /* 19: */ public static String username;
- /* 20: */ public static String password;
- /* 21: */ public static String database;
- /* 22: */ public static String host;
- /* 23: */ public static String port;
- /* 24: */ public static Connection con;
- /* 25: */
- /* 26: */ public MySQL(String user, String pass, String host2, String dB) {}
- /* 27: */
- /* 28: */ public static void connect()
- /* 29: */ {
- /* 30: 27 */ if (!isConnected()) {
- /* 31: */ try
- /* 32: */ {
- /* 33: 30 */ con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + username + "&password=" + password + "&autoReconnect=true");
- /* 34: 31 */ Bukkit.getConsoleSender().sendMessage("§aMySQL MySQL connected");
- /* 35: */ }
- /* 36: */ catch (SQLException e)
- /* 37: */ {
- /* 38: 35 */ e.printStackTrace();
- /* 39: */ }
- /* 40: */ }
- /* 41: */ }
- /* 42: */
- /* 43: */ public static void close()
- /* 44: */ {
- /* 45: 42 */ if (isConnected()) {
- /* 46: */ try
- /* 47: */ {
- /* 48: 45 */ con.close();
- /* 49: 46 */ Bukkit.getConsoleSender().sendMessage("§aMySQL MySQL disconnected");
- /* 50: */ }
- /* 51: */ catch (SQLException e)
- /* 52: */ {
- /* 53: 50 */ e.printStackTrace();
- /* 54: */ }
- /* 55: */ }
- /* 56: */ }
- /* 57: */
- /* 58: */ public static boolean isConnected()
- /* 59: */ {
- /* 60: 57 */ return con != null;
- /* 61: */ }
- /* 62: */
- /* 63: */ public static void createTable()
- /* 64: */ {
- /* 65: 62 */ if (isConnected()) {
- /* 66: */ try
- /* 67: */ {
- /* 68: 66 */ con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS Aura (UUID VARCHAR(100), NAME VARCHAR(100), KILLS int, DEATHS int , WIN int , LOSE int , COINS int)");
- /* 69: 67 */ Bukkit.getConsoleSender().sendMessage("§4MySQL MySQL Table created");
- /* 70: */ }
- /* 71: */ catch (SQLException e)
- /* 72: */ {
- /* 73: 71 */ e.printStackTrace();
- /* 74: */ }
- /* 75: */ }
- /* 76: */ }
- /* 77: */
- /* 78: */ public static void update(String qry)
- /* 79: */ {
- /* 80: 78 */ if (isConnected()) {
- /* 81: */ try
- /* 82: */ {
- /* 83: 81 */ con.createStatement().executeUpdate(qry);
- /* 84: */ }
- /* 85: */ catch (SQLException e)
- /* 86: */ {
- /* 87: 85 */ e.printStackTrace();
- /* 88: */ }
- /* 89: */ }
- /* 90: */ }
- /* 91: */
- /* 92: */ public static ResultSet getResult(String qry)
- /* 93: */ {
- /* 94: 92 */ ResultSet rs = null;
- /* 95: */ try
- /* 96: */ {
- /* 97: 95 */ Statement st = con.createStatement();
- /* 98: 96 */ rs = st.executeQuery(qry);
- /* 99: */ }
- /* 100: */ catch (SQLException e)
- /* 101: */ {
- /* 102:100 */ connect();
- /* 103:101 */ System.err.println(e);
- /* 104: */ }
- /* 105:103 */ return rs;
- /* 106: */ }
- /* 107: */
- /* 108: */ public static File getMySQLFile()
- /* 109: */ {
- /* 110:108 */ return new File("plugins/Aura_Ceriox", "MySQL.yml");
- /* 111: */ }
- /* 112: */
- /* 113: */ public static FileConfiguration getMySQLFileConfiguration()
- /* 114: */ {
- /* 115:113 */ return YamlConfiguration.loadConfiguration(getMySQLFile());
- /* 116: */ }
- /* 117: */
- /* 118: */ public static void setStandardMySQL()
- /* 119: */ {
- /* 120:118 */ FileConfiguration cfg = getMySQLFileConfiguration();
- /* 121: */
- /* 122:120 */ cfg.options().copyDefaults(true);
- /* 123:121 */ cfg.addDefault("username", "root");
- /* 124:122 */ cfg.addDefault("password", "password");
- /* 125:123 */ cfg.addDefault("database", "localhost");
- /* 126:124 */ cfg.addDefault("host", "localhost");
- /* 127:125 */ cfg.addDefault("port", "3306");
- /* 128: */ try
- /* 129: */ {
- /* 130:128 */ cfg.save(getMySQLFile());
- /* 131: */ }
- /* 132: */ catch (IOException e)
- /* 133: */ {
- /* 134:132 */ e.printStackTrace();
- /* 135: */ }
- /* 136: */ }
- /* 137: */
- /* 138: */ public static void readMySQL()
- /* 139: */ {
- /* 140:138 */ FileConfiguration cfg = getMySQLFileConfiguration();
- /* 141:139 */ username = cfg.getString("username");
- /* 142:140 */ password = cfg.getString("password");
- /* 143:141 */ database = cfg.getString("database");
- /* 144:142 */ host = cfg.getString("host");
- /* 145:143 */ port = cfg.getString("port");
- /* 146: */ }
- /* 147: */ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement