Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.creepercow.DBTL.account;
- import me.creepercow.DBTL.Main;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.plugin.Plugin;
- import java.io.File;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Utils {
- private static Plugin plugin = new Main();
- @SuppressWarnings("unused")
- static File dataFile;
- static FileConfiguration data;
- public static void Setup() {
- Logger logger = Logger.getLogger("Minecraft");
- String url = "jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "Data";
- String table_account = "CREATE TABLE IF NOT EXISTS accounts (\n"
- + " id interger PRIMARY KEY,\n"
- + " name text NOT NULL INDEX, \n"
- + " blood interger DEFAULT 0, \n"
- + " shards interger DEFAULT 0, \n"
- + " rank text NOT NULL, \n"
- + " passes interger, \n"
- + " );";
- String table_server = "CREATE TABLE IF NOT EXISTS server (\n"
- + " Shrine1 text, \n"
- + " Shrine2 text, \n"
- + " Shrine3 text, \n"
- + " Shrine4 text, \n"
- + " DoubleXP boolean, \n"
- + " DoubleBlood boolean, \n"
- //+ " "
- + " );";
- try (Connection conn = DriverManager.getConnection(url)) {
- if (conn != null) {
- DatabaseMetaData meta = conn.getMetaData();
- logger.info("Database created");
- Statement stmt = conn.createStatement();
- stmt.execute(table_account);
- stmt.execute(table_server);
- }
- } catch (SQLException e) {
- logger.log(Level.SEVERE, e.getMessage());
- }
- }
- public static Connection Connect() {
- Logger logger = Logger.getLogger("Minecraft");
- String url = "jdbc:sqlite:" + plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "Data";
- try (Connection conn = DriverManager.getConnection(url)) {
- return conn;
- } catch (SQLException e) {
- logger.log(Level.SEVERE, e.getMessage());
- }
- return null;
- }
- public void CreatePlayer(String name) throws SQLException {
- String sql = "INSERT INTO accounts(name,rank) VALUES(" + name + ",DEFAULT)";
- Connection conn = Connect();
- Statement stmt = conn.createStatement();
- stmt.executeQuery(sql);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement