mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Add MongoDB collection prefix option
This commit is contained in:
parent
2ecaa39cb6
commit
b9fc8f4b5f
@ -250,6 +250,10 @@ data:
|
|||||||
# This should *not* be set to "lp_" if you have previously ran LuckPerms v2.16.81 or earlier with this database.
|
# This should *not* be set to "lp_" if you have previously ran LuckPerms v2.16.81 or earlier with this database.
|
||||||
table_prefix: 'luckperms_'
|
table_prefix: 'luckperms_'
|
||||||
|
|
||||||
|
# The prefix to use for all LuckPerms collections. Change this if you want to use different collections for different servers.
|
||||||
|
# The default is no prefix.
|
||||||
|
mongodb_collection_prefix: ''
|
||||||
|
|
||||||
# This option controls how frequently LuckPerms will perform a sync task.
|
# This option controls how frequently LuckPerms will perform a sync task.
|
||||||
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is being used by the plugin.
|
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is being used by the plugin.
|
||||||
#
|
#
|
||||||
|
@ -185,6 +185,10 @@ data:
|
|||||||
# This should *not* be set to "lp_" if you have previously ran LuckPerms v2.16.81 or earlier with this database.
|
# This should *not* be set to "lp_" if you have previously ran LuckPerms v2.16.81 or earlier with this database.
|
||||||
table_prefix: 'luckperms_'
|
table_prefix: 'luckperms_'
|
||||||
|
|
||||||
|
# The prefix to use for all LuckPerms collections. Change this if you want to use different collections for different servers.
|
||||||
|
# The default is no prefix.
|
||||||
|
mongodb_collection_prefix: ''
|
||||||
|
|
||||||
# This option controls how frequently LuckPerms will perform a sync task.
|
# This option controls how frequently LuckPerms will perform a sync task.
|
||||||
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is being used by the plugin.
|
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is being used by the plugin.
|
||||||
#
|
#
|
||||||
|
@ -342,6 +342,11 @@ public class ConfigKeys {
|
|||||||
*/
|
*/
|
||||||
public static final ConfigKey<String> SQL_TABLE_PREFIX = EnduringKey.wrap(StringKey.of("data.table_prefix", "luckperms_"));
|
public static final ConfigKey<String> SQL_TABLE_PREFIX = EnduringKey.wrap(StringKey.of("data.table_prefix", "luckperms_"));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prefix for any MongoDB collections
|
||||||
|
*/
|
||||||
|
public static final ConfigKey<String> MONGODB_COLLECTION_PREFIX = EnduringKey.wrap(StringKey.of("data.mongodb_collection_prefix", ""));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the storage method being used
|
* The name of the storage method being used
|
||||||
*/
|
*/
|
||||||
|
@ -149,7 +149,11 @@ public class StorageFactory {
|
|||||||
plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX)
|
plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX)
|
||||||
);
|
);
|
||||||
case MONGODB:
|
case MONGODB:
|
||||||
return new MongoDBBacking(plugin, plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES));
|
return new MongoDBBacking(
|
||||||
|
plugin,
|
||||||
|
plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES),
|
||||||
|
plugin.getConfiguration().get(ConfigKeys.MONGODB_COLLECTION_PREFIX)
|
||||||
|
);
|
||||||
case YAML:
|
case YAML:
|
||||||
return new YAMLBacking(plugin, plugin.getDataDirectory(), "yaml-storage");
|
return new YAMLBacking(plugin, plugin.getDataDirectory(), "yaml-storage");
|
||||||
default:
|
default:
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.storage.backing;
|
package me.lucko.luckperms.common.storage.backing;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
import com.mongodb.MongoCredential;
|
import com.mongodb.MongoCredential;
|
||||||
@ -130,9 +132,13 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
private MongoClient mongoClient;
|
private MongoClient mongoClient;
|
||||||
private MongoDatabase database;
|
private MongoDatabase database;
|
||||||
|
|
||||||
public MongoDBBacking(LuckPermsPlugin plugin, DatastoreConfiguration configuration) {
|
@Getter
|
||||||
|
private final String prefix;
|
||||||
|
|
||||||
|
public MongoDBBacking(LuckPermsPlugin plugin, DatastoreConfiguration configuration, String prefix) {
|
||||||
super(plugin, "MongoDB");
|
super(plugin, "MongoDB");
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -179,7 +185,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
@Override
|
@Override
|
||||||
public boolean logAction(LogEntry entry) {
|
public boolean logAction(LogEntry entry) {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("action");
|
MongoCollection<Document> c = database.getCollection(prefix + "action");
|
||||||
|
|
||||||
Document doc = new Document()
|
Document doc = new Document()
|
||||||
.append("timestamp", entry.getTimestamp())
|
.append("timestamp", entry.getTimestamp())
|
||||||
@ -202,7 +208,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
public Log getLog() {
|
public Log getLog() {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
final Log.Builder log = Log.builder();
|
final Log.Builder log = Log.builder();
|
||||||
MongoCollection<Document> c = database.getCollection("action");
|
MongoCollection<Document> c = database.getCollection(prefix + "action");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -234,7 +240,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
public boolean applyBulkUpdate(BulkUpdate bulkUpdate) {
|
public boolean applyBulkUpdate(BulkUpdate bulkUpdate) {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
if (bulkUpdate.getDataType().isIncludingUsers()) {
|
if (bulkUpdate.getDataType().isIncludingUsers()) {
|
||||||
MongoCollection<Document> c = database.getCollection("users");
|
MongoCollection<Document> c = database.getCollection(prefix + "users");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -268,7 +274,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bulkUpdate.getDataType().isIncludingGroups()) {
|
if (bulkUpdate.getDataType().isIncludingGroups()) {
|
||||||
MongoCollection<Document> c = database.getCollection("groups");
|
MongoCollection<Document> c = database.getCollection(prefix + "groups");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -311,7 +317,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
user.getIoLock().lock();
|
user.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("users");
|
MongoCollection<Document> c = database.getCollection(prefix + "users");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUuid())).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUuid())).iterator()) {
|
||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
@ -354,7 +360,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
user.getIoLock().lock();
|
user.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("users");
|
MongoCollection<Document> c = database.getCollection(prefix + "users");
|
||||||
return c.deleteOne(new Document("_id", user.getUuid())).wasAcknowledged();
|
return c.deleteOne(new Document("_id", user.getUuid())).wasAcknowledged();
|
||||||
}, false);
|
}, false);
|
||||||
} finally {
|
} finally {
|
||||||
@ -365,7 +371,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
user.getIoLock().lock();
|
user.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("users");
|
MongoCollection<Document> c = database.getCollection(prefix + "users");
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUuid())).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUuid())).iterator()) {
|
||||||
if (!cursor.hasNext()) {
|
if (!cursor.hasNext()) {
|
||||||
c.insertOne(fromUser(user));
|
c.insertOne(fromUser(user));
|
||||||
@ -389,7 +395,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
public Set<UUID> getUniqueUsers() {
|
public Set<UUID> getUniqueUsers() {
|
||||||
Set<UUID> uuids = new HashSet<>();
|
Set<UUID> uuids = new HashSet<>();
|
||||||
boolean success = call(() -> {
|
boolean success = call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("users");
|
MongoCollection<Document> c = database.getCollection(prefix + "users");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -408,7 +414,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
||||||
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
||||||
boolean success = call(() -> {
|
boolean success = call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("users");
|
MongoCollection<Document> c = database.getCollection(prefix + "users");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -439,7 +445,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("groups");
|
MongoCollection<Document> c = database.getCollection(prefix + "groups");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", group.getName())).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", group.getName())).iterator()) {
|
||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
@ -466,7 +472,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("groups");
|
MongoCollection<Document> c = database.getCollection(prefix + "groups");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", group.getName())).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", group.getName())).iterator()) {
|
||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
@ -490,7 +496,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
public boolean loadAllGroups() {
|
public boolean loadAllGroups() {
|
||||||
List<String> groups = new ArrayList<>();
|
List<String> groups = new ArrayList<>();
|
||||||
boolean success = call(() -> {
|
boolean success = call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("groups");
|
MongoCollection<Document> c = database.getCollection(prefix + "groups");
|
||||||
|
|
||||||
boolean b = true;
|
boolean b = true;
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
@ -519,7 +525,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
group.getIoLock().lock();
|
group.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("groups");
|
MongoCollection<Document> c = database.getCollection(prefix + "groups");
|
||||||
return c.replaceOne(new Document("_id", group.getName()), fromGroup(group)).wasAcknowledged();
|
return c.replaceOne(new Document("_id", group.getName()), fromGroup(group)).wasAcknowledged();
|
||||||
}, false);
|
}, false);
|
||||||
} finally {
|
} finally {
|
||||||
@ -533,7 +539,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
boolean success;
|
boolean success;
|
||||||
try {
|
try {
|
||||||
success = call(() -> {
|
success = call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("groups");
|
MongoCollection<Document> c = database.getCollection(prefix + "groups");
|
||||||
return c.deleteOne(new Document("_id", group.getName())).wasAcknowledged();
|
return c.deleteOne(new Document("_id", group.getName())).wasAcknowledged();
|
||||||
}, false);
|
}, false);
|
||||||
} finally {
|
} finally {
|
||||||
@ -548,7 +554,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
||||||
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
||||||
boolean success = call(() -> {
|
boolean success = call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("groups");
|
MongoCollection<Document> c = database.getCollection(prefix + "groups");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -579,7 +585,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("tracks");
|
MongoCollection<Document> c = database.getCollection(prefix + "tracks");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", track.getName())).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", track.getName())).iterator()) {
|
||||||
if (!cursor.hasNext()) {
|
if (!cursor.hasNext()) {
|
||||||
@ -602,7 +608,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("tracks");
|
MongoCollection<Document> c = database.getCollection(prefix + "tracks");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", track.getName())).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", track.getName())).iterator()) {
|
||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
@ -622,7 +628,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
public boolean loadAllTracks() {
|
public boolean loadAllTracks() {
|
||||||
List<String> tracks = new ArrayList<>();
|
List<String> tracks = new ArrayList<>();
|
||||||
boolean success = call(() -> {
|
boolean success = call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("tracks");
|
MongoCollection<Document> c = database.getCollection(prefix + "tracks");
|
||||||
|
|
||||||
boolean b = true;
|
boolean b = true;
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
@ -651,7 +657,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
track.getIoLock().lock();
|
track.getIoLock().lock();
|
||||||
try {
|
try {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("tracks");
|
MongoCollection<Document> c = database.getCollection(prefix + "tracks");
|
||||||
return c.replaceOne(new Document("_id", track.getName()), fromTrack(track)).wasAcknowledged();
|
return c.replaceOne(new Document("_id", track.getName()), fromTrack(track)).wasAcknowledged();
|
||||||
}, false);
|
}, false);
|
||||||
} finally {
|
} finally {
|
||||||
@ -665,7 +671,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
boolean success;
|
boolean success;
|
||||||
try {
|
try {
|
||||||
success = call(() -> {
|
success = call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("tracks");
|
MongoCollection<Document> c = database.getCollection(prefix + "tracks");
|
||||||
return c.deleteOne(new Document("_id", track.getName())).wasAcknowledged();
|
return c.deleteOne(new Document("_id", track.getName())).wasAcknowledged();
|
||||||
}, false);
|
}, false);
|
||||||
} finally {
|
} finally {
|
||||||
@ -679,7 +685,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
@Override
|
@Override
|
||||||
public boolean saveUUIDData(String username, UUID uuid) {
|
public boolean saveUUIDData(String username, UUID uuid) {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("uuid");
|
MongoCollection<Document> c = database.getCollection(prefix + "uuid");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", uuid)).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", uuid)).iterator()) {
|
||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
@ -696,7 +702,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
@Override
|
@Override
|
||||||
public UUID getUUID(String username) {
|
public UUID getUUID(String username) {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("uuid");
|
MongoCollection<Document> c = database.getCollection(prefix + "uuid");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("name", username.toLowerCase())).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("name", username.toLowerCase())).iterator()) {
|
||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
@ -710,7 +716,7 @@ public class MongoDBBacking extends AbstractBacking {
|
|||||||
@Override
|
@Override
|
||||||
public String getName(UUID uuid) {
|
public String getName(UUID uuid) {
|
||||||
return call(() -> {
|
return call(() -> {
|
||||||
MongoCollection<Document> c = database.getCollection("uuid");
|
MongoCollection<Document> c = database.getCollection(prefix + "uuid");
|
||||||
|
|
||||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", uuid)).iterator()) {
|
try (MongoCursor<Document> cursor = c.find(new Document("_id", uuid)).iterator()) {
|
||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
|
@ -117,6 +117,7 @@ public class SQLBacking extends AbstractBacking {
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final SQLProvider provider;
|
private final SQLProvider provider;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Function<String, String> prefix;
|
private final Function<String, String> prefix;
|
||||||
|
|
||||||
|
@ -204,6 +204,10 @@ data {
|
|||||||
# This should *not* be set to "lp_" if you have previously ran LuckPerms v2.16.81 or earlier with this database.
|
# This should *not* be set to "lp_" if you have previously ran LuckPerms v2.16.81 or earlier with this database.
|
||||||
table_prefix="luckperms_"
|
table_prefix="luckperms_"
|
||||||
|
|
||||||
|
# The prefix to use for all LuckPerms collections. Change this if you want to use different collections for different servers.
|
||||||
|
# The default is no prefix.
|
||||||
|
mongodb_collection_prefix=""
|
||||||
|
|
||||||
# This option controls how frequently LuckPerms will perform a sync task.
|
# This option controls how frequently LuckPerms will perform a sync task.
|
||||||
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is being used by the plugin.
|
# A sync task will refresh all data from the storage, and ensure that the most up-to-date data is being used by the plugin.
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user