mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-23 19:16:37 +01:00
Changes to messaging service setup
This commit is contained in:
parent
a5e15b8a29
commit
c4bd657826
@ -213,8 +213,8 @@ watch-files: true
|
||||
# installed.
|
||||
# => redis Uses Redis pub-sub to push changes. Your server connection info must be configured
|
||||
# below.
|
||||
# => none Disables the service.
|
||||
messaging-service: none
|
||||
# => auto Attempts to automatically setup a messaging service using redis or sql.
|
||||
messaging-service: auto
|
||||
|
||||
# If LuckPerms should automatically push updates after a change has been made with a command.
|
||||
auto-push-updates: true
|
||||
|
@ -211,8 +211,8 @@ watch-files: true
|
||||
# configured below.
|
||||
# => redisbungee Uses Redis pub-sub to push changes, using the RedisBungee API. You need to have
|
||||
# the RedisBungee plugin installed.
|
||||
# => none Disables the service.
|
||||
messaging-service: none
|
||||
# => auto Attempts to automatically setup a messaging service using redis or sql.
|
||||
messaging-service: auto
|
||||
|
||||
# If LuckPerms should automatically push updates after a change has been made with a command.
|
||||
auto-push-updates: true
|
||||
|
@ -485,7 +485,7 @@ public final class ConfigKeys {
|
||||
/**
|
||||
* The name of the messaging service in use, or "none" if not enabled
|
||||
*/
|
||||
public static final ConfigKey<String> MESSAGING_SERVICE = enduringKey(lowercaseStringKey("messaging-service", "none"));
|
||||
public static final ConfigKey<String> MESSAGING_SERVICE = enduringKey(lowercaseStringKey("messaging-service", "auto"));
|
||||
|
||||
/**
|
||||
* If updates should be automatically pushed by the messaging service
|
||||
|
@ -25,12 +25,11 @@
|
||||
|
||||
package me.lucko.luckperms.common.messaging;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.messaging.redis.RedisMessenger;
|
||||
import me.lucko.luckperms.common.messaging.sql.SqlMessenger;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.storage.implementation.StorageImplementation;
|
||||
import me.lucko.luckperms.common.storage.implementation.sql.SqlStorage;
|
||||
import me.lucko.luckperms.common.storage.implementation.sql.connection.hikari.MariaDbConnectionFactory;
|
||||
import me.lucko.luckperms.common.storage.implementation.sql.connection.hikari.MySqlConnectionFactory;
|
||||
@ -53,19 +52,29 @@ public class MessagingFactory<P extends LuckPermsPlugin> {
|
||||
}
|
||||
|
||||
public final InternalMessagingService getInstance() {
|
||||
String messagingType = this.plugin.getConfiguration().get(ConfigKeys.MESSAGING_SERVICE).toLowerCase();
|
||||
if (messagingType.equals("none") && this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
String messagingType = this.plugin.getConfiguration().get(ConfigKeys.MESSAGING_SERVICE);
|
||||
if (messagingType.equals("none")) {
|
||||
messagingType = "auto";
|
||||
}
|
||||
|
||||
// attempt to detect "auto" messaging service type.
|
||||
if (messagingType.equals("auto")) {
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
messagingType = "redis";
|
||||
}
|
||||
|
||||
if (messagingType.equals("none") && this.plugin.getStorage().getImplementation() instanceof SqlStorage) {
|
||||
SqlStorage dao = (SqlStorage) this.plugin.getStorage().getImplementation();
|
||||
if (dao.getConnectionFactory() instanceof MySqlConnectionFactory || dao.getConnectionFactory() instanceof MariaDbConnectionFactory) {
|
||||
} else {
|
||||
for (StorageImplementation implementation : this.plugin.getStorage().getImplementations()) {
|
||||
if (implementation instanceof SqlStorage) {
|
||||
SqlStorage sql = (SqlStorage) implementation;
|
||||
if (sql.getConnectionFactory() instanceof MySqlConnectionFactory || sql.getConnectionFactory() instanceof MariaDbConnectionFactory) {
|
||||
messagingType = "sql";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (messagingType.equals("none") || messagingType.equals("notsql")) {
|
||||
if (messagingType.equals("auto") || messagingType.equals("notsql")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -126,13 +135,20 @@ public class MessagingFactory<P extends LuckPermsPlugin> {
|
||||
|
||||
@Override
|
||||
public @NonNull Messenger obtain(@NonNull IncomingMessageConsumer incomingMessageConsumer) {
|
||||
SqlStorage dao = (SqlStorage) getPlugin().getStorage().getImplementation();
|
||||
Preconditions.checkState(dao.getConnectionFactory() instanceof MySqlConnectionFactory || dao.getConnectionFactory() instanceof MariaDbConnectionFactory, "not a supported sql type");
|
||||
|
||||
SqlMessenger sql = new SqlMessenger(getPlugin(), dao, incomingMessageConsumer);
|
||||
for (StorageImplementation implementation : getPlugin().getStorage().getImplementations()) {
|
||||
if (implementation instanceof SqlStorage) {
|
||||
SqlStorage storage = (SqlStorage) implementation;
|
||||
if (storage.getConnectionFactory() instanceof MySqlConnectionFactory || storage.getConnectionFactory() instanceof MariaDbConnectionFactory) {
|
||||
// found an implementation match!
|
||||
SqlMessenger sql = new SqlMessenger(getPlugin(), storage, incomingMessageConsumer);
|
||||
sql.init();
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Can't find a supported sql storage implementation");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import me.lucko.luckperms.common.model.Track;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.storage.implementation.StorageImplementation;
|
||||
import me.lucko.luckperms.common.storage.implementation.split.SplitStorage;
|
||||
import me.lucko.luckperms.common.util.ThrowingRunnable;
|
||||
|
||||
import net.luckperms.api.actionlog.Action;
|
||||
@ -43,6 +44,8 @@ import net.luckperms.api.event.cause.DeletionCause;
|
||||
import net.luckperms.api.model.PlayerSaveResult;
|
||||
import net.luckperms.api.node.HeldNode;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -68,6 +71,14 @@ public class Storage {
|
||||
return this.implementation;
|
||||
}
|
||||
|
||||
public Collection<StorageImplementation> getImplementations() {
|
||||
if (this.implementation instanceof SplitStorage) {
|
||||
return ((SplitStorage) this.implementation).getImplementations().values();
|
||||
} else {
|
||||
return Collections.singleton(this.implementation);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> CompletableFuture<T> makeFuture(Callable<T> supplier) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
|
@ -59,6 +59,10 @@ public class SplitStorage implements StorageImplementation {
|
||||
this.types = ImmutableMap.copyOf(types);
|
||||
}
|
||||
|
||||
public Map<StorageType, StorageImplementation> getImplementations() {
|
||||
return this.implementations;
|
||||
}
|
||||
|
||||
private StorageImplementation implFor(SplitStorageType type) {
|
||||
return this.implementations.get(this.types.get(type));
|
||||
}
|
||||
|
@ -38,16 +38,18 @@ import me.lucko.luckperms.common.verbose.expression.BooleanExpressionCompiler.Pa
|
||||
* evaluations should be relatively fast.</p>
|
||||
*/
|
||||
public final class VerboseFilter {
|
||||
private final String expression;
|
||||
private final AST ast;
|
||||
|
||||
public VerboseFilter(String filterExpression) throws InvalidFilterException {
|
||||
if (filterExpression.isEmpty()) {
|
||||
public VerboseFilter(String expression) throws InvalidFilterException {
|
||||
this.expression = expression;
|
||||
if (expression.isEmpty()) {
|
||||
this.ast = AST.ALWAYS_TRUE;
|
||||
} else {
|
||||
try {
|
||||
this.ast = BooleanExpressionCompiler.compile(filterExpression);
|
||||
this.ast = BooleanExpressionCompiler.compile(expression);
|
||||
} catch (LexerException | ParserException e) {
|
||||
throw new InvalidFilterException("Exception occurred whilst generating an expression for '" + filterExpression + "'", e);
|
||||
throw new InvalidFilterException("Exception occurred whilst generating an expression for '" + expression + "'", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,10 +61,6 @@ public final class VerboseFilter {
|
||||
* @return if the check data passes the filter
|
||||
*/
|
||||
public boolean evaluate(VerboseEvent data) {
|
||||
if (isBlank()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return this.ast.eval(data);
|
||||
} catch (Exception e) {
|
||||
@ -75,4 +73,8 @@ public final class VerboseFilter {
|
||||
return this.ast == AST.ALWAYS_TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return isBlank() ? "any" : this.expression;
|
||||
}
|
||||
}
|
||||
|
@ -258,14 +258,6 @@ public class VerboseListener {
|
||||
String endDate = DATE_FORMAT.format(new Date(now));
|
||||
long secondsTaken = (now - this.startTime) / 1000L;
|
||||
String duration = DurationFormatter.CONCISE.format(secondsTaken);
|
||||
|
||||
String filter;
|
||||
if (this.filter.isBlank()){
|
||||
filter = "any";
|
||||
} else {
|
||||
filter = this.filter.toString();
|
||||
}
|
||||
|
||||
boolean truncated = this.matchedCounter.get() > this.results.size();
|
||||
|
||||
JObject metadata = new JObject()
|
||||
@ -280,7 +272,7 @@ public class VerboseListener {
|
||||
.add("name", this.notifiedSender.getNameWithLocation())
|
||||
.add("uuid", this.notifiedSender.getUniqueId().toString())
|
||||
)
|
||||
.add("filter", filter)
|
||||
.add("filter", this.filter.toString())
|
||||
.add("truncated", truncated);
|
||||
|
||||
JArray data = new JArray();
|
||||
|
@ -208,8 +208,8 @@ watch-files: true
|
||||
# option is set to 'none' and SQL storage is in use. Set to 'notsql' to disable this.
|
||||
# => redis Uses Redis pub-sub to push changes. Your server connection info must be configured
|
||||
# below.
|
||||
# => none Disables the service.
|
||||
messaging-service: none
|
||||
# => auto Attempts to automatically setup a messaging service using redis or sql.
|
||||
messaging-service: auto
|
||||
|
||||
# If LuckPerms should automatically push updates after a change has been made with a command.
|
||||
auto-push-updates: true
|
||||
|
@ -216,8 +216,8 @@ watch-files = true
|
||||
# Won't work if you have more than one proxy.
|
||||
# => redis Uses Redis pub-sub to push changes. Your server connection info must be configured
|
||||
# below.
|
||||
# => none Disables the service.
|
||||
messaging-service = "none"
|
||||
# => auto Attempts to automatically setup a messaging service using redis or sql.
|
||||
messaging-service = "auto"
|
||||
|
||||
# If LuckPerms should automatically push updates after a change has been made with a command.
|
||||
auto-push-updates = true
|
||||
|
@ -202,8 +202,8 @@ watch-files: true
|
||||
# servers. Won't work if you have more than one Velocity proxy.
|
||||
# => redis Uses Redis pub-sub to push changes. Your server connection info must be
|
||||
# configured below.
|
||||
# => none Disables the service.
|
||||
messaging-service: none
|
||||
# => auto Attempts to automatically setup a messaging service using redis or sql.
|
||||
messaging-service: auto
|
||||
|
||||
# If LuckPerms should automatically push updates after a change has been made with a command.
|
||||
auto-push-updates: true
|
||||
|
Loading…
Reference in New Issue
Block a user