Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* */ package de.mevax.mineshine;
- /* */
- /* */ import java.io.File;
- /* */ import java.io.IOException;
- /* */ import java.io.PrintStream;
- /* */ import java.sql.Connection;
- /* */ import java.sql.DriverManager;
- /* */ import java.sql.ResultSet;
- /* */ import java.sql.SQLException;
- /* */ import java.sql.Statement;
- /* */ import org.bukkit.configuration.file.FileConfiguration;
- /* */ import org.bukkit.configuration.file.FileConfigurationOptions;
- /* */
- /* */ public class MySQL
- /* */ {
- /* */ public static String username;
- /* */ public static String password;
- /* */ public static String host;
- /* */ public static int port;
- /* */ public static String database;
- /* */ public static Connection con;
- /* */
- /* */ public static void loadsql()
- /* */ {
- /* 25 */ File file = new File("plugins/MineShine", "MySQL.yml");
- /* 26 */ FileConfiguration cfg = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(file);
- /* */
- /* 28 */ String m = "MySQL.";
- /* 29 */ cfg.addDefault(m + "host", "hostname");
- /* 30 */ cfg.addDefault(m + "port", Integer.valueOf(3306));
- /* 31 */ cfg.addDefault(m + "database", "database");
- /* 32 */ cfg.addDefault(m + "username", "username");
- /* 33 */ cfg.addDefault(m + "password", "password");
- /* 34 */ cfg.options().copyDefaults(true);
- /* */ try
- /* */ {
- /* 37 */ cfg.save(file);
- /* */ }
- /* */ catch (IOException e)
- /* */ {
- /* 41 */ e.printStackTrace();
- /* */ }
- /* 43 */ host = cfg.getString(m + "host");
- /* 44 */ port = cfg.getInt(m + "port");
- /* 45 */ database = cfg.getString(m + "database");
- /* 46 */ username = cfg.getString(m + "username");
- /* 47 */ password = cfg.getString(m + "password");
- /* */ }
- /* */
- /* */ public static void connect()
- /* */ {
- /* 52 */ if (!isConnected()) {
- /* */ try
- /* */ {
- /* 55 */ con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true", username, password);
- /* */ }
- /* */ catch (SQLException e)
- /* */ {
- /* 59 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */ }
- /* */
- /* */ public static void close()
- /* */ {
- /* 66 */ if (isConnected()) {
- /* */ try
- /* */ {
- /* 69 */ con.close();
- /* */ }
- /* */ catch (SQLException e)
- /* */ {
- /* 73 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */ }
- /* */
- /* */ public static boolean contains(String name)
- /* */ {
- /* 80 */ boolean value = false;
- /* */ try
- /* */ {
- /* 83 */ String query = "SELECT * FROM `stats` WHERE `name` = '" + name + "'";
- /* 84 */ ResultSet rs = Query(query);
- /* 85 */ if (rs.next()) {
- /* 86 */ value = true;
- /* */ } else {
- /* 88 */ value = false;
- /* */ }
- /* */ }
- /* */ catch (Exception e)
- /* */ {
- /* 93 */ value = false;
- /* 94 */ e.printStackTrace();
- /* */ }
- /* 96 */ return value;
- /* */ }
- /* */
- /* */ public static ResultSet Query(String query)
- /* */ {
- /* 101 */ ResultSet rs = null;
- /* */ try
- /* */ {
- /* 104 */ Statement stmt = con.createStatement();
- /* 105 */ stmt.executeQuery(query);
- /* 106 */ return stmt.getResultSet();
- /* */ }
- /* */ catch (Exception e)
- /* */ {
- /* 110 */ System.err.println(e);
- /* */ }
- /* 112 */ return rs;
- /* */ }
- /* */
- /* */ public static int getPoints(String name)
- /* */ {
- /* 117 */ int points = 0;
- /* */ try
- /* */ {
- /* 120 */ ResultSet rs = Query("SELECT `points` FROM `eps_user` WHERE `name`= '" + name + "'");
- /* 121 */ if (rs.next()) {
- /* 122 */ points = rs.getInt(1);
- /* */ }
- /* 124 */ rs.close();
- /* */ }
- /* */ catch (Exception ex)
- /* */ {
- /* 128 */ ex.printStackTrace();
- /* */ }
- /* 130 */ return points;
- /* */ }
- /* */
- /* */ public static void addPoints(String name, int amount)
- /* */ {
- /* 135 */ if (!contains(name)) {
- /* 136 */ update("INSERT INTO `eps_user` (`name`, `points`) VALUES ('" + name + "', '" + (getPoints(name) + amount) + "')");
- /* */ } else {
- /* 138 */ update("UPDATE `eps_user` SET `points` = '" + (getPoints(name) + amount) + "' WHERE `name` = '" + name + "'; ");
- /* */ }
- /* */ }
- /* */
- /* */ public static boolean isConnected()
- /* */ {
- /* 144 */ return con != null;
- /* */ }
- /* */
- /* */ public static void createTabel()
- /* */ {
- /* 149 */ if (isConnected()) {
- /* */ try
- /* */ {
- /* 152 */ con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS stats (Name VARCHAR(32), UUID VARCHAR(100), Kills int, Deaths int, Points int, Wins int)");
- /* 153 */ con.createStatement().executeUpdate("CREATE TABLE IF NOT EXISTS money (Name VARCHAR(32), UUID VARCHAR(100), Money int)");
- /* */ }
- /* */ catch (SQLException e)
- /* */ {
- /* 157 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */ }
- /* */
- /* */ public static void update(String qry)
- /* */ {
- /* 164 */ if (isConnected()) {
- /* */ try
- /* */ {
- /* 167 */ con.createStatement().executeUpdate(qry);
- /* */ }
- /* */ catch (SQLException e)
- /* */ {
- /* 171 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */ }
- /* */
- /* */ public static ResultSet getResult(String qry)
- /* */ {
- /* 178 */ if (isConnected()) {
- /* */ try
- /* */ {
- /* 181 */ return con.createStatement().executeQuery(qry);
- /* */ }
- /* */ catch (SQLException e)
- /* */ {
- /* 185 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* 188 */ return null;
- /* */ }
- /* */ }
- /* Location: C:\Users\tatjana\Desktop\MineShine.jar!\de\mevax\mineshine\MySQL.class
- * Java compiler version: 7 (51.0)
- * JD-Core Version: 0.7.1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement