Skip to content

Commit

Permalink
Merge pull request #4 from Baktus79/dev-1x
Browse files Browse the repository at this point in the history
SQL håndtering
  • Loading branch information
Baktus79 authored Nov 11, 2021
2 parents e59971e + 2323b44 commit 5b8aa5b
Show file tree
Hide file tree
Showing 17 changed files with 484 additions and 291 deletions.
12 changes: 6 additions & 6 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/lars/eclipse-workspace/API/CMI8.8.1.2.jar"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/lars/eclipse-workspace/API/CMI8.8.1.2.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
43 changes: 18 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>no.vestlandetmc</groupId>
<artifactId>FellesVarsling</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<packaging>jar</packaging>

<name>fv</name>
Expand All @@ -30,10 +30,6 @@
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>minecraft-repo</id>
<url>https://libraries.minecraft.net/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -66,19 +62,18 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>3.1.36</version>
<scope>provided</scope>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.7.4</version>
</dependency>

</dependencies>

Expand All @@ -92,20 +87,18 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<archive>
<manifestEntries>
<Built-By>Baktus_79</Built-By>
</manifestEntries>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>FellesVarsling/libs/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
Expand Down
43 changes: 41 additions & 2 deletions src/main/java/no/vestlandetmc/fv/bukkit/FVBukkit.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package no.vestlandetmc.fv.bukkit;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;

import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -11,6 +13,7 @@
import no.vestlandetmc.fv.bukkit.listeners.CMIListener;
import no.vestlandetmc.fv.bukkit.listeners.LitebansAPI;
import no.vestlandetmc.fv.bukkit.listeners.PlayerListener;
import no.vestlandetmc.fv.bukkit.util.DownloadLibs;

public class FVBukkit extends JavaPlugin {

Expand All @@ -24,15 +27,16 @@ public static FVBukkit getInstance() {
public void onEnable() {
instance = this;

try { downloadLibs(); } catch (final IOException e) { e.printStackTrace(); }

this.getCommand("fellesvarsling").setExecutor(new FellesVarsling());
this.getCommand("fellesvarsling").setTabCompleter(new FellesVarsling());
Config.initialize();

MessageHandler.sendConsole("[" + getDescription().getPrefix() + "] Kontakter databasen...");
new MySqlPool().initialize();

try {
MySqlPool.getConnection();
new MySqlPool().initialize();
MessageHandler.sendConsole("[" + getDescription().getPrefix() + "] Kontakt med database er oppnådd");
this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
MySQLHandler.sqlEnabled = true;
Expand All @@ -56,4 +60,39 @@ public void onEnable() {
}

}

private void downloadLibs() throws IOException {
final HashMap<String, String> libs = new HashMap<>();

libs.put("mariadb-java-client-2.7.4.jar", "https://repo1.maven.org/maven2/org/mariadb/jdbc/mariadb-java-client/2.7.4/mariadb-java-client-2.7.4.jar");
libs.put("mysql-connector-java-8.0.27.jar", "https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar");
libs.put("HikariCP-5.0.0.jar", "https://repo1.maven.org/maven2/com/zaxxer/HikariCP/5.0.0/HikariCP-5.0.0.jar");

for(final String filename : libs.keySet()) {
final DownloadLibs dl = new DownloadLibs(filename);
final String url = libs.get(filename);

if(!dl.exist()) {
dl.url(url);

MessageHandler.sendConsole("&6[" + getDescription().getPrefix() + "] &eBibliotek " + filename + " ble lastet ned...");
}
}
}

@Override
public void onDisable() {
try {
MessageHandler.sendConsole("[" + getDescription().getPrefix() + "] Stenger databasen...");

if(!MySqlPool.getDataSource().getConnection().isClosed()) {
MySqlPool.getDataSource().getConnection().close();
}

MessageHandler.sendConsole("[" + getDescription().getPrefix() + "] Kontakten til database er stengt...");

} catch (final SQLException e) {
e.printStackTrace();
}
}
}
29 changes: 15 additions & 14 deletions src/main/java/no/vestlandetmc/fv/bukkit/commands/SubCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,24 @@ public void reload() {
if(!isConsole) { MessageHandler.sendMessage(player, message); }
else { MessageHandler.sendConsole(message); }

new MySqlPool().initialize();

try {
MySqlPool.getConnection();
if(!isConsole) { MessageHandler.sendMessage(player, sqlEnabled); }
else { MessageHandler.sendConsole(sqlEnabled); }
new MySqlPool().initialize();
} catch (final SQLException e) {
e.printStackTrace();
}

if(!isConsole) { MessageHandler.sendMessage(player, sqlSS); }
else { MessageHandler.sendConsole(sqlSS); }
if(!isConsole) { MessageHandler.sendMessage(player, sqlEnabled); }
else { MessageHandler.sendConsole(sqlEnabled); }

MySQLHandler.sqlEnabled = true;
} catch (final SQLException e) {
if(!isConsole) { MessageHandler.sendMessage(player, sqlDisable); }
else {
MySQLHandler.sqlEnabled = false;
MessageHandler.sendConsole(sqlDisable);
}
if(!isConsole) { MessageHandler.sendMessage(player, sqlSS); }
else { MessageHandler.sendConsole(sqlSS); }

MySQLHandler.sqlEnabled = true;

if(!isConsole) { MessageHandler.sendMessage(player, sqlDisable); }
else {
MySQLHandler.sqlEnabled = false;
MessageHandler.sendConsole(sqlDisable);
}

if(!isConsole) { MessageHandler.sendMessage(player, litebans); }
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/no/vestlandetmc/fv/bukkit/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ private Config(String fileName) {
USER,
PASSWORD,
DATABASE,
SERVERNAME;
SERVERNAME,
SQLTYPE;

public static int
PORT,
Expand All @@ -40,6 +41,7 @@ private Config(String fileName) {
private void onLoad() {

SERVERNAME = getString("servername");
SQLTYPE = getString("mysql.engine");
HOST = getString("mysql.host");
USER = getString("mysql.user");
PASSWORD = getString("mysql.password");
Expand Down
Loading

0 comments on commit 5b8aa5b

Please sign in to comment.