Add creating database
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -36,6 +36,7 @@ buildNumber.properties
|
|||||||
.mvn/timing.properties
|
.mvn/timing.properties
|
||||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||||
.mvn/wrapper/maven-wrapper.jar
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
ic_plugin/settings.xml
|
||||||
|
|
||||||
# Eclipse m2e generated files
|
# Eclipse m2e generated files
|
||||||
# Eclipse Core
|
# Eclipse Core
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
"files.encoding": "utf8",
|
"files.encoding": "utf8",
|
||||||
"java.home": "/usr/lib/jvm/jdk-25",
|
"java.home": "/usr/lib/jvm/jdk-25",
|
||||||
"java.jdt.ls.vmargs": "-Dfile.encoding=UTF-8",
|
"java.jdt.ls.vmargs": "-Dfile.encoding=UTF-8",
|
||||||
"javac-linter.javac": "javac -Dfile.encoding=UTF-8"
|
"javac-linter.javac": "javac -Dfile.encoding=UTF-8",
|
||||||
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
|
"java.format.settings.url": "eclipse-formatter.xml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,6 +57,11 @@
|
|||||||
<version>1.21.8-R0.1-SNAPSHOT</version>
|
<version>1.21.8-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.xerial</groupId>
|
||||||
|
<artifactId>sqlite-jdbc</artifactId>
|
||||||
|
<version>3.50.3.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -92,6 +97,12 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>3.4.2</version>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<db.username>${db.username}</db.username>
|
||||||
|
<db.password>${db.password}</db.password>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
|||||||
@@ -1,14 +1,27 @@
|
|||||||
package nl.interestingcorner;
|
package nl.interestingcorner;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import nl.interestingcorner.db.DatabaseManager;
|
||||||
|
|
||||||
public class App extends JavaPlugin {
|
public class App extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getLogger().info("Hello, SpigotMC!");
|
getLogger().info("Eyooo we boutta get lit!");
|
||||||
|
|
||||||
|
// saveDefaultConfig(); // create config.yml if not exists
|
||||||
|
if (!DatabaseManager.INSTANCE.initialize(this))
|
||||||
|
{
|
||||||
|
getLogger().severe("Could not initialize database. Exiting!");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getLogger().info("See you again, SpigotMC!");
|
getLogger().info("Eyooo we outta here!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package nl.interestingcorner.db;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public enum DatabaseManager {
|
||||||
|
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
private Connection connection;
|
||||||
|
private JavaPlugin app;
|
||||||
|
|
||||||
|
public boolean initialize(JavaPlugin app) {
|
||||||
|
this.app = app;
|
||||||
|
|
||||||
|
if (!app.getDataFolder().exists()) {
|
||||||
|
if (!app.getDataFolder().mkdirs()) {
|
||||||
|
app.getLogger().severe("Could not create data folder");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File dbFile = new File(app.getDataFolder(), "database.db");
|
||||||
|
String url = "jdbc:sqlite:" + dbFile.getAbsolutePath();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.connection = DriverManager.getConnection(url);
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
app.getLogger().log(Level.SEVERE, "Could not connect to database file {0}: {1}",
|
||||||
|
new Object[] { dbFile, e.getMessage() });
|
||||||
|
}
|
||||||
|
|
||||||
|
app.getLogger().log(Level.INFO, "Connected to SQLite database: {0}", dbFile.getName());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user