Cleanup / tidy up a number of classes
This commit is contained in:
@@ -34,11 +34,10 @@ import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.constants.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.NoopMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class LogDispatcher {
|
||||
@@ -55,18 +54,15 @@ public class LogDispatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
InternalMessagingService messagingService = plugin.getMessagingService();
|
||||
if (!sender.isImport() && !(messagingService instanceof NoopMessagingService)) {
|
||||
messagingService.pushLog(entry);
|
||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (!sender.isImport() && messagingService.isPresent()) {
|
||||
messagingService.get().pushLog(entry);
|
||||
}
|
||||
|
||||
if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(!plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY), entry, LogBroadcastEvent.Origin.LOCAL)) {
|
||||
final String msg = entry.getFormatted();
|
||||
|
||||
List<Sender> senders = plugin.getOnlineSenders();
|
||||
senders.add(plugin.getConsoleSender());
|
||||
|
||||
senders.stream()
|
||||
plugin.getOnlineSenders()
|
||||
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
|
||||
.filter(s -> !LogNotify.isIgnoring(plugin, s.getUuid()))
|
||||
.filter(s -> !s.getUuid().equals(sender.getUuid()))
|
||||
@@ -82,10 +78,7 @@ public class LogDispatcher {
|
||||
if (!plugin.getApiProvider().getEventFactory().handleLogBroadcast(!plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY), entry, LogBroadcastEvent.Origin.REMOTE)) {
|
||||
final String msg = entry.getFormatted();
|
||||
|
||||
List<Sender> senders = plugin.getOnlineSenders();
|
||||
senders.add(plugin.getConsoleSender());
|
||||
|
||||
senders.stream()
|
||||
plugin.getOnlineSenders()
|
||||
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
|
||||
.filter(s -> !LogNotify.isIgnoring(plugin, s.getUuid()))
|
||||
.forEach(s -> Message.LOG.send(s, msg));
|
||||
|
||||
@@ -48,8 +48,6 @@ import me.lucko.luckperms.common.api.delegates.NodeFactoryDelegate;
|
||||
import me.lucko.luckperms.common.api.delegates.UserDelegate;
|
||||
import me.lucko.luckperms.common.event.EventFactory;
|
||||
import me.lucko.luckperms.common.event.LuckPermsEventBus;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.NoopMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.references.UserIdentifier;
|
||||
|
||||
@@ -57,6 +55,7 @@ import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -113,8 +112,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public Optional<MessagingService> getMessagingService() {
|
||||
InternalMessagingService service = plugin.getMessagingService();
|
||||
return service instanceof NoopMessagingService ? Optional.empty() : Optional.of(service);
|
||||
return plugin.getMessagingService().map(Function.identity());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ public class UpdateTaskBuffer extends BufferedRequest<Void> {
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
public UpdateTaskBuffer(LuckPermsPlugin plugin) {
|
||||
super(250L, 50L, plugin::doAsync);
|
||||
super(250L, 50L, plugin.getScheduler().async());
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -36,8 +36,7 @@ import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.constants.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.LocalizedSpec;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.NoopMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.common.model.Group;
|
||||
import me.lucko.luckperms.common.model.Track;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
@@ -50,6 +49,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -182,9 +182,9 @@ public abstract class SubCommand<T> extends Command<T, Void> {
|
||||
}
|
||||
|
||||
if (!sender.isImport()) {
|
||||
InternalMessagingService messagingService = plugin.getMessagingService();
|
||||
if (!(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.getUpdateBuffer().request();
|
||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.get().getUpdateBuffer().request();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,9 +203,9 @@ public abstract class SubCommand<T> extends Command<T, Void> {
|
||||
}
|
||||
|
||||
if (!sender.isImport()) {
|
||||
InternalMessagingService messagingService = plugin.getMessagingService();
|
||||
if (!(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.getUpdateBuffer().request();
|
||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.get().getUpdateBuffer().request();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,9 +224,9 @@ public abstract class SubCommand<T> extends Command<T, Void> {
|
||||
}
|
||||
|
||||
if (!sender.isImport()) {
|
||||
InternalMessagingService messagingService = plugin.getMessagingService();
|
||||
if (!(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.getUpdateBuffer().request();
|
||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) {
|
||||
messagingService.get().getUpdateBuffer().request();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ public class MetaAddChatMeta extends SharedSubCommand {
|
||||
super(
|
||||
type == ChatMetaType.PREFIX ? CommandSpec.META_ADDPREFIX.spec(locale) : CommandSpec.META_ADDSUFFIX.spec(locale),
|
||||
"add" + type.name().toLowerCase(),
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_ADDPREFIX : CommandPermission.USER_META_ADDSUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_ADDPREFIX : CommandPermission.GROUP_META_ADDSUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_ADD_PREFIX : CommandPermission.USER_META_ADD_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_ADD_PREFIX : CommandPermission.GROUP_META_ADD_SUFFIX,
|
||||
Predicates.inRange(0, 1)
|
||||
);
|
||||
this.type = type;
|
||||
|
||||
+2
-2
@@ -65,8 +65,8 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
|
||||
super(
|
||||
type == ChatMetaType.PREFIX ? CommandSpec.META_ADDTEMP_PREFIX.spec(locale) : CommandSpec.META_ADDTEMP_SUFFIX.spec(locale),
|
||||
"addtemp" + type.name().toLowerCase(),
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_ADDTEMP_PREFIX : CommandPermission.USER_META_ADDTEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_ADDTEMP_PREFIX : CommandPermission.GROUP_META_ADDTEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_ADD_TEMP_PREFIX : CommandPermission.USER_META_ADD_TEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_ADD_TEMP_PREFIX : CommandPermission.GROUP_META_ADD_TEMP_SUFFIX,
|
||||
Predicates.inRange(0, 2)
|
||||
);
|
||||
this.type = type;
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
|
||||
super(
|
||||
type == ChatMetaType.PREFIX ? CommandSpec.META_REMOVEPREFIX.spec(locale) : CommandSpec.META_REMOVESUFFIX.spec(locale),
|
||||
"remove" + type.name().toLowerCase(),
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_REMOVEPREFIX : CommandPermission.USER_META_REMOVESUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_REMOVEPREFIX : CommandPermission.GROUP_META_REMOVESUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_REMOVE_PREFIX : CommandPermission.USER_META_REMOVE_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_REMOVE_PREFIX : CommandPermission.GROUP_META_REMOVE_SUFFIX,
|
||||
Predicates.is(0)
|
||||
);
|
||||
this.type = type;
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
|
||||
super(
|
||||
type == ChatMetaType.PREFIX ? CommandSpec.META_REMOVETEMP_PREFIX.spec(locale) : CommandSpec.META_REMOVETEMP_SUFFIX.spec(locale),
|
||||
"removetemp" + type.name().toLowerCase(),
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_REMOVETEMP_PREFIX : CommandPermission.USER_META_REMOVETEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_REMOVETEMP_PREFIX : CommandPermission.GROUP_META_REMOVETEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.USER_META_REMOVE_TEMP_PREFIX : CommandPermission.USER_META_REMOVE_TEMP_SUFFIX,
|
||||
type == ChatMetaType.PREFIX ? CommandPermission.GROUP_META_REMOVE_TEMP_PREFIX : CommandPermission.GROUP_META_REMOVE_TEMP_SUFFIX,
|
||||
Predicates.is(0)
|
||||
);
|
||||
this.type = type;
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class MetaSetTemp extends SharedSubCommand {
|
||||
public MetaSetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.META_SETTEMP.spec(locale), "settemp", CommandPermission.USER_META_SETTEMP, CommandPermission.GROUP_META_SETTEMP, Predicates.inRange(0, 2));
|
||||
super(CommandSpec.META_SETTEMP.spec(locale), "settemp", CommandPermission.USER_META_SET_TEMP, CommandPermission.GROUP_META_SET_TEMP, Predicates.inRange(0, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class MetaUnsetTemp extends SharedSubCommand {
|
||||
public MetaUnsetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.META_UNSETTEMP.spec(locale), "unsettemp", CommandPermission.USER_META_UNSETTEMP, CommandPermission.GROUP_META_UNSETTEMP, Predicates.is(0));
|
||||
super(CommandSpec.META_UNSETTEMP.spec(locale), "unsettemp", CommandPermission.USER_META_UNSET_TEMP, CommandPermission.GROUP_META_UNSET_TEMP, Predicates.is(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T> {
|
||||
public HolderShowTracks(LocaleManager locale, boolean user) {
|
||||
super(CommandSpec.HOLDER_SHOWTRACKS.spec(locale), "showtracks", user ? CommandPermission.USER_SHOWTRACKS : CommandPermission.GROUP_SHOWTRACKS, Predicates.alwaysFalse());
|
||||
super(CommandSpec.HOLDER_SHOWTRACKS.spec(locale), "showtracks", user ? CommandPermission.USER_SHOW_TRACKS : CommandPermission.GROUP_SHOW_TRACKS, Predicates.alwaysFalse());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getGroup
|
||||
|
||||
public class ParentAddTemp extends SharedSubCommand {
|
||||
public ParentAddTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_ADD_TEMP.spec(locale), "addtemp", CommandPermission.USER_PARENT_ADDTEMP, CommandPermission.GROUP_PARENT_ADDTEMP, Predicates.inRange(0, 1));
|
||||
super(CommandSpec.PARENT_ADD_TEMP.spec(locale), "addtemp", CommandPermission.USER_PARENT_ADD_TEMP, CommandPermission.GROUP_PARENT_ADD_TEMP, Predicates.inRange(0, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getGroup
|
||||
|
||||
public class ParentRemoveTemp extends SharedSubCommand {
|
||||
public ParentRemoveTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PARENT_REMOVE_TEMP.spec(locale), "removetemp", CommandPermission.USER_PARENT_REMOVETEMP, CommandPermission.GROUP_PARENT_REMOVETEMP, Predicates.is(0));
|
||||
super(CommandSpec.PARENT_REMOVE_TEMP.spec(locale), "removetemp", CommandPermission.USER_PARENT_REMOVE_TEMP, CommandPermission.GROUP_PARENT_REMOVE_TEMP, Predicates.is(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getPermi
|
||||
|
||||
public class PermissionSetTemp extends SharedSubCommand {
|
||||
public PermissionSetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_SETTEMP.spec(locale), "settemp", CommandPermission.USER_PERM_SETTEMP, CommandPermission.GROUP_PERM_SETTEMP, Predicates.inRange(0, 2));
|
||||
super(CommandSpec.PERMISSION_SETTEMP.spec(locale), "settemp", CommandPermission.USER_PERM_SET_TEMP, CommandPermission.GROUP_PERM_SET_TEMP, Predicates.inRange(0, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ import static me.lucko.luckperms.common.commands.abstraction.SubCommand.getPermi
|
||||
|
||||
public class PermissionUnsetTemp extends SharedSubCommand {
|
||||
public PermissionUnsetTemp(LocaleManager locale) {
|
||||
super(CommandSpec.PERMISSION_UNSETTEMP.spec(locale), "unsettemp", CommandPermission.USER_PERM_UNSETTEMP, CommandPermission.GROUP_PERM_UNSETTEMP, Predicates.is(0));
|
||||
super(CommandSpec.PERMISSION_UNSETTEMP.spec(locale), "unsettemp", CommandPermission.USER_PERM_UNSET_TEMP, CommandPermission.GROUP_PERM_UNSET_TEMP, Predicates.is(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class GroupListMembers extends SubCommand<Group> {
|
||||
public GroupListMembers(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_LISTMEMBERS.spec(locale), "listmembers", CommandPermission.GROUP_LISTMEMBERS, Predicates.notInRange(0, 1));
|
||||
super(CommandSpec.GROUP_LISTMEMBERS.spec(locale), "listmembers", CommandPermission.GROUP_LIST_MEMBERS, Predicates.notInRange(0, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ import java.util.List;
|
||||
|
||||
public class GroupSetWeight extends SubCommand<Group> {
|
||||
public GroupSetWeight(LocaleManager locale) {
|
||||
super(CommandSpec.GROUP_SETWEIGHT.spec(locale), "setweight", CommandPermission.GROUP_SETWEIGHT, Predicates.not(1));
|
||||
super(CommandSpec.GROUP_SETWEIGHT.spec(locale), "setweight", CommandPermission.GROUP_SET_WEIGHT, Predicates.not(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,11 +76,11 @@ public class CheckCommand extends SingleCommand {
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
return plugin.getPlayerList();
|
||||
return plugin.getPlayerList().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
return plugin.getPlayerList().stream().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
return plugin.getPlayerList().filter(s -> s.toLowerCase().startsWith(args.get(0).toLowerCase())).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
args.remove(0);
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ public class ExportCommand extends SingleCommand {
|
||||
Exporter exporter = new Exporter(plugin, sender, path);
|
||||
|
||||
// Run the exporter in its own thread.
|
||||
plugin.doAsync(() -> {
|
||||
plugin.getScheduler().doAsync(() -> {
|
||||
try {
|
||||
exporter.run();
|
||||
} finally {
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ public class ImportCommand extends SingleCommand {
|
||||
Importer importer = new Importer(plugin.getCommandManager(), sender, commands);
|
||||
|
||||
// Run the importer in its own thread.
|
||||
plugin.doAsync(() -> {
|
||||
plugin.getScheduler().doAsync(() -> {
|
||||
try {
|
||||
importer.run();
|
||||
} finally {
|
||||
|
||||
@@ -35,7 +35,7 @@ import me.lucko.luckperms.common.constants.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.messaging.NoopMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.DateUtil;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
@@ -69,7 +69,7 @@ public class InfoCommand extends SingleCommand {
|
||||
}
|
||||
|
||||
Message.INFO_MIDDLE.send(sender,
|
||||
plugin.getMessagingService() instanceof NoopMessagingService ? "None" : plugin.getMessagingService().getName(),
|
||||
plugin.getMessagingService().map(ExtendedMessagingService::getName).orElse("None"),
|
||||
c.get(ConfigKeys.SERVER),
|
||||
plugin.getPlayerCount(),
|
||||
plugin.getUniqueConnections().size(),
|
||||
|
||||
+6
-7
@@ -32,12 +32,12 @@ import me.lucko.luckperms.common.constants.CommandPermission;
|
||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.NoopMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class NetworkSyncCommand extends SingleCommand {
|
||||
public NetworkSyncCommand(LocaleManager locale) {
|
||||
@@ -50,16 +50,15 @@ public class NetworkSyncCommand extends SingleCommand {
|
||||
plugin.getUpdateTaskBuffer().request().join();
|
||||
Message.UPDATE_TASK_COMPLETE_NETWORK.send(sender);
|
||||
|
||||
InternalMessagingService messagingService = plugin.getMessagingService();
|
||||
|
||||
if (messagingService instanceof NoopMessagingService) {
|
||||
Optional<ExtendedMessagingService> messagingService = plugin.getMessagingService();
|
||||
if (!messagingService.isPresent()) {
|
||||
Message.UPDATE_TASK_PUSH_FAILURE_NOT_SETUP.send(sender);
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
messagingService.pushUpdate();
|
||||
Message.UPDATE_TASK_PUSH_SUCCESS.send(sender, messagingService.getName());
|
||||
messagingService.get().pushUpdate();
|
||||
Message.UPDATE_TASK_PUSH_SUCCESS.send(sender, messagingService.get().getName());
|
||||
return CommandResult.SUCCESS;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
+2
-1
@@ -52,6 +52,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserMainCommand extends MainCommand<User, UserIdentifier> {
|
||||
|
||||
@@ -143,6 +144,6 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
|
||||
|
||||
@Override
|
||||
protected List<String> getTargets(LuckPermsPlugin plugin) {
|
||||
return plugin.getPlayerList();
|
||||
return plugin.getPlayerList().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,17 @@
|
||||
|
||||
package me.lucko.luckperms.common.config;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.CacheLoader;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
|
||||
import me.lucko.luckperms.common.api.delegates.LPConfigurationDelegate;
|
||||
import me.lucko.luckperms.common.config.keys.EnduringKey;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -40,16 +44,22 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* An abstract implementation of {@link LuckPermsConfiguration}, backed by a cache.
|
||||
*/
|
||||
public abstract class AbstractConfiguration implements LuckPermsConfiguration {
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class AbstractConfiguration implements LuckPermsConfiguration, CacheLoader<ConfigKey<?>, Optional<Object>> {
|
||||
|
||||
// the loading cache for config keys --> their value
|
||||
// the value is wrapped in an optional as null values don't get cached.
|
||||
private final LoadingCache<ConfigKey<?>, Optional<Object>> cache = Caffeine.newBuilder().build(this::loadKeyValue);
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final LoadingCache<ConfigKey<?>, Optional<Object>> cache = Caffeine.newBuilder().build(this);
|
||||
|
||||
@Getter
|
||||
// the plugin instance
|
||||
private final LuckPermsPlugin plugin;
|
||||
// the adapter used to read values
|
||||
private final ConfigurationAdapter adapter;
|
||||
// the api delegate
|
||||
private final LPConfigurationDelegate delegate = new LPConfigurationDelegate(this);
|
||||
|
||||
@Getter
|
||||
// the contextsfile handler
|
||||
private final ContextsFile contextsFile = new ContextsFile(this);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -68,6 +78,12 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration {
|
||||
contextsFile.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
adapter.init();
|
||||
loadAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
init();
|
||||
@@ -79,7 +95,8 @@ public abstract class AbstractConfiguration implements LuckPermsConfiguration {
|
||||
getPlugin().getApiProvider().getEventFactory().handleConfigReload();
|
||||
}
|
||||
|
||||
private Optional<Object> loadKeyValue(ConfigKey<?> key) {
|
||||
return Optional.ofNullable(key.get(this));
|
||||
@Override
|
||||
public Optional<Object> load(ConfigKey<?> key) {
|
||||
return Optional.ofNullable(key.get(adapter));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ public interface ConfigKey<T> {
|
||||
* <p>The {@link LuckPermsConfiguration#get(ConfigKey)} method should be used to
|
||||
* retrieve the value, as opposed to calling this directly.</p>
|
||||
*
|
||||
* @param config the config instance
|
||||
* @param adapter the config adapter instance
|
||||
* @return the value mapped to this key
|
||||
*/
|
||||
T get(LuckPermsConfiguration config);
|
||||
T get(ConfigurationAdapter adapter);
|
||||
|
||||
}
|
||||
|
||||
+17
-21
@@ -23,35 +23,31 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.common.messaging;
|
||||
package me.lucko.luckperms.common.config;
|
||||
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.common.buffers.BufferedRequest;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
public class NoopMessagingService implements InternalMessagingService {
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "No op";
|
||||
}
|
||||
public interface ConfigurationAdapter {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
LuckPermsPlugin getPlugin();
|
||||
|
||||
}
|
||||
void init();
|
||||
|
||||
@Override
|
||||
public BufferedRequest<Void> getUpdateBuffer() {
|
||||
return null;
|
||||
}
|
||||
boolean contains(String path);
|
||||
|
||||
@Override
|
||||
public void pushLog(LogEntry logEntry) {
|
||||
String getString(String path, String def);
|
||||
|
||||
}
|
||||
int getInt(String path, int def);
|
||||
|
||||
@Override
|
||||
public void pushUpdate() {
|
||||
boolean getBoolean(String path, boolean def);
|
||||
|
||||
List<String> getList(String path, List<String> def);
|
||||
|
||||
List<String> getObjectList(String path, List<String> def);
|
||||
|
||||
Map<String, String> getMap(String path, Map<String, String> def);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,6 @@ package me.lucko.luckperms.common.config;
|
||||
import me.lucko.luckperms.common.api.delegates.LPConfigurationDelegate;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The master configuration used by LuckPerms.
|
||||
*/
|
||||
@@ -81,22 +78,4 @@ public interface LuckPermsConfiguration {
|
||||
*/
|
||||
<T> T get(ConfigKey<T> key);
|
||||
|
||||
|
||||
|
||||
/* methods used by config keys to load their values */
|
||||
|
||||
boolean contains(String path);
|
||||
|
||||
String getString(String path, String def);
|
||||
|
||||
int getInt(String path, int def);
|
||||
|
||||
boolean getBoolean(String path, boolean def);
|
||||
|
||||
List<String> getList(String path, List<String> def);
|
||||
|
||||
List<String> getObjectList(String path, List<String> def);
|
||||
|
||||
Map<String, String> getMap(String path, Map<String, String> def);
|
||||
|
||||
}
|
||||
|
||||
@@ -28,16 +28,16 @@ package me.lucko.luckperms.common.config.keys;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class AbstractKey<T> implements ConfigKey<T> {
|
||||
private final Function<LuckPermsConfiguration, T> function;
|
||||
private final Function<ConfigurationAdapter, T> function;
|
||||
|
||||
@Override
|
||||
public T get(LuckPermsConfiguration config) {
|
||||
return function.apply(config);
|
||||
public T get(ConfigurationAdapter adapter) {
|
||||
return function.apply(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class BooleanKey implements ConfigKey<Boolean> {
|
||||
@@ -36,7 +36,7 @@ public class BooleanKey implements ConfigKey<Boolean> {
|
||||
private final boolean def;
|
||||
|
||||
@Override
|
||||
public Boolean get(LuckPermsConfiguration config) {
|
||||
return config.getBoolean(path, def);
|
||||
public Boolean get(ConfigurationAdapter adapter) {
|
||||
return adapter.getBoolean(path, def);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class IntegerKey implements ConfigKey<Integer> {
|
||||
@@ -36,7 +36,7 @@ public class IntegerKey implements ConfigKey<Integer> {
|
||||
private final int def;
|
||||
|
||||
@Override
|
||||
public Integer get(LuckPermsConfiguration config) {
|
||||
return config.getInt(path, def);
|
||||
public Integer get(ConfigurationAdapter adapter) {
|
||||
return adapter.getInt(path, def);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class LowercaseStringKey implements ConfigKey<String> {
|
||||
@@ -36,7 +36,7 @@ public class LowercaseStringKey implements ConfigKey<String> {
|
||||
private final String def;
|
||||
|
||||
@Override
|
||||
public String get(LuckPermsConfiguration config) {
|
||||
return config.getString(path, def).toLowerCase();
|
||||
public String get(ConfigurationAdapter adapter) {
|
||||
return adapter.getString(path, def).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import lombok.AllArgsConstructor;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class MapKey implements ConfigKey<Map<String, String>> {
|
||||
private final String path;
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(LuckPermsConfiguration config) {
|
||||
return ImmutableMap.copyOf(config.getMap(path, ImmutableMap.of()));
|
||||
public Map<String, String> get(ConfigurationAdapter adapter) {
|
||||
return ImmutableMap.copyOf(adapter.getMap(path, ImmutableMap.of()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ package me.lucko.luckperms.common.config.keys;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class StaticKey<T> implements ConfigKey<T> {
|
||||
private final T val;
|
||||
|
||||
@Override
|
||||
public T get(LuckPermsConfiguration config) {
|
||||
public T get(ConfigurationAdapter adapter) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ package me.lucko.luckperms.common.config.keys;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.ConfigKey;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class StringKey implements ConfigKey<String> {
|
||||
@@ -36,7 +36,7 @@ public class StringKey implements ConfigKey<String> {
|
||||
private final String def;
|
||||
|
||||
@Override
|
||||
public String get(LuckPermsConfiguration config) {
|
||||
return config.getString(path, def);
|
||||
public String get(ConfigurationAdapter adapter) {
|
||||
return adapter.getString(path, def);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ public enum CommandPermission {
|
||||
USER_PERM_INFO("permission.info", USER),
|
||||
USER_PERM_SET("permission.set", USER),
|
||||
USER_PERM_UNSET("permission.unset", USER),
|
||||
USER_PERM_SETTEMP("permission.settemp", USER),
|
||||
USER_PERM_UNSETTEMP("permission.unsettemp", USER),
|
||||
USER_PERM_SET_TEMP("permission.settemp", USER),
|
||||
USER_PERM_UNSET_TEMP("permission.unsettemp", USER),
|
||||
USER_PERM_CHECK("permission.check", USER),
|
||||
USER_PERM_CHECK_INHERITS("permission.checkinherits", USER),
|
||||
USER_PARENT_INFO("parent.info", USER),
|
||||
@@ -76,27 +76,27 @@ public enum CommandPermission {
|
||||
USER_PARENT_SET_TRACK("parent.settrack", USER),
|
||||
USER_PARENT_ADD("parent.add", USER),
|
||||
USER_PARENT_REMOVE("parent.remove", USER),
|
||||
USER_PARENT_ADDTEMP("parent.addtemp", USER),
|
||||
USER_PARENT_REMOVETEMP("parent.removetemp", USER),
|
||||
USER_PARENT_ADD_TEMP("parent.addtemp", USER),
|
||||
USER_PARENT_REMOVE_TEMP("parent.removetemp", USER),
|
||||
USER_PARENT_CLEAR("parent.clear", USER),
|
||||
USER_PARENT_CLEAR_TRACK("parent.cleartrack", USER),
|
||||
USER_META_INFO("meta.info", USER),
|
||||
USER_META_SET("meta.set", USER),
|
||||
USER_META_UNSET("meta.unset", USER),
|
||||
USER_META_SETTEMP("meta.settemp", USER),
|
||||
USER_META_UNSETTEMP("meta.unsettemp", USER),
|
||||
USER_META_ADDPREFIX("meta.addprefix", USER),
|
||||
USER_META_ADDSUFFIX("meta.addsuffix", USER),
|
||||
USER_META_REMOVEPREFIX("meta.removeprefix", USER),
|
||||
USER_META_REMOVESUFFIX("meta.removesuffix", USER),
|
||||
USER_META_ADDTEMP_PREFIX("meta.addtempprefix", USER),
|
||||
USER_META_ADDTEMP_SUFFIX("meta.addtempsuffix", USER),
|
||||
USER_META_REMOVETEMP_PREFIX("meta.removetempprefix", USER),
|
||||
USER_META_REMOVETEMP_SUFFIX("meta.removetempsuffix", USER),
|
||||
USER_META_SET_TEMP("meta.settemp", USER),
|
||||
USER_META_UNSET_TEMP("meta.unsettemp", USER),
|
||||
USER_META_ADD_PREFIX("meta.addprefix", USER),
|
||||
USER_META_ADD_SUFFIX("meta.addsuffix", USER),
|
||||
USER_META_REMOVE_PREFIX("meta.removeprefix", USER),
|
||||
USER_META_REMOVE_SUFFIX("meta.removesuffix", USER),
|
||||
USER_META_ADD_TEMP_PREFIX("meta.addtempprefix", USER),
|
||||
USER_META_ADD_TEMP_SUFFIX("meta.addtempsuffix", USER),
|
||||
USER_META_REMOVE_TEMP_PREFIX("meta.removetempprefix", USER),
|
||||
USER_META_REMOVE_TEMP_SUFFIX("meta.removetempsuffix", USER),
|
||||
USER_META_CLEAR("meta.clear", USER),
|
||||
USER_EDITOR("editor", USER),
|
||||
USER_SWITCHPRIMARYGROUP("switchprimarygroup", USER),
|
||||
USER_SHOWTRACKS("showtracks", USER),
|
||||
USER_SHOW_TRACKS("showtracks", USER),
|
||||
USER_PROMOTE("promote", USER),
|
||||
USER_DEMOTE("demote", USER),
|
||||
USER_CLEAR("clear", USER),
|
||||
@@ -105,8 +105,8 @@ public enum CommandPermission {
|
||||
GROUP_PERM_INFO("permission.info", GROUP),
|
||||
GROUP_PERM_SET("permission.set", GROUP),
|
||||
GROUP_PERM_UNSET("permission.unset", GROUP),
|
||||
GROUP_PERM_SETTEMP("permission.settemp", GROUP),
|
||||
GROUP_PERM_UNSETTEMP("permission.unsettemp", GROUP),
|
||||
GROUP_PERM_SET_TEMP("permission.settemp", GROUP),
|
||||
GROUP_PERM_UNSET_TEMP("permission.unsettemp", GROUP),
|
||||
GROUP_PERM_CHECK("permission.check", GROUP),
|
||||
GROUP_PERM_CHECK_INHERITS("permission.checkinherits", GROUP),
|
||||
GROUP_PARENT_INFO("parent.info", GROUP),
|
||||
@@ -114,28 +114,28 @@ public enum CommandPermission {
|
||||
GROUP_PARENT_SET_TRACK("parent.settrack", GROUP),
|
||||
GROUP_PARENT_ADD("parent.add", GROUP),
|
||||
GROUP_PARENT_REMOVE("parent.remove", GROUP),
|
||||
GROUP_PARENT_ADDTEMP("parent.addtemp", GROUP),
|
||||
GROUP_PARENT_REMOVETEMP("parent.removetemp", GROUP),
|
||||
GROUP_PARENT_ADD_TEMP("parent.addtemp", GROUP),
|
||||
GROUP_PARENT_REMOVE_TEMP("parent.removetemp", GROUP),
|
||||
GROUP_PARENT_CLEAR("parent.clear", GROUP),
|
||||
GROUP_PARENT_CLEAR_TRACK("parent.cleartrack", GROUP),
|
||||
GROUP_META_INFO("meta.info", GROUP),
|
||||
GROUP_META_SET("meta.set", GROUP),
|
||||
GROUP_META_UNSET("meta.unset", GROUP),
|
||||
GROUP_META_SETTEMP("meta.settemp", GROUP),
|
||||
GROUP_META_UNSETTEMP("meta.unsettemp", GROUP),
|
||||
GROUP_META_ADDPREFIX("meta.addprefix", GROUP),
|
||||
GROUP_META_ADDSUFFIX("meta.addsuffix", GROUP),
|
||||
GROUP_META_REMOVEPREFIX("meta.removeprefix", GROUP),
|
||||
GROUP_META_REMOVESUFFIX("meta.removesuffix", GROUP),
|
||||
GROUP_META_ADDTEMP_PREFIX("meta.addtempprefix", GROUP),
|
||||
GROUP_META_ADDTEMP_SUFFIX("meta.addtempsuffix", GROUP),
|
||||
GROUP_META_REMOVETEMP_PREFIX("meta.removetempprefix", GROUP),
|
||||
GROUP_META_REMOVETEMP_SUFFIX("meta.removetempsuffix", GROUP),
|
||||
GROUP_META_SET_TEMP("meta.settemp", GROUP),
|
||||
GROUP_META_UNSET_TEMP("meta.unsettemp", GROUP),
|
||||
GROUP_META_ADD_PREFIX("meta.addprefix", GROUP),
|
||||
GROUP_META_ADD_SUFFIX("meta.addsuffix", GROUP),
|
||||
GROUP_META_REMOVE_PREFIX("meta.removeprefix", GROUP),
|
||||
GROUP_META_REMOVE_SUFFIX("meta.removesuffix", GROUP),
|
||||
GROUP_META_ADD_TEMP_PREFIX("meta.addtempprefix", GROUP),
|
||||
GROUP_META_ADD_TEMP_SUFFIX("meta.addtempsuffix", GROUP),
|
||||
GROUP_META_REMOVE_TEMP_PREFIX("meta.removetempprefix", GROUP),
|
||||
GROUP_META_REMOVE_TEMP_SUFFIX("meta.removetempsuffix", GROUP),
|
||||
GROUP_META_CLEAR("meta.clear", GROUP),
|
||||
GROUP_EDITOR("editor", GROUP),
|
||||
GROUP_LISTMEMBERS("listmembers", GROUP),
|
||||
GROUP_SHOWTRACKS("showtracks", GROUP),
|
||||
GROUP_SETWEIGHT("setweight", GROUP),
|
||||
GROUP_LIST_MEMBERS("listmembers", GROUP),
|
||||
GROUP_SHOW_TRACKS("showtracks", GROUP),
|
||||
GROUP_SET_WEIGHT("setweight", GROUP),
|
||||
GROUP_SET_DISPLAY_NAME("setdisplayname", GROUP),
|
||||
GROUP_CLEAR("clear", GROUP),
|
||||
GROUP_RENAME("rename", GROUP),
|
||||
|
||||
@@ -107,6 +107,6 @@ public class LuckPermsEventBus implements EventBus {
|
||||
if (event instanceof Cancellable) {
|
||||
throw new IllegalArgumentException("cannot call Cancellable event async");
|
||||
}
|
||||
plugin.doAsync(() -> fireEvent(event));
|
||||
plugin.getScheduler().doAsync(() -> fireEvent(event));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,12 +113,10 @@ public class GenericUserManager extends AbstractManager<UserIdentifier, User> im
|
||||
@Override
|
||||
public CompletableFuture<Void> updateAllUsers() {
|
||||
return CompletableFuture.supplyAsync(plugin::getOnlinePlayers, plugin.getScheduler().sync())
|
||||
.thenAcceptAsync(players -> {
|
||||
for (UUID uuid : players) {
|
||||
UUID internal = plugin.getUuidCache().getUUID(uuid);
|
||||
plugin.getStorage().loadUser(internal, "null").join();
|
||||
}
|
||||
}, plugin.getScheduler().async());
|
||||
.thenAcceptAsync(players -> players.forEach(uuid -> {
|
||||
UUID internal = plugin.getUuidCache().getUUID(uuid);
|
||||
plugin.getStorage().loadUser(internal, "null").join();
|
||||
}), plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
public static boolean giveDefaultIfNeeded(User user, boolean save, LuckPermsPlugin plugin) {
|
||||
|
||||
+8
-12
@@ -46,7 +46,7 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* An abstract implementation of {@link me.lucko.luckperms.api.MessagingService}.
|
||||
*/
|
||||
public abstract class AbstractMessagingService implements InternalMessagingService {
|
||||
public abstract class AbstractMessagingService implements ExtendedMessagingService {
|
||||
protected static final String CHANNEL = "lpuc";
|
||||
|
||||
@Getter
|
||||
@@ -69,13 +69,9 @@ public abstract class AbstractMessagingService implements InternalMessagingServi
|
||||
this.updateBuffer = new PushUpdateBuffer(plugin);
|
||||
}
|
||||
|
||||
protected abstract void sendMessage(String channel, String message);
|
||||
|
||||
protected void onMessage(String channel, String msg, Consumer<String> callback) {
|
||||
if (!channel.equals(CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
protected abstract void sendMessage(String message);
|
||||
|
||||
protected void onMessage(String msg, Consumer<String> callback) {
|
||||
if (msg.startsWith("update:") && msg.length() > "update:".length()) {
|
||||
UUID uuid = parseUpdateMessage(msg);
|
||||
if (uuid == null) {
|
||||
@@ -127,7 +123,7 @@ public abstract class AbstractMessagingService implements InternalMessagingServi
|
||||
|
||||
@Override
|
||||
public void pushLog(LogEntry logEntry) {
|
||||
plugin.doAsync(() -> {
|
||||
plugin.getScheduler().doAsync(() -> {
|
||||
UUID id = generatePingId();
|
||||
|
||||
if (plugin.getApiProvider().getEventFactory().handleLogNetworkPublish(!plugin.getConfiguration().get(ConfigKeys.PUSH_LOG_ENTRIES), id, logEntry)) {
|
||||
@@ -135,17 +131,17 @@ public abstract class AbstractMessagingService implements InternalMessagingServi
|
||||
}
|
||||
|
||||
plugin.getLog().info("[" + name + " Messaging] Sending log with id: " + id.toString());
|
||||
sendMessage(CHANNEL, "log:" + gson.toJson(ExtendedLogEntry.serializeWithId(id, logEntry)));
|
||||
sendMessage("log:" + gson.toJson(ExtendedLogEntry.serializeWithId(id, logEntry)));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushUpdate() {
|
||||
plugin.doAsync(() -> {
|
||||
plugin.getScheduler().doAsync(() -> {
|
||||
UUID id = generatePingId();
|
||||
plugin.getLog().info("[" + name + " Messaging] Sending ping with id: " + id.toString());
|
||||
|
||||
sendMessage(CHANNEL, "update:" + id.toString());
|
||||
sendMessage("update:" + id.toString());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -166,7 +162,7 @@ public abstract class AbstractMessagingService implements InternalMessagingServi
|
||||
|
||||
private final class PushUpdateBuffer extends BufferedRequest<Void> {
|
||||
public PushUpdateBuffer(LuckPermsPlugin plugin) {
|
||||
super(3000L, 200L, plugin::doAsync);
|
||||
super(3000L, 200L, plugin.getScheduler().async());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import me.lucko.luckperms.api.LogEntry;
|
||||
import me.lucko.luckperms.api.MessagingService;
|
||||
import me.lucko.luckperms.common.buffers.BufferedRequest;
|
||||
|
||||
public interface InternalMessagingService extends MessagingService {
|
||||
public interface ExtendedMessagingService extends MessagingService {
|
||||
|
||||
/**
|
||||
* Gets the name of this messaging service
|
||||
@@ -38,28 +38,28 @@ public class MessagingFactory<P extends LuckPermsPlugin> {
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final P plugin;
|
||||
|
||||
public final InternalMessagingService getInstance() {
|
||||
public final ExtendedMessagingService getInstance() {
|
||||
String messagingType = plugin.getConfiguration().get(ConfigKeys.MESSAGING_SERVICE).toLowerCase();
|
||||
if (messagingType.equals("none") && plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
messagingType = "redis";
|
||||
}
|
||||
|
||||
if (messagingType.equals("none")) {
|
||||
return new NoopMessagingService();
|
||||
return null;
|
||||
}
|
||||
|
||||
plugin.getLog().info("Loading messaging service... [" + messagingType.toUpperCase() + "]");
|
||||
|
||||
InternalMessagingService service = getServiceFor(messagingType);
|
||||
ExtendedMessagingService service = getServiceFor(messagingType);
|
||||
if (service != null) {
|
||||
return service;
|
||||
}
|
||||
|
||||
plugin.getLog().warn("Messaging service '" + messagingType + "' not recognised.");
|
||||
return new NoopMessagingService();
|
||||
return null;
|
||||
}
|
||||
|
||||
protected InternalMessagingService getServiceFor(String messagingType) {
|
||||
protected ExtendedMessagingService getServiceFor(String messagingType) {
|
||||
if (messagingType.equals("redis")) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
RedisMessagingService redis = new RedisMessagingService(plugin);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class RedisMessagingService extends AbstractMessagingService {
|
||||
jedisPool = new JedisPool(new JedisPoolConfig(), host, port, 0, password);
|
||||
}
|
||||
|
||||
plugin.doAsync(() -> {
|
||||
plugin.getScheduler().doAsync(() -> {
|
||||
sub = new LPSub(this);
|
||||
try (Jedis jedis = jedisPool.getResource()) {
|
||||
jedis.subscribe(sub, CHANNEL);
|
||||
@@ -75,7 +75,7 @@ public class RedisMessagingService extends AbstractMessagingService {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(String channel, String message) {
|
||||
protected void sendMessage(String message) {
|
||||
try (Jedis jedis = jedisPool.getResource()) {
|
||||
jedis.publish(CHANNEL, message);
|
||||
} catch (Exception e) {
|
||||
@@ -89,7 +89,10 @@ public class RedisMessagingService extends AbstractMessagingService {
|
||||
|
||||
@Override
|
||||
public void onMessage(String channel, String msg) {
|
||||
parent.onMessage(channel, msg, null);
|
||||
if (!channel.equals(CHANNEL)) {
|
||||
return;
|
||||
}
|
||||
parent.onMessage(msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,10 +68,10 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
|
||||
* The users data cache instance, if present.
|
||||
*/
|
||||
@Getter
|
||||
private final UserCache userData = new UserCache(this);
|
||||
private final UserCache userData;
|
||||
|
||||
@Getter
|
||||
private BufferedRequest<Void> refreshBuffer = new UserRefreshBuffer(this);
|
||||
private BufferedRequest<Void> refreshBuffer;
|
||||
|
||||
@Getter
|
||||
private final UserDelegate delegate = new UserDelegate(this);
|
||||
@@ -80,16 +80,22 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
|
||||
super(uuid.toString(), plugin);
|
||||
this.uuid = uuid;
|
||||
|
||||
this.refreshBuffer = new UserRefreshBuffer(plugin, this);
|
||||
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
|
||||
|
||||
this.userData = new UserCache(this);
|
||||
getPlugin().getApiProvider().getEventFactory().handleUserCacheLoad(this, userData);
|
||||
}
|
||||
|
||||
public User(UUID uuid, String name, LuckPermsPlugin plugin) {
|
||||
super(uuid.toString(), plugin);
|
||||
this.uuid = uuid;
|
||||
|
||||
setName(name, false);
|
||||
|
||||
this.refreshBuffer = new UserRefreshBuffer(plugin, this);
|
||||
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
|
||||
|
||||
this.userData = new UserCache(this);
|
||||
getPlugin().getApiProvider().getEventFactory().handleUserCacheLoad(this, userData);
|
||||
}
|
||||
|
||||
@@ -207,8 +213,8 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
|
||||
private static final class UserRefreshBuffer extends BufferedRequest<Void> {
|
||||
private final User user;
|
||||
|
||||
private UserRefreshBuffer(User user) {
|
||||
super(250L, 50L, r -> user.getPlugin().doAsync(r));
|
||||
private UserRefreshBuffer(LuckPermsPlugin plugin, User user) {
|
||||
super(250L, 50L, plugin.getScheduler().async());
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.managers.GroupManager;
|
||||
import me.lucko.luckperms.common.managers.TrackManager;
|
||||
import me.lucko.luckperms.common.managers.UserManager;
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
import me.lucko.luckperms.common.storage.dao.file.FileWatcher;
|
||||
@@ -60,7 +60,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Main internal interface for LuckPerms plugins, providing the base for abstraction throughout the project.
|
||||
@@ -109,7 +109,7 @@ public interface LuckPermsPlugin {
|
||||
*
|
||||
* @return the redis messaging service
|
||||
*/
|
||||
InternalMessagingService getMessagingService();
|
||||
Optional<ExtendedMessagingService> getMessagingService();
|
||||
|
||||
/**
|
||||
* Gets a wrapped logger instance for the platform.
|
||||
@@ -194,15 +194,14 @@ public interface LuckPermsPlugin {
|
||||
*
|
||||
* @return the scheduler
|
||||
*/
|
||||
LuckPermsScheduler getScheduler();
|
||||
SchedulerAdapter getScheduler();
|
||||
|
||||
default void doAsync(Runnable runnable) {
|
||||
getScheduler().doAsync(runnable);
|
||||
}
|
||||
|
||||
default void doSync(Runnable runnable) {
|
||||
getScheduler().doSync(runnable);
|
||||
}
|
||||
/**
|
||||
* Gets the file watcher running on the platform
|
||||
*
|
||||
* @return the file watcher
|
||||
*/
|
||||
Optional<FileWatcher> getFileWatcher();
|
||||
|
||||
/**
|
||||
* Gets a string of the plugin's version
|
||||
@@ -239,20 +238,6 @@ public interface LuckPermsPlugin {
|
||||
*/
|
||||
long getStartTime();
|
||||
|
||||
/**
|
||||
* Gets the file watcher running on the platform, or null if it's not enabled.
|
||||
*
|
||||
* @return the file watcher, or null
|
||||
*/
|
||||
FileWatcher getFileWatcher();
|
||||
|
||||
default void applyToFileWatcher(Consumer<FileWatcher> consumer) {
|
||||
FileWatcher fw = getFileWatcher();
|
||||
if (fw != null) {
|
||||
consumer.accept(fw);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugins main data storage directory
|
||||
*
|
||||
@@ -331,14 +316,14 @@ public interface LuckPermsPlugin {
|
||||
*
|
||||
* @return a {@link List} of usernames
|
||||
*/
|
||||
List<String> getPlayerList();
|
||||
Stream<String> getPlayerList();
|
||||
|
||||
/**
|
||||
* Gets the UUIDs of the users online on the platform
|
||||
*
|
||||
* @return a {@link Set} of UUIDs
|
||||
*/
|
||||
Set<UUID> getOnlinePlayers();
|
||||
Stream<UUID> getOnlinePlayers();
|
||||
|
||||
/**
|
||||
* Checks if a user is online
|
||||
@@ -353,7 +338,7 @@ public interface LuckPermsPlugin {
|
||||
*
|
||||
* @return a {@link List} of senders online on the platform
|
||||
*/
|
||||
List<Sender> getOnlineSenders();
|
||||
Stream<Sender> getOnlineSenders();
|
||||
|
||||
/**
|
||||
* Gets the console.
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import java.util.concurrent.Executor;
|
||||
/**
|
||||
* A scheduler for running tasks using the systems provided by the platform
|
||||
*/
|
||||
public interface LuckPermsScheduler {
|
||||
public interface SchedulerAdapter {
|
||||
|
||||
/**
|
||||
* Gets an async executor instance
|
||||
@@ -144,7 +144,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
}
|
||||
|
||||
private void registerFileAction(StorageLocation type, File file) {
|
||||
plugin.applyToFileWatcher(fileWatcher -> fileWatcher.registerChange(type, file.getName()));
|
||||
plugin.getFileWatcher().ifPresent(fileWatcher -> fileWatcher.registerChange(type, file.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,7 +241,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
actionLogFile.createNewFile();
|
||||
|
||||
// Listen for file changes.
|
||||
plugin.applyToFileWatcher(watcher -> {
|
||||
plugin.getFileWatcher().ifPresent(watcher -> {
|
||||
watcher.subscribe("user", usersDirectory.toPath(), s -> {
|
||||
if (!s.endsWith(fileExtension)) {
|
||||
return;
|
||||
@@ -287,11 +287,10 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public boolean logAction(LogEntry entry) {
|
||||
//noinspection deprecation
|
||||
actionLogger.info(String.format(LOG_FORMAT,
|
||||
(entry.getActor().equals(Constants.CONSOLE_UUID) ? "" : entry.getActor() + " "),
|
||||
entry.getActorName(),
|
||||
Character.toString(entry.getType()),
|
||||
Character.toString(entry.getEntryType().getCode()),
|
||||
(entry.getActed() == null ? "" : entry.getActed().toString() + " "),
|
||||
entry.getActedName(),
|
||||
entry.getAction())
|
||||
|
||||
@@ -161,12 +161,11 @@ public class MongoDao extends AbstractDao {
|
||||
try {
|
||||
MongoCollection<Document> c = database.getCollection(prefix + "action");
|
||||
|
||||
//noinspection deprecation
|
||||
Document doc = new Document()
|
||||
.append("timestamp", entry.getTimestamp())
|
||||
.append("actor", entry.getActor())
|
||||
.append("actorName", entry.getActorName())
|
||||
.append("type", Character.toString(entry.getType()))
|
||||
.append("type", Character.toString(entry.getEntryType().getCode()))
|
||||
.append("actedName", entry.getActedName())
|
||||
.append("action", entry.getAction());
|
||||
|
||||
|
||||
@@ -224,8 +224,7 @@ public class SqlDao extends AbstractDao {
|
||||
ps.setLong(1, entry.getTimestamp());
|
||||
ps.setString(2, entry.getActor().toString());
|
||||
ps.setString(3, entry.getActorName());
|
||||
//noinspection deprecation
|
||||
ps.setString(4, Character.toString(entry.getType()));
|
||||
ps.setString(4, Character.toString(entry.getEntryType().getCode()));
|
||||
ps.setString(5, entry.getActed() == null ? "null" : entry.getActed().toString());
|
||||
ps.setString(6, entry.getActedName());
|
||||
ps.setString(7, entry.getAction());
|
||||
|
||||
Reference in New Issue
Block a user