Cleanup / tidy up a number of classes
This commit is contained in:
@@ -42,6 +42,7 @@ import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
|
||||
import me.lucko.luckperms.common.calculators.CalculatorFactory;
|
||||
import me.lucko.luckperms.common.commands.abstraction.Command;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.config.AbstractConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
|
||||
import me.lucko.luckperms.common.constants.CommandPermission;
|
||||
@@ -55,10 +56,10 @@ import me.lucko.luckperms.common.locale.SimpleLocaleManager;
|
||||
import me.lucko.luckperms.common.logging.SenderLogger;
|
||||
import me.lucko.luckperms.common.managers.GenericTrackManager;
|
||||
import me.lucko.luckperms.common.managers.TrackManager;
|
||||
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.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsScheduler;
|
||||
import me.lucko.luckperms.common.plugin.SchedulerAdapter;
|
||||
import me.lucko.luckperms.common.storage.Storage;
|
||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||
import me.lucko.luckperms.common.storage.StorageType;
|
||||
@@ -73,6 +74,8 @@ import me.lucko.luckperms.sponge.calculators.SpongeCalculatorFactory;
|
||||
import me.lucko.luckperms.sponge.commands.SpongeMainCommand;
|
||||
import me.lucko.luckperms.sponge.contexts.SpongeContextManager;
|
||||
import me.lucko.luckperms.sponge.contexts.WorldCalculator;
|
||||
import me.lucko.luckperms.sponge.listeners.SpongeConnectionListener;
|
||||
import me.lucko.luckperms.sponge.listeners.SpongePlatformListener;
|
||||
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
||||
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
||||
import me.lucko.luckperms.sponge.messaging.SpongeMessagingFactory;
|
||||
@@ -93,10 +96,10 @@ import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
|
||||
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
|
||||
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
|
||||
import org.spongepowered.api.plugin.Plugin;
|
||||
import org.spongepowered.api.plugin.PluginContainer;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
import org.spongepowered.api.scheduler.AsynchronousExecutor;
|
||||
import org.spongepowered.api.scheduler.Scheduler;
|
||||
@@ -109,9 +112,7 @@ import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -121,7 +122,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* LuckPerms implementation for the Sponge API.
|
||||
@@ -157,18 +158,21 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
@AsynchronousExecutor
|
||||
private SpongeExecutorService asyncExecutorService;
|
||||
|
||||
@Inject
|
||||
private PluginContainer pluginContainer;
|
||||
|
||||
private boolean lateLoad = false;
|
||||
private long startTime;
|
||||
|
||||
private LuckPermsScheduler scheduler;
|
||||
private SpongeCommand commandManager;
|
||||
private SchedulerAdapter scheduler;
|
||||
private SpongeCommandExecutor commandManager;
|
||||
private LuckPermsConfiguration configuration;
|
||||
private SpongeUserManager userManager;
|
||||
private SpongeGroupManager groupManager;
|
||||
private TrackManager trackManager;
|
||||
private Storage storage;
|
||||
private FileWatcher fileWatcher = null;
|
||||
private InternalMessagingService messagingService = null;
|
||||
private ExtendedMessagingService messagingService = null;
|
||||
private UuidCache uuidCache;
|
||||
private ApiProvider apiProvider;
|
||||
private me.lucko.luckperms.api.Logger log;
|
||||
@@ -187,7 +191,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
@Listener(order = Order.FIRST)
|
||||
public void onEnable(GamePreInitializationEvent event) {
|
||||
startTime = System.currentTimeMillis();
|
||||
scheduler = new LPSpongeScheduler(this);
|
||||
scheduler = new SpongeSchedulerAdapter(this);
|
||||
localeManager = new NoopLocaleManager();
|
||||
senderFactory = new SpongeSenderFactory(this);
|
||||
log = new SenderLogger(this, getConsoleSender());
|
||||
@@ -198,15 +202,15 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
logDispatcher = new LogDispatcher(this);
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new SpongeConfig(this);
|
||||
configuration = new AbstractConfiguration(this, new SpongeConfigAdapter(this));
|
||||
configuration.init();
|
||||
configuration.loadAll();
|
||||
|
||||
Set<StorageType> storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2);
|
||||
DependencyManager.loadStorageDependencies(this, storageTypes);
|
||||
|
||||
// register events
|
||||
game.getEventManager().registerListeners(this, new SpongeListener(this));
|
||||
game.getEventManager().registerListeners(this, new SpongeConnectionListener(this));
|
||||
game.getEventManager().registerListeners(this, new SpongePlatformListener(this));
|
||||
|
||||
if (getConfiguration().get(ConfigKeys.WATCH_FILES)) {
|
||||
fileWatcher = new FileWatcher(this);
|
||||
@@ -228,7 +232,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
// register commands
|
||||
CommandManager cmdService = game.getCommandManager();
|
||||
commandManager = new SpongeCommand(this);
|
||||
commandManager = new SpongeCommandExecutor(this);
|
||||
cmdService.register(this, commandManager, "luckperms", "lp", "perm", "perms", "permission", "permissions");
|
||||
|
||||
// load internal managers
|
||||
@@ -281,6 +285,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
scheduler.asyncRepeating(new CacheHousekeepingTask(this), 2400L);
|
||||
scheduler.asyncRepeating(new ServiceCacheHousekeepingTask(service), 2400L);
|
||||
|
||||
// register permissions
|
||||
for (CommandPermission perm : CommandPermission.values()) {
|
||||
service.registerPermissionDescription(perm.getPermission(), null, pluginContainer);
|
||||
}
|
||||
|
||||
getLog().info("Successfully enabled. (took " + (System.currentTimeMillis() - startTime) + "ms)");
|
||||
}
|
||||
|
||||
@@ -319,19 +328,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
getLog().info("Goodbye!");
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onPostInit(GamePostInitializationEvent event) {
|
||||
// register permissions
|
||||
LuckPermsService service = this.service;
|
||||
if (service == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (CommandPermission perm : CommandPermission.values()) {
|
||||
registerPermission(service, perm.getPermission());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostUpdate() {
|
||||
for (LPSubjectCollection collection : service.getLoadedCollections().values()) {
|
||||
@@ -342,6 +338,15 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ExtendedMessagingService> getMessagingService() {
|
||||
return Optional.ofNullable(messagingService);
|
||||
}
|
||||
|
||||
public Optional<FileWatcher> getFileWatcher() {
|
||||
return Optional.ofNullable(fileWatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDataDirectory() {
|
||||
File base = configDir.toFile().getParentFile().getParentFile();
|
||||
@@ -422,13 +427,13 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayerList() {
|
||||
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()) : new ArrayList<>();
|
||||
public Stream<String> getPlayerList() {
|
||||
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getName) : Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getOnlinePlayers() {
|
||||
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet()) : new HashSet<>();
|
||||
public Stream<UUID> getOnlinePlayers() {
|
||||
return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId) : Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -437,14 +442,15 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sender> getOnlineSenders() {
|
||||
public Stream<Sender> getOnlineSenders() {
|
||||
if (!game.isServerAvailable()) {
|
||||
return new ArrayList<>();
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
return game.getServer().getOnlinePlayers().stream()
|
||||
.map(s -> getSenderFactory().wrap(s))
|
||||
.collect(Collectors.toList());
|
||||
return Stream.concat(
|
||||
Stream.of(getConsoleSender()),
|
||||
game.getServer().getOnlinePlayers().stream().map(s -> getSenderFactory().wrap(s))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -496,7 +502,4 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
return map;
|
||||
}
|
||||
|
||||
private void registerPermission(LuckPermsService p, String node) {
|
||||
p.registerPermissionDescription(node, null, game.getPluginManager().fromInstance(this).get());
|
||||
}
|
||||
}
|
||||
|
||||
+38
-33
@@ -28,10 +28,10 @@ package me.lucko.luckperms.sponge;
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.commands.CommandManager;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
|
||||
import org.spongepowered.api.command.CommandCallable;
|
||||
import org.spongepowered.api.command.CommandException;
|
||||
import org.spongepowered.api.command.CommandResult;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
@@ -46,49 +46,31 @@ import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
public class SpongeCommandExecutor extends CommandManager implements CommandCallable {
|
||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
SpongeCommand(LPSpongePlugin plugin) {
|
||||
SpongeCommandExecutor(LPSpongePlugin plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private List<String> processArgs(CommandSource source, String s) {
|
||||
List<String> args = Util.stripQuotes(Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(s));
|
||||
|
||||
// resolve selectors
|
||||
ListIterator<String> it = args.listIterator();
|
||||
while (it.hasNext()) {
|
||||
String element = it.next();
|
||||
if (element.startsWith("@")) {
|
||||
try {
|
||||
Player ret = Selector.parse(element).resolve(source).stream()
|
||||
.filter(e -> e instanceof Player)
|
||||
.map(e -> ((Player) e))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
if (ret != null) {
|
||||
it.set(ret.getUniqueId().toString());
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult process(CommandSource source, String s) throws CommandException {
|
||||
onCommand(plugin.getSenderFactory().wrap(source), "lp", processArgs(source, s));
|
||||
public CommandResult process(CommandSource source, String s) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(source);
|
||||
List<String> arguments = processSelectors(source, Util.stripQuotes(ARGUMENT_SPLITTER.splitToList(s)));
|
||||
|
||||
onCommand(lpSender, "lp", arguments);
|
||||
return CommandResult.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandSource source, String s, @Nullable Location<World> location) throws CommandException {
|
||||
return onTabComplete(plugin.getSenderFactory().wrap(source), processArgs(source, s));
|
||||
public List<String> getSuggestions(CommandSource source, String s, @Nullable Location<World> location) {
|
||||
Sender lpSender = plugin.getSenderFactory().wrap(source);
|
||||
List<String> arguments = processSelectors(source, Util.stripQuotes(ARGUMENT_SPLITTER.splitToList(s)));
|
||||
|
||||
return onTabComplete(lpSender, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,4 +92,27 @@ public class SpongeCommand extends CommandManager implements CommandCallable {
|
||||
public Text getUsage(CommandSource source) {
|
||||
return Text.of("/luckperms");
|
||||
}
|
||||
|
||||
private List<String> processSelectors(CommandSource source, List<String> args) {
|
||||
ListIterator<String> it = args.listIterator();
|
||||
while (it.hasNext()) {
|
||||
String element = it.next();
|
||||
if (element.startsWith("@")) {
|
||||
try {
|
||||
Player ret = Selector.parse(element).resolve(source).stream()
|
||||
.filter(e -> e instanceof Player)
|
||||
.map(e -> ((Player) e))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
if (ret != null) {
|
||||
it.set(ret.getUniqueId().toString());
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -30,7 +30,7 @@ import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.config.AbstractConfiguration;
|
||||
import me.lucko.luckperms.common.config.ConfigurationAdapter;
|
||||
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.SimpleConfigurationNode;
|
||||
@@ -49,7 +49,7 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SpongeConfig extends AbstractConfiguration {
|
||||
public class SpongeConfigAdapter implements ConfigurationAdapter {
|
||||
|
||||
@Getter
|
||||
private final LPSpongePlugin plugin;
|
||||
+3
-3
@@ -25,7 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.sponge;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsScheduler;
|
||||
import me.lucko.luckperms.common.plugin.SchedulerAdapter;
|
||||
|
||||
import org.spongepowered.api.scheduler.Task;
|
||||
|
||||
@@ -33,11 +33,11 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class LPSpongeScheduler implements LuckPermsScheduler {
|
||||
public class SpongeSchedulerAdapter implements SchedulerAdapter {
|
||||
private final LPSpongePlugin plugin;
|
||||
private final Set<Task> tasks = ConcurrentHashMap.newKeySet();
|
||||
|
||||
public LPSpongeScheduler(LPSpongePlugin plugin) {
|
||||
public SpongeSchedulerAdapter(LPSpongePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
+2
-5
@@ -71,11 +71,8 @@ public class SpongeCalculatorFactory extends AbstractCalculatorFactory {
|
||||
processors.add(new DefaultsProcessor(plugin.getService(), contexts.getContexts().makeImmutable()));
|
||||
}
|
||||
|
||||
return registerCalculator(new PermissionCalculator(
|
||||
plugin,
|
||||
PermissionCalculatorMetadata.of(user.getFriendlyName(), contexts.getContexts()),
|
||||
processors.build()
|
||||
));
|
||||
PermissionCalculatorMetadata meta = PermissionCalculatorMetadata.of(user.getFriendlyName(), contexts.getContexts());
|
||||
return registerCalculator(new PermissionCalculator(plugin, meta, processors.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-15
@@ -23,7 +23,7 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge;
|
||||
package me.lucko.luckperms.sponge.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -32,11 +32,10 @@ import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.common.model.User;
|
||||
import me.lucko.luckperms.common.utils.LoginHelper;
|
||||
import me.lucko.luckperms.common.utils.UuidCache;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.command.SendCommandEvent;
|
||||
import org.spongepowered.api.event.filter.IsCancelled;
|
||||
import org.spongepowered.api.event.network.ClientConnectionEvent;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
@@ -49,7 +48,7 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SpongeListener {
|
||||
public class SpongeConnectionListener {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
private final Set<UUID> deniedAsyncLogin = Collections.synchronizedSet(new HashSet<>());
|
||||
@@ -175,7 +174,7 @@ public class SpongeListener {
|
||||
@Listener(order = Order.EARLY)
|
||||
public void onClientJoin(ClientConnectionEvent.Join e) {
|
||||
// Refresh permissions again
|
||||
plugin.doAsync(() -> LoginHelper.refreshPlayer(plugin, e.getTargetEntity().getUniqueId()));
|
||||
plugin.getScheduler().doAsync(() -> LoginHelper.refreshPlayer(plugin, e.getTargetEntity().getUniqueId()));
|
||||
}
|
||||
|
||||
@Listener(order = Order.POST)
|
||||
@@ -190,14 +189,4 @@ public class SpongeListener {
|
||||
cache.clearCache(e.getTargetEntity().getUniqueId());
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onSendCommand(SendCommandEvent e) {
|
||||
CommandSource source = e.getCause().first(CommandSource.class).orElse(null);
|
||||
if (source == null) return;
|
||||
|
||||
final String name = e.getCommand().toLowerCase();
|
||||
if (((name.equals("op") || name.equals("minecraft:op")) && source.hasPermission("minecraft.command.op")) || ((name.equals("deop") || name.equals("minecraft:deop")) && source.hasPermission("minecraft.command.deop"))) {
|
||||
Message.OP_DISABLED_SPONGE.send(plugin.getSenderFactory().wrap(source));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge.listeners;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.locale.Message;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.command.SendCommandEvent;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SpongePlatformListener {
|
||||
private final LPSpongePlugin plugin;
|
||||
|
||||
@Listener
|
||||
public void onSendCommand(SendCommandEvent e) {
|
||||
CommandSource source = e.getCause().first(CommandSource.class).orElse(null);
|
||||
if (source == null) return;
|
||||
|
||||
final String name = e.getCommand().toLowerCase();
|
||||
if (((name.equals("op") || name.equals("minecraft:op")) && source.hasPermission("minecraft.command.op")) || ((name.equals("deop") || name.equals("minecraft:deop")) && source.hasPermission("minecraft.command.deop"))) {
|
||||
Message.OP_DISABLED_SPONGE.send(plugin.getSenderFactory().wrap(source));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,12 +198,10 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
||||
@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());
|
||||
}
|
||||
|
||||
/* ------------------------------------------
|
||||
|
||||
+4
-3
@@ -28,6 +28,7 @@ package me.lucko.luckperms.sponge.messaging;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import me.lucko.luckperms.common.messaging.AbstractMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
import org.spongepowered.api.Platform;
|
||||
@@ -41,7 +42,7 @@ import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* An implementation of {@link me.lucko.luckperms.api.MessagingService} using the plugin messaging channels.
|
||||
* An implementation of {@link ExtendedMessagingService} using the plugin messaging channels.
|
||||
*/
|
||||
public class BungeeMessagingService extends AbstractMessagingService implements RawDataListener {
|
||||
private final LPSpongePlugin plugin;
|
||||
@@ -65,7 +66,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(String channel, String message) {
|
||||
protected void sendMessage(String message) {
|
||||
plugin.getSpongeScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(task -> {
|
||||
if (!plugin.getGame().isServerAvailable()) {
|
||||
return;
|
||||
@@ -86,6 +87,6 @@ public class BungeeMessagingService extends AbstractMessagingService implements
|
||||
@Override
|
||||
public void handlePayload(ChannelBuf buf, RemoteConnection connection, Platform.Type type) {
|
||||
String msg = buf.readUTF();
|
||||
onMessage(CHANNEL, msg, null);
|
||||
onMessage(msg, null);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
|
||||
package me.lucko.luckperms.sponge.messaging;
|
||||
|
||||
import me.lucko.luckperms.common.messaging.InternalMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||
import me.lucko.luckperms.common.messaging.MessagingFactory;
|
||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class SpongeMessagingFactory extends MessagingFactory<LPSpongePlugin> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InternalMessagingService getServiceFor(String messagingType) {
|
||||
protected ExtendedMessagingService getServiceFor(String messagingType) {
|
||||
if (messagingType.equals("bungee")) {
|
||||
BungeeMessagingService bungeeMessaging = new BungeeMessagingService(getPlugin());
|
||||
bungeeMessaging.init();
|
||||
|
||||
+6
-8
@@ -79,16 +79,14 @@ public class PersistedSubject implements LPSubject {
|
||||
.expireAfterAccess(20, TimeUnit.MINUTES)
|
||||
.build(lookup -> lookupOptionValue(lookup.getContexts(), lookup.getKey()));
|
||||
|
||||
private final BufferedRequest<Void> saveBuffer = new BufferedRequest<Void>(1000L, 500L, r -> PersistedSubject.this.service.getPlugin().doAsync(r)) {
|
||||
private final BufferedRequest<Void> saveBuffer = new BufferedRequest<Void>(1000L, 500L, r -> PersistedSubject.this.service.getPlugin().getScheduler().doAsync(r)) {
|
||||
@Override
|
||||
protected Void perform() {
|
||||
service.getPlugin().doAsync(() -> {
|
||||
try {
|
||||
service.getStorage().saveToFile(PersistedSubject.this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
try {
|
||||
service.getStorage().saveToFile(PersistedSubject.this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user