Skip to content

Commit

Permalink
Merge pull request #4 from MEFRREEX/feat/more-server-software
Browse files Browse the repository at this point in the history
feat: more server software and fixes
  • Loading branch information
MEFRREEX authored Apr 23, 2024
2 parents eefb070 + ea5d53d commit 32c7c6f
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 14 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Features:
- MySQL support
- Disabled printing logo and tips from JOOQ
- Inclusion of JOOQ, SQLite and MySQL drivers in jar file
- Support for different server software (Nukkit, PowerNukkitX, JukeboxMC, WaterdogPE)

## 🛠 Examples

Expand Down Expand Up @@ -62,7 +63,7 @@ System.out.println("Value from table: " + value);

Example of using a MySQL database
```java
MySQLDatabase database = new MySQLDatabase("host", "database", "user", "password");
MySQLDatabase database = new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");

// Other code will be identical...
```
Expand All @@ -71,7 +72,7 @@ Example of using SQlite or MySQL database
```java
IDatabase database = sqlite ?
new SQLiteDatabase(new File("database.db")) :
new MySQLDatabase("host", "database", "user", "password");
new MySQLDatabase("127.0.0.1:3306", "database", "user", "password");
```

You can make a separate class with methods for the database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mefrreex.jooq.exception.ConnectionNotEstablishedException;
import org.jooq.SQLDialect;
import lombok.Getter;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand All @@ -10,6 +11,7 @@
import java.sql.SQLException;
import java.util.concurrent.CompletableFuture;

@Getter
public class MySQLDatabase implements IDatabase {

private final String host;
Expand All @@ -19,10 +21,7 @@ public class MySQLDatabase implements IDatabase {
private Connection connection;

public MySQLDatabase(String host, String database, String user, String password) {
if (!host.contains(":")) {
throw new IllegalArgumentException("Host must be in format: address:port");
}
this.host = host;
this.host = host.contains(":") ? host : host + ":3306";
this.database = database;
this.user = user;
this.password = password;
Expand Down
16 changes: 9 additions & 7 deletions api/src/main/java/com/mefrreex/jooq/database/SQLiteDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mefrreex.jooq.exception.ConnectionNotEstablishedException;
import org.jooq.SQLDialect;
import lombok.Getter;

import java.io.File;
import java.io.IOException;
Expand All @@ -10,17 +11,18 @@
import java.sql.SQLException;
import java.util.concurrent.CompletableFuture;

@Getter
public class SQLiteDatabase implements IDatabase {

private final File database;
private final File file;
private Connection connection;

public SQLiteDatabase(File database) {
this.database = database;
if (!database.exists()) {
public SQLiteDatabase(File file) {
this.file = file;
if (!file.exists()) {
try {
if (!database.createNewFile()) {
throw new IOException("Failed to create the database file.");
if (!file.createNewFile()) {
throw new IOException("Failed to create the database file");
}
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -38,7 +40,7 @@ public CompletableFuture<Connection> getConnection() {
return CompletableFuture.supplyAsync(() -> {
try {
if (connection == null || connection.isClosed()) {
connection = DriverManager.getConnection("jdbc:sqlite:" + database.getAbsolutePath());
connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
}
return connection;
} catch (SQLException e) {
Expand Down
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ tasks.build {
allprojects {
group = "com.mefrreex.jooqconnector"
description = "jooqconnector"
version = "1.0.0"
version = "1.0.1"
}

subprojects {
Expand Down Expand Up @@ -42,6 +42,10 @@ subprojects {
}
}

fun getArchiveName(): String {
return name
}

publishing {
publications {
create<MavenPublication>("maven") {
Expand Down
22 changes: 22 additions & 0 deletions plugin-jukeboxmc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
}

repositories {
maven("https://repo.jukeboxmc.eu/releases")
maven("https://repo.jukeboxmc.eu/snapshots")
}

dependencies {
compileOnlyApi("org.jukeboxmc:JukeboxMC-API:1.0.0-SNAPSHOT")
api(project(":api"))
}

tasks.withType<Jar> {
archiveFileName.set("JOOQConnector-JukeboxMC-${project.version}.jar")
}

tasks.build {
dependsOn(tasks.shadowJar)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mefrreex.jooq;

import org.jukeboxmc.api.plugin.Plugin;

public class JOOQConnectorJukeboxMC extends Plugin {

@Override
public void onStartup() {
JOOQConnector.setJOOQMessagesEnabled(false);
}

@Override
public void onEnable() {

}
}
4 changes: 4 additions & 0 deletions plugin-jukeboxmc/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "JOOQConnector"
version: "${project.version}"
author: "MEFRREEX"
main: com.mefrreex.jooq.JOOQConnectorJukeboxMC
24 changes: 24 additions & 0 deletions plugin-waterdogpe/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id("java")
id("com.github.johnrengelman.shadow") version "8.1.1"
}

repositories {
mavenCentral()
maven("https://repo.waterdog.dev/main")
maven("https://repo.opencollab.dev/maven-releases")
maven("https://repo.opencollab.dev/maven-snapshots")
}

dependencies {
compileOnlyApi("dev.waterdog.waterdogpe:waterdog:2.0.0-SNAPSHOT")
api(project(":api"))
}

tasks.withType<Jar> {
archiveFileName.set("JOOQConnector-WaterdogPE-${project.version}.jar")
}

tasks.build {
dependsOn(tasks.shadowJar)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mefrreex.jooq;

import dev.waterdog.waterdogpe.plugin.Plugin;

public class JOOQConnectorWaterdogPE extends Plugin {

@Override
public void onStartup() {
JOOQConnector.setJOOQMessagesEnabled(false);
}

@Override
public void onEnable() {

}
}
4 changes: 4 additions & 0 deletions plugin-waterdogpe/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "JOOQConnector"
version: "${project.version}"
author: "MEFRREEX"
main: com.mefrreex.jooq.JOOQConnectorWaterdogPE
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ rootProject.name = "JOOQConnector"
include("api")
include("plugin-nukkit")
include("plugin-pnx")
include("plugin-jukeboxmc")
include("plugin-waterdogpe")

0 comments on commit 32c7c6f

Please sign in to comment.