Skip to content

Commit

Permalink
optimized for mongodb & added mongodb basics
Browse files Browse the repository at this point in the history
  • Loading branch information
ezTxmMC committed Aug 19, 2024
1 parent 2a3b07b commit a09a950
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 34 deletions.
5 changes: 5 additions & 0 deletions luckprefix-modern/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
<artifactId>ezlib-database-sqlite</artifactId>
<version>1.0-ALPHA10</version>
</dependency>
<dependency>
<groupId>de.eztxm</groupId>
<artifactId>ezlib-database-mongodb</artifactId>
<version>1.0-ALPHA10</version>
</dependency>
<dependency>
<groupId>de.eztxm</groupId>
<artifactId>ezlib-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.eztxm.luckprefix;

import de.eztxm.api.database.SQLConnection;
import de.eztxm.database.MongoDBConnection;
import de.eztxm.luckprefix.command.LuckPrefixCommand;
import de.eztxm.luckprefix.database.Table;
import de.eztxm.luckprefix.database.sql.Table;
import de.eztxm.luckprefix.listener.ChatListener;
import de.eztxm.luckprefix.listener.GroupListener;
import de.eztxm.luckprefix.listener.JoinListener;
Expand All @@ -22,11 +23,12 @@ public final class LuckPrefix extends JavaPlugin {
private String prefix;
private ConfigManager databaseFile;
private ConfigManager groupsFile;
private SQLConnection connection;
private MongoDBConnection mongoDBConnection;
private SQLConnection sqlConnection;
private BukkitAudiences adventure;
private LuckPerms luckPerms;
private Registry registry;
private DatabaseManager databaseManager;
private SQLDatabaseManager sqlDatabaseManager;
private PlayerManager playerManager;
private GroupManager groupManager;
private GroupListener groupListener;
Expand All @@ -39,11 +41,15 @@ public void onEnable() {
prefix = "<#77ef77>LuckPrefix <dark_gray>| <gray>";
databaseFile = ConfigUtil.addDatabaseDefault("database.yml");
groupsFile = ConfigUtil.addGroupsDefault("groups.yml");
if (LuckPrefix.getInstance().getDatabaseFile().getValue("Database.Enabled").asBoolean()) {
connection = DatabaseManager.createDatabaseConnection();
databaseManager = new DatabaseManager(connection);
databaseManager.getProcessor().createTable(Table.CREATE_GROUPS_TABLE);
databaseManager.getProcessor().createTable(Table.CREATE_MESSAGES_TABLE);
if (getDatabaseFile().getValue("Database.Enabled").asBoolean()) {
if (getDatabaseFile().getValue("Database.Type").asString().equalsIgnoreCase("mongodb")) {
mongoDBConnection = MongoDBManager.createMongoDBConnection();
} else {
sqlConnection = SQLDatabaseManager.createSQLDatabaseConnection();
sqlDatabaseManager = new SQLDatabaseManager(sqlConnection);
sqlDatabaseManager.getProcessor().createTable(Table.CREATE_GROUPS_TABLE);
sqlDatabaseManager.getProcessor().createTable(Table.CREATE_MESSAGES_TABLE);
}
}
adventure = BukkitAudiences.create(instance);
luckPerms = LuckPermsProvider.get();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.eztxm.luckprefix.database.sql;

public class Delete {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.eztxm.luckprefix.database.sql;

public class Insert {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.eztxm.luckprefix.database.sql;

public class Select {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.eztxm.luckprefix.database;
package de.eztxm.luckprefix.database.sql;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package de.eztxm.luckprefix.database.sql;

public class Update {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.eztxm.luckprefix.util;

import de.eztxm.database.MongoDBConnection;
import de.eztxm.luckprefix.LuckPrefix;
import de.eztxm.luckprefix.util.database.MongoDBProcessor;
import org.bukkit.configuration.file.FileConfiguration;

public class MongoDBManager {
private final MongoDBProcessor processor;

public MongoDBManager(MongoDBConnection connection) {
this.processor = new MongoDBProcessor(connection);
}

public static MongoDBConnection createMongoDBConnection() {
FileConfiguration config = LuckPrefix.getInstance().getConfig();
return new MongoDBConnection(
config.getString("Database.MariaDB.Host"),
config.getInt("Database.MariaDB.Port"),
config.getString("Database.MariaDB.User"),
config.getString("Database.MariaDB.Password"),
config.getString("Database.MariaDB.Database")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import de.eztxm.database.MariaDBConnection;
import de.eztxm.database.SQLiteConnection;
import de.eztxm.luckprefix.LuckPrefix;
import de.eztxm.luckprefix.util.database.DatabaseProcessor;
import de.eztxm.luckprefix.util.database.SQLDatabaseProcessor;
import lombok.Getter;
import org.bukkit.configuration.file.FileConfiguration;

@Getter
public class DatabaseManager {
private final DatabaseProcessor processor;
public class SQLDatabaseManager {
private final SQLDatabaseProcessor processor;

public DatabaseManager(SQLConnection connection) {
this.processor = new DatabaseProcessor(connection);
public SQLDatabaseManager(SQLConnection connection) {
this.processor = new SQLDatabaseProcessor(connection);
}

public static SQLConnection createDatabaseConnection() {
public static SQLConnection createSQLDatabaseConnection() {
FileConfiguration config = LuckPrefix.getInstance().getConfig();
String type = config.getString("Database.Type");
return switch (type.toUpperCase()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.eztxm.luckprefix.util.database;

import de.eztxm.database.MongoDBConnection;

public class MongoDBProcessor {
private final MongoDBConnection connection;

public MongoDBProcessor(MongoDBConnection connection) {
this.connection = connection;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package de.eztxm.luckprefix.util.database;

import de.eztxm.api.database.SQLConnection;
import de.eztxm.luckprefix.database.Table;
import de.eztxm.luckprefix.database.sql.Table;

public class DatabaseProcessor {
public class SQLDatabaseProcessor {
private final SQLConnection connection;

public DatabaseProcessor(SQLConnection connection) {
public SQLDatabaseProcessor(SQLConnection connection) {
this.connection = connection;
}

Expand Down

0 comments on commit a09a950

Please sign in to comment.