mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 13:15:28 +01:00
parent
faba022a7b
commit
6a28ba0b1d
@ -103,6 +103,11 @@ public class Settings implements ConfigObject {
|
||||
@ConfigEntry(path = "general.database.prefix-character", since = "1.13.0")
|
||||
private String databasePrefix = "";
|
||||
|
||||
@ConfigComment("MongoDB client connection URI to override default connection options.")
|
||||
@ConfigComment("See: https://docs.mongodb.com/manual/reference/connection-string/")
|
||||
@ConfigEntry(path = "general.database.mongodb-connection-uri", since = "1.14.0")
|
||||
private String mongodbConnectionUri = "";
|
||||
|
||||
@ConfigComment("Allow FTB Autonomous Activator to work (will allow a pseudo player [CoFH] to place and break blocks and hang items)")
|
||||
@ConfigComment("Add other fake player names here if required")
|
||||
@ConfigEntry(path = "general.fakeplayers", experimental = true)
|
||||
@ -661,4 +666,23 @@ public class Settings implements ConfigObject {
|
||||
public void setKeepPreviousIslandOnReset(boolean keepPreviousIslandOnReset) {
|
||||
this.keepPreviousIslandOnReset = keepPreviousIslandOnReset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a MongoDB client connection URI to override default connection options.
|
||||
*
|
||||
* @return mongodb client connection.
|
||||
* @see <a href="https://docs.mongodb.com/manual/reference/connection-string/">MongoDB Documentation</a>
|
||||
* @since 1.14.0
|
||||
*/
|
||||
public String getMongodbConnectionUri() {
|
||||
return mongodbConnectionUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MongoDB client connection URI.
|
||||
* @param mongodbConnectionUri connection URI.
|
||||
*/
|
||||
public void setMongodbConnectionUri(String mongodbConnectionUri) {
|
||||
this.mongodbConnectionUri = mongodbConnectionUri;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class MongoDBDatabase implements DatabaseSetup {
|
||||
plugin.getSettings().getDatabaseUsername(),
|
||||
plugin.getSettings().getDatabasePassword(),
|
||||
plugin.getSettings().isUseSSL()
|
||||
));
|
||||
), plugin.getSettings().getMongodbConnectionUri());
|
||||
}
|
||||
return new MongoDBDatabaseHandler<>(plugin, type, connector);
|
||||
}
|
||||
|
@ -3,13 +3,10 @@ package world.bentobox.bentobox.database.mongodb;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.mongodb.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientOptions;
|
||||
import com.mongodb.MongoCredential;
|
||||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
|
||||
@ -18,15 +15,17 @@ import world.bentobox.bentobox.database.DatabaseConnector;
|
||||
public class MongoDBDatabaseConnector implements DatabaseConnector {
|
||||
|
||||
private MongoClient client;
|
||||
private DatabaseConnectionSettingsImpl dbSettings;
|
||||
private Set<Class<?>> types = new HashSet<>();
|
||||
private final DatabaseConnectionSettingsImpl dbSettings;
|
||||
private final String mongoDbConnectionURI;
|
||||
private final Set<Class<?>> types = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Class for MySQL database connections using the settings provided
|
||||
* @param dbSettings - database settings
|
||||
*/
|
||||
MongoDBDatabaseConnector(DatabaseConnectionSettingsImpl dbSettings) {
|
||||
MongoDBDatabaseConnector(DatabaseConnectionSettingsImpl dbSettings, String mongoDbConnectionURI) {
|
||||
this.dbSettings = dbSettings;
|
||||
this.mongoDbConnectionURI = mongoDbConnectionURI;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,11 +33,16 @@ public class MongoDBDatabaseConnector implements DatabaseConnector {
|
||||
types.add(type);
|
||||
// Only get one client
|
||||
if (client == null) {
|
||||
MongoCredential credential = MongoCredential.createCredential(dbSettings.getUsername(),
|
||||
dbSettings.getDatabaseName(),
|
||||
dbSettings.getPassword().toCharArray());
|
||||
MongoClientOptions options = MongoClientOptions.builder().sslEnabled(dbSettings.isUseSSL()).build();
|
||||
client = new MongoClient(new ServerAddress(dbSettings.getHost(), dbSettings.getPort()), credential,options);
|
||||
if(mongoDbConnectionURI == null || mongoDbConnectionURI.isEmpty()){
|
||||
MongoCredential credential = MongoCredential.createCredential(dbSettings.getUsername(),
|
||||
dbSettings.getDatabaseName(),
|
||||
dbSettings.getPassword().toCharArray());
|
||||
MongoClientOptions options = MongoClientOptions.builder().sslEnabled(dbSettings.isUseSSL()).build();
|
||||
client = new MongoClient(new ServerAddress(dbSettings.getHost(), dbSettings.getPort()), credential,options);
|
||||
}else {
|
||||
client = new MongoClient(new MongoClientURI(this.mongoDbConnectionURI));
|
||||
}
|
||||
|
||||
}
|
||||
return client.getDatabase(dbSettings.getDatabaseName());
|
||||
}
|
||||
|
@ -54,6 +54,9 @@ general:
|
||||
name: bentobox
|
||||
username: username
|
||||
password: password
|
||||
# MongoDB client connection URI to override default connection options.
|
||||
# See: https://docs.mongodb.com/manual/reference/connection-string/
|
||||
mongodb-connection-uri: ''
|
||||
# How often the data will be saved to file in mins. Default is 5 minutes.
|
||||
# This helps prevent issues if the server crashes.
|
||||
# Data is also saved at important points in the game.
|
||||
|
Loading…
Reference in New Issue
Block a user