diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommand.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java similarity index 70% rename from bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommand.java rename to bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java index 9ebdb976..b573f7e6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommand.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCommandExecutor.java @@ -29,6 +29,7 @@ import com.google.common.base.Joiner; 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.bukkit.command.Command; @@ -36,29 +37,33 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; -import java.util.Arrays; import java.util.List; -public class BukkitCommand extends CommandManager implements CommandExecutor, TabExecutor { +public class BukkitCommandExecutor extends CommandManager implements CommandExecutor, TabExecutor { + private static final Splitter ARGUMENT_SPLITTER = Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings(); + private static final Joiner ARGUMENT_JOINER = Joiner.on(' '); + private final LPBukkitPlugin plugin; - BukkitCommand(LPBukkitPlugin plugin) { + BukkitCommandExecutor(LPBukkitPlugin plugin) { super(plugin); this.plugin = plugin; } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - onCommand( - plugin.getSenderFactory().wrap(sender), - label, - Util.stripQuotes(Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))) - ); + Sender lpSender = plugin.getSenderFactory().wrap(sender); + List arguments = Util.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); + + onCommand(lpSender, label, arguments); return true; } @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { - return onTabComplete(plugin.getSenderFactory().wrap(sender), Arrays.asList(args)); + Sender lpSender = plugin.getSenderFactory().wrap(sender); + List arguments = Util.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); + + return onTabComplete(lpSender, arguments); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java similarity index 96% rename from bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java rename to bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java index cce58ce4..b8dfecf7 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java @@ -28,7 +28,7 @@ package me.lucko.luckperms.bukkit; import lombok.Getter; import lombok.RequiredArgsConstructor; -import me.lucko.luckperms.common.config.AbstractConfiguration; +import me.lucko.luckperms.common.config.ConfigurationAdapter; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -41,7 +41,7 @@ import java.util.Map; import java.util.Set; @RequiredArgsConstructor -public class BukkitConfig extends AbstractConfiguration { +public class BukkitConfigAdapter implements ConfigurationAdapter { @Getter private final LPBukkitPlugin plugin; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitScheduler.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSchedulerAdapter.java similarity index 91% rename from bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitScheduler.java rename to bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSchedulerAdapter.java index de30b0a6..389d89a3 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitScheduler.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSchedulerAdapter.java @@ -29,7 +29,7 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; -import me.lucko.luckperms.common.plugin.LuckPermsScheduler; +import me.lucko.luckperms.common.plugin.SchedulerAdapter; import org.bukkit.scheduler.BukkitTask; @@ -40,7 +40,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -public class LPBukkitScheduler implements LuckPermsScheduler { +public class BukkitSchedulerAdapter implements SchedulerAdapter { private final LPBukkitPlugin plugin; @Getter @@ -55,23 +55,23 @@ public class LPBukkitScheduler implements LuckPermsScheduler { @Accessors(fluent = true) private Executor sync; + @Getter + @Accessors(fluent = true) + private Executor async; + @Getter @Setter private boolean useBukkitAsync = false; private final Set tasks = ConcurrentHashMap.newKeySet(); - public LPBukkitScheduler(LPBukkitPlugin plugin) { + public BukkitSchedulerAdapter(LPBukkitPlugin plugin) { this.plugin = plugin; this.asyncLp = Executors.newCachedThreadPool(); this.asyncBukkit = r -> plugin.getServer().getScheduler().runTaskAsynchronously(plugin, r); this.sync = r -> plugin.getServer().getScheduler().runTask(plugin, r); - } - - @Override - public Executor async() { - return useBukkitAsync ? asyncBukkit : asyncLp; + this.async = r -> (useBukkitAsync ? asyncBukkit : asyncLp).execute(r); } @Override diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java index d8898870..067c4f2d 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitSenderFactory.java @@ -25,6 +25,8 @@ package me.lucko.luckperms.bukkit; +import lombok.AllArgsConstructor; + import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.bukkit.compat.MessageHandler; import me.lucko.luckperms.common.commands.sender.SenderFactory; @@ -68,7 +70,7 @@ public class BukkitSenderFactory extends SenderFactory { // send sync if command block if (sender instanceof BlockCommandSender) { - getPlugin().getScheduler().doSync(() -> sender.sendMessage(s)); + getPlugin().getScheduler().doSync(new BlockMessageAgent(((BlockCommandSender) sender), s)); return; } @@ -92,4 +94,16 @@ public class BukkitSenderFactory extends SenderFactory { protected boolean hasPermission(CommandSender sender, String node) { return sender.hasPermission(node); } + + @AllArgsConstructor + private static final class BlockMessageAgent implements Runnable { + private final BlockCommandSender block; + private final String message; + + @Override + public void run() { + block.sendMessage(message); + } + } + } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 172df2d2..fee6feba 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -34,9 +34,12 @@ import me.lucko.luckperms.api.PlatformType; import me.lucko.luckperms.bukkit.calculators.BukkitCalculatorFactory; import me.lucko.luckperms.bukkit.contexts.BukkitContextManager; import me.lucko.luckperms.bukkit.contexts.WorldCalculator; +import me.lucko.luckperms.bukkit.listeners.BukkitConnectionListener; +import me.lucko.luckperms.bukkit.listeners.BukkitPlatformListener; import me.lucko.luckperms.bukkit.messaging.BukkitMessagingFactory; import me.lucko.luckperms.bukkit.model.Injector; import me.lucko.luckperms.bukkit.model.LPPermissible; +import me.lucko.luckperms.bukkit.processors.BukkitProcessorsSetupTask; import me.lucko.luckperms.bukkit.processors.ChildPermissionProvider; import me.lucko.luckperms.bukkit.processors.DefaultsProvider; import me.lucko.luckperms.bukkit.vault.VaultHookManager; @@ -48,6 +51,7 @@ import me.lucko.luckperms.common.buffers.UpdateTaskBuffer; import me.lucko.luckperms.common.caching.handlers.CachedStateManager; import me.lucko.luckperms.common.calculators.CalculatorFactory; 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; @@ -65,7 +69,7 @@ import me.lucko.luckperms.common.managers.GenericUserManager; 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.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.storage.Storage; @@ -92,16 +96,14 @@ import java.io.File; import java.io.InputStream; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; -import java.util.stream.Collectors; +import java.util.stream.Stream; /** * LuckPerms implementation for the Bukkit API. @@ -110,8 +112,8 @@ import java.util.stream.Collectors; public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private long startTime; - private LPBukkitScheduler scheduler; - private BukkitCommand commandManager; + private BukkitSchedulerAdapter scheduler; + private BukkitCommandExecutor commandManager; private VaultHookManager vaultHookManager = null; private LuckPermsConfiguration configuration; private UserManager userManager; @@ -119,9 +121,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private TrackManager trackManager; private Storage storage; private FileWatcher fileWatcher = null; - private InternalMessagingService messagingService = null; + private ExtendedMessagingService messagingService = null; private UuidCache uuidCache; - private BukkitListener listener; private ApiProvider apiProvider; private Logger log; private DefaultsProvider defaultsProvider; @@ -146,7 +147,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } // setup minimal functionality in order to load initial dependencies - scheduler = new LPBukkitScheduler(this); + scheduler = new BukkitSchedulerAdapter(this); localeManager = new NoopLocaleManager(); senderFactory = new BukkitSenderFactory(this); log = new SenderLogger(this, getConsoleSender()); @@ -186,9 +187,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { logDispatcher = new LogDispatcher(this); getLog().info("Loading configuration..."); - configuration = new BukkitConfig(this); + configuration = new AbstractConfiguration(this, new BukkitConfigAdapter(this)); configuration.init(); - configuration.loadAll(); Set storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2); DependencyManager.loadStorageDependencies(this, storageTypes); @@ -198,22 +198,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { childPermissionProvider = new ChildPermissionProvider(); // give all plugins a chance to load their permissions, then refresh. - scheduler.syncLater(() -> { - defaultsProvider.refresh(); - childPermissionProvider.setup(); - - Set perms = new HashSet<>(); - getServer().getPluginManager().getPermissions().forEach(p -> { - perms.add(p.getName()); - perms.addAll(p.getChildren().keySet()); - }); - - perms.forEach(p -> permissionVault.offer(p)); - }, 1L); + scheduler.syncLater(new BukkitProcessorsSetupTask(this), 1L); // register events - listener = new BukkitListener(this); - getServer().getPluginManager().registerEvents(listener, this); + getServer().getPluginManager().registerEvents(new BukkitConnectionListener(this), this); + getServer().getPluginManager().registerEvents(new BukkitPlatformListener(this), this); if (getConfiguration().get(ConfigKeys.WATCH_FILES)) { fileWatcher = new FileWatcher(this); @@ -234,7 +223,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { localeManager.tryLoad(this, new File(getDataFolder(), "lang.yml")); // register commands - commandManager = new BukkitCommand(this); + commandManager = new BukkitCommandExecutor(this); PluginCommand main = getServer().getPluginCommand("luckperms"); main.setExecutor(commandManager); main.setTabCompleter(commandManager); @@ -282,7 +271,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { // register permissions try { - registerPermissions(getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE); + PluginManager pm = getServer().getPluginManager(); + PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE; + + for (CommandPermission p : CommandPermission.values()) { + pm.addPermission(new org.bukkit.permissions.Permission(p.getPermission(), permDefault)); + } } catch (Exception e) { // this throws an exception if the plugin is /reloaded, grr } @@ -414,6 +408,15 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } } + @Override + public Optional getMessagingService() { + return Optional.ofNullable(messagingService); + } + + public Optional getFileWatcher() { + return Optional.ofNullable(fileWatcher); + } + @Override public String getVersion() { return getDescription().getVersion(); @@ -475,13 +478,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } @Override - public List getPlayerList() { - return getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); + public Stream getPlayerList() { + return getServer().getOnlinePlayers().stream().map(Player::getName); } @Override - public Set getOnlinePlayers() { - return getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet()); + public Stream getOnlinePlayers() { + return getServer().getOnlinePlayers().stream().map(Player::getUniqueId); } @Override @@ -491,10 +494,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } @Override - public List getOnlineSenders() { - return getServer().getOnlinePlayers().stream() - .map(p -> getSenderFactory().wrap(p)) - .collect(Collectors.toList()); + public Stream getOnlineSenders() { + return Stream.concat( + Stream.of(getConsoleSender()), + getServer().getOnlinePlayers().stream().map(p -> getSenderFactory().wrap(p)) + ); } @Override @@ -511,14 +515,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { return map; } - private void registerPermissions(PermissionDefault def) { - PluginManager pm = getServer().getPluginManager(); - - for (CommandPermission p : CommandPermission.values()) { - pm.addPermission(new org.bukkit.permissions.Permission(p.getPermission(), def)); - } - } - private static boolean checkInvalidVersion() { try { Class.forName("com.google.gson.JsonElement"); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java index 05b6c9db..5be4b649 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/calculators/BukkitCalculatorFactory.java @@ -71,11 +71,8 @@ public class BukkitCalculatorFactory extends AbstractCalculatorFactory { processors.add(new DefaultsProcessor(contexts.isOp(), plugin.getDefaultsProvider())); } - 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 diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java similarity index 88% rename from bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java rename to bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java index 9b328618..ce5fde58 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java @@ -23,10 +23,11 @@ * SOFTWARE. */ -package me.lucko.luckperms.bukkit; +package me.lucko.luckperms.bukkit.listeners; import lombok.RequiredArgsConstructor; +import me.lucko.luckperms.bukkit.LPBukkitPlugin; import me.lucko.luckperms.bukkit.model.Injector; import me.lucko.luckperms.bukkit.model.LPPermissible; import me.lucko.luckperms.common.config.ConfigKeys; @@ -39,11 +40,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.server.PluginEnableEvent; import java.util.Collections; import java.util.HashSet; @@ -52,7 +50,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; @RequiredArgsConstructor -public class BukkitListener implements Listener { +public class BukkitConnectionListener implements Listener { private final LPBukkitPlugin plugin; private final Set deniedAsyncLogin = Collections.synchronizedSet(new HashSet<>()); @@ -225,33 +223,4 @@ public class BukkitListener implements Listener { plugin.getUserManager().scheduleUnload(player.getUniqueId()); } - @EventHandler - public void onPlayerCommand(PlayerCommandPreprocessEvent e) { - if (plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) { - return; - } - - String s = e.getMessage().substring(1).toLowerCase() - .replace("bukkit:", "") - .replace("spigot:", "") - .replace("minecraft:", ""); - - if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) { - e.setCancelled(true); - e.getPlayer().sendMessage(Message.OP_DISABLED.asString(plugin.getLocaleManager())); - } - } - - @EventHandler - public void onPluginEnable(PluginEnableEvent e) { - if (e.getPlugin().getName().equalsIgnoreCase("Vault")) { - plugin.tryVaultHook(true); - } - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onWorldChange(PlayerChangedWorldEvent e) { - plugin.getContextManager().invalidateCache(e.getPlayer()); - plugin.refreshAutoOp(plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()), e.getPlayer()); - } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitPlatformListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitPlatformListener.java new file mode 100644 index 00000000..225ee61f --- /dev/null +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitPlatformListener.java @@ -0,0 +1,100 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.bukkit.listeners; + +import lombok.RequiredArgsConstructor; + +import me.lucko.luckperms.bukkit.LPBukkitPlugin; +import me.lucko.luckperms.common.config.ConfigKeys; +import me.lucko.luckperms.common.locale.Message; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.Cancellable; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.server.PluginEnableEvent; +import org.bukkit.event.server.RemoteServerCommandEvent; +import org.bukkit.event.server.ServerCommandEvent; + +@RequiredArgsConstructor +public class BukkitPlatformListener implements Listener { + private final LPBukkitPlugin plugin; + + @EventHandler + public void onPlayerCommand(PlayerCommandPreprocessEvent e) { + handleCommand(e.getPlayer(), e.getMessage().toLowerCase(), e); + } + + @EventHandler + public void onServerCommand(ServerCommandEvent e) { + handleCommand(e.getSender(), e.getCommand().toLowerCase(), e); + } + + @EventHandler + public void onRemoteServerCommand(RemoteServerCommandEvent e) { + handleCommand(e.getSender(), e.getCommand().toLowerCase(), e); + } + + private void handleCommand(CommandSender sender, String s, Cancellable event) { + if (s.isEmpty()) { + return; + } + + if (plugin.getConfiguration().get(ConfigKeys.OPS_ENABLED)) { + return; + } + + if (s.charAt(0) == '/') { + s = s.substring(1); + } + + if (s.startsWith("minecraft:")) { + s = s.substring("minecraft:".length()); + } + + if (s.equals("op") || s.startsWith("op ") || s.equals("deop") || s.startsWith("deop ")) { + event.setCancelled(true); + sender.sendMessage(Message.OP_DISABLED.asString(plugin.getLocaleManager())); + } + } + + @EventHandler + public void onPluginEnable(PluginEnableEvent e) { + if (e.getPlugin().getName().equalsIgnoreCase("Vault")) { + plugin.tryVaultHook(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onWorldChange(PlayerChangedWorldEvent e) { + plugin.getContextManager().invalidateCache(e.getPlayer()); + plugin.refreshAutoOp(plugin.getUserManager().getIfLoaded(e.getPlayer().getUniqueId()), e.getPlayer()); + } + +} diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BukkitMessagingFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BukkitMessagingFactory.java index aa30ceaf..a480a9cb 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BukkitMessagingFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BukkitMessagingFactory.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.bukkit.messaging; import me.lucko.luckperms.bukkit.LPBukkitPlugin; -import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.ExtendedMessagingService; import me.lucko.luckperms.common.messaging.MessagingFactory; public class BukkitMessagingFactory extends MessagingFactory { @@ -35,7 +35,7 @@ public class BukkitMessagingFactory extends MessagingFactory { } @Override - protected InternalMessagingService getServiceFor(String messagingType) { + protected ExtendedMessagingService getServiceFor(String messagingType) { if (messagingType.equals("bungee")) { BungeeMessagingService bungeeMessaging = new BungeeMessagingService(getPlugin()); bungeeMessaging.init(); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BungeeMessagingService.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BungeeMessagingService.java index 0e1ff46d..667efe93 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BungeeMessagingService.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/BungeeMessagingService.java @@ -32,6 +32,7 @@ import com.google.common.io.ByteStreams; import me.lucko.luckperms.bukkit.LPBukkitPlugin; import me.lucko.luckperms.common.messaging.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.ExtendedMessagingService; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; @@ -40,7 +41,7 @@ import org.bukkit.scheduler.BukkitRunnable; import java.util.Collection; /** - * 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 PluginMessageListener { private final LPBukkitPlugin plugin; @@ -62,7 +63,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements } @Override - protected void sendMessage(String channel, String message) { + protected void sendMessage(String message) { new BukkitRunnable() { @Override public void run() { @@ -77,7 +78,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements byte[] data = out.toByteArray(); - p.sendPluginMessage(plugin, channel, data); + p.sendPluginMessage(plugin, CHANNEL, data); cancel(); } }.runTaskTimer(plugin, 1L, 100L); @@ -92,6 +93,6 @@ public class BungeeMessagingService extends AbstractMessagingService implements ByteArrayDataInput in = ByteStreams.newDataInput(bytes); String msg = in.readUTF(); - onMessage(s, msg, null); + onMessage(msg, null); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/LilyPadMessagingService.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/LilyPadMessagingService.java index c48644d9..a3571938 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/LilyPadMessagingService.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/messaging/LilyPadMessagingService.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.bukkit.messaging; import me.lucko.luckperms.bukkit.LPBukkitPlugin; import me.lucko.luckperms.common.messaging.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.ExtendedMessagingService; import lilypad.client.connect.api.Connect; import lilypad.client.connect.api.event.EventListener; @@ -38,7 +39,7 @@ import java.io.UnsupportedEncodingException; import java.util.Collections; /** - * An implementation of {@link me.lucko.luckperms.api.MessagingService} using LilyPad. + * An implementation of {@link ExtendedMessagingService} using LilyPad. */ public class LilyPadMessagingService extends AbstractMessagingService { private final LPBukkitPlugin plugin; @@ -60,11 +61,11 @@ public class LilyPadMessagingService extends AbstractMessagingService { } @Override - protected void sendMessage(String channel, String message) { + protected void sendMessage(String message) { MessageRequest request; try { - request = new MessageRequest(Collections.emptyList(), channel, message); + request = new MessageRequest(Collections.emptyList(), CHANNEL, message); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return; @@ -79,12 +80,17 @@ public class LilyPadMessagingService extends AbstractMessagingService { @EventListener public void onMessage(MessageEvent event) { - plugin.doAsync(() -> { + plugin.getScheduler().doAsync(() -> { try { String channel = event.getChannel(); + + if (!channel.equals(CHANNEL)) { + return; + } + String message = event.getMessageAsString(); - onMessage(channel, message, null); + onMessage(message, null); } catch (Exception e) { e.printStackTrace(); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java index 752f209b..8a4fb44f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java @@ -73,7 +73,7 @@ public class LPPermissible extends PermissibleBase { private final User user; // the player this permissible is injected into. - private final Player parent; + private final Player player; // the luckperms plugin instance private final LPBukkitPlugin plugin; @@ -92,10 +92,10 @@ public class LPPermissible extends PermissibleBase { // this collection is only modified by the attachments themselves final Set attachments = ConcurrentHashMap.newKeySet(); - public LPPermissible(@NonNull Player parent, @NonNull User user, @NonNull LPBukkitPlugin plugin) { - super(parent); + public LPPermissible(@NonNull Player player, @NonNull User user, @NonNull LPBukkitPlugin plugin) { + super(player); this.user = user; - this.parent = parent; + this.player = player; this.plugin = plugin; this.subscriptions = new SubscriptionManager(this); } @@ -148,7 +148,7 @@ public class LPPermissible extends PermissibleBase { return; } - plugin.doAsync(this::updateSubscriptions); + plugin.getScheduler().doAsync(this::updateSubscriptions); } /** @@ -166,7 +166,7 @@ public class LPPermissible extends PermissibleBase { // include defaults, if enabled. if (plugin.getConfiguration().get(ConfigKeys.APPLY_BUKKIT_DEFAULT_PERMISSIONS)) { - if (parent.isOp()) { + if (player.isOp()) { ent.addAll(plugin.getDefaultsProvider().getOpDefaults().keySet()); } else { ent.addAll(plugin.getDefaultsProvider().getNonOpDefaults().keySet()); @@ -180,7 +180,7 @@ public class LPPermissible extends PermissibleBase { * Unsubscribes from all permissions asynchronously */ public void unsubscribeFromAllAsync() { - plugin.doAsync(this::unsubscribeFromAll); + plugin.getScheduler().doAsync(this::unsubscribeFromAll); } /** @@ -208,12 +208,12 @@ public class LPPermissible extends PermissibleBase { * @return the calculated contexts for the player. */ public Contexts calculateContexts() { - return plugin.getContextManager().getApplicableContexts(parent); + return plugin.getContextManager().getApplicableContexts(player); } @Override public void setOp(boolean value) { - parent.setOp(value); + player.setOp(value); } @Override @@ -221,7 +221,7 @@ public class LPPermissible extends PermissibleBase { Set perms = new HashSet<>(); perms.addAll( user.getUserData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet().stream() - .map(e -> new PermissionAttachmentInfo(parent, e.getKey(), null, e.getValue())) + .map(e -> new PermissionAttachmentInfo(player, e.getKey(), null, e.getValue())) .collect(Collectors.toList()) ); return perms; @@ -250,7 +250,7 @@ public class LPPermissible extends PermissibleBase { LPPermissionAttachment ret = addAttachment(plugin); if (getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(plugin, ret::remove, ticks) == -1) { ret.remove(); - throw new RuntimeException("Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1"); + throw new RuntimeException("Could not add PermissionAttachment to " + player + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1"); } return ret; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java index b0d24310..b28ac75f 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/SubscriptionManager.java @@ -57,7 +57,9 @@ public class SubscriptionManager { // we compare changes to avoid unnecessary time wasted on the main thread mutating this data. // the changes can be calculated here async, and then only the needed changes can be applied. Map.Entry, Set> changes = compareSets(newPerms, currentSubscriptions); - permissible.getPlugin().doSync(new SubscriptionUpdateTask(permissible, changes.getKey(), changes.getValue())); + if (!changes.getKey().isEmpty() || !changes.getValue().isEmpty()) { + permissible.getPlugin().getScheduler().doSync(new SubscriptionUpdateTask(permissible, changes.getKey(), changes.getValue())); + } this.currentSubscriptions = newPerms; } @@ -71,10 +73,10 @@ public class SubscriptionManager { @Override public void run() { for (String s : toAdd) { - permissible.getPlugin().getServer().getPluginManager().subscribeToPermission(s, permissible.getParent()); + permissible.getPlugin().getServer().getPluginManager().subscribeToPermission(s, permissible.getPlayer()); } for (String s : toRemove) { - permissible.getPlugin().getServer().getPluginManager().unsubscribeFromPermission(s, permissible.getParent()); + permissible.getPlugin().getServer().getPluginManager().unsubscribeFromPermission(s, permissible.getPlayer()); } } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/processors/BukkitProcessorsSetupTask.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/processors/BukkitProcessorsSetupTask.java new file mode 100644 index 00000000..5d00fc37 --- /dev/null +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/processors/BukkitProcessorsSetupTask.java @@ -0,0 +1,55 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.bukkit.processors; + +import lombok.RequiredArgsConstructor; + +import me.lucko.luckperms.bukkit.LPBukkitPlugin; + +import java.util.HashSet; +import java.util.Set; + +/** + * Performs the initial setup for Bukkit permission processors + */ +@RequiredArgsConstructor +public class BukkitProcessorsSetupTask implements Runnable { + private final LPBukkitPlugin plugin; + + @Override + public void run() { + plugin.getDefaultsProvider().refresh(); + plugin.getChildPermissionProvider().setup(); + + Set perms = new HashSet<>(); + plugin.getServer().getPluginManager().getPermissions().forEach(p -> { + perms.add(p.getName()); + perms.addAll(p.getChildren().keySet()); + }); + + perms.forEach(p -> plugin.getPermissionVault().offer(p)); + } +} diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommandExecutor.java similarity index 69% rename from bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java rename to bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommandExecutor.java index 35368637..54905823 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommandExecutor.java @@ -29,19 +29,23 @@ import com.google.common.base.Joiner; 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 net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.TabExecutor; -import java.util.Arrays; +import java.util.List; + +public class BungeeCommandExecutor extends Command implements TabExecutor { + private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings(); + private static final Joiner ARGUMENT_JOINER = Joiner.on(' '); -public class BungeeCommand extends Command implements TabExecutor { private final LPBungeePlugin plugin; private final CommandManager manager; - BungeeCommand(LPBungeePlugin plugin, CommandManager manager) { + BungeeCommandExecutor(LPBungeePlugin plugin, CommandManager manager) { super("luckpermsbungee", null, "lpb", "bperm", "bperms", "bpermission", "bpermissions"); this.plugin = plugin; this.manager = manager; @@ -49,15 +53,17 @@ public class BungeeCommand extends Command implements TabExecutor { @Override public void execute(CommandSender sender, String[] args) { - manager.onCommand( - plugin.getSenderFactory().wrap(sender), - "lpb", - Util.stripQuotes(Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))) - ); + Sender lpSender = plugin.getSenderFactory().wrap(sender); + List arguments = Util.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); + + manager.onCommand(lpSender, "lpb", arguments); } @Override public Iterable onTabComplete(CommandSender sender, String[] args) { - return manager.onTabComplete(plugin.getSenderFactory().wrap(sender), Arrays.asList(args)); + Sender lpSender = plugin.getSenderFactory().wrap(sender); + List arguments = Util.stripQuotes(ARGUMENT_SPLITTER.splitToList(ARGUMENT_JOINER.join(args))); + + return manager.onTabComplete(lpSender, arguments); } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java similarity index 96% rename from bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java rename to bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java index 11c49f20..10da7879 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java @@ -28,7 +28,7 @@ package me.lucko.luckperms.bungee; import lombok.Getter; import lombok.RequiredArgsConstructor; -import me.lucko.luckperms.common.config.AbstractConfiguration; +import me.lucko.luckperms.common.config.ConfigurationAdapter; import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.ConfigurationProvider; @@ -45,7 +45,7 @@ import java.util.Map; import java.util.Optional; @RequiredArgsConstructor -public class BungeeConfig extends AbstractConfiguration { +public class BungeeConfigAdapter implements ConfigurationAdapter { @Getter private final LPBungeePlugin plugin; diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeeScheduler.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSchedulerAdapter.java similarity index 94% rename from bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeeScheduler.java rename to bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSchedulerAdapter.java index 2e2497b5..f747a072 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeeScheduler.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeSchedulerAdapter.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.bungee; -import me.lucko.luckperms.common.plugin.LuckPermsScheduler; +import me.lucko.luckperms.common.plugin.SchedulerAdapter; import net.md_5.bungee.api.scheduler.ScheduledTask; @@ -34,13 +34,13 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; -public class LPBungeeScheduler implements LuckPermsScheduler { +public class BungeeSchedulerAdapter implements SchedulerAdapter { private final LPBungeePlugin plugin; private final Executor asyncExecutor; private final Set tasks = ConcurrentHashMap.newKeySet(); - public LPBungeeScheduler(LPBungeePlugin plugin) { + public BungeeSchedulerAdapter(LPBungeePlugin plugin) { this.plugin = plugin; this.asyncExecutor = r -> plugin.getProxy().getScheduler().runAsync(plugin, r); } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index 62bba40c..d57df63a 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -33,6 +33,8 @@ import me.lucko.luckperms.api.PlatformType; import me.lucko.luckperms.bungee.calculators.BungeeCalculatorFactory; import me.lucko.luckperms.bungee.contexts.BackendServerCalculator; import me.lucko.luckperms.bungee.contexts.BungeeContextManager; +import me.lucko.luckperms.bungee.listeners.BungeeConnectionListener; +import me.lucko.luckperms.bungee.listeners.BungeePermissionCheckListener; import me.lucko.luckperms.bungee.messaging.BungeeMessagingFactory; import me.lucko.luckperms.bungee.util.RedisBungeeUtil; import me.lucko.luckperms.common.actionlog.LogDispatcher; @@ -44,6 +46,7 @@ import me.lucko.luckperms.common.caching.handlers.CachedStateManager; import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.commands.CommandManager; 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.contexts.ContextManager; @@ -60,10 +63,10 @@ import me.lucko.luckperms.common.managers.GenericUserManager; 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.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; @@ -81,12 +84,11 @@ import net.md_5.bungee.api.plugin.Plugin; import java.io.File; import java.io.InputStream; import java.util.Collections; -import java.util.List; import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; +import java.util.stream.Stream; /** * LuckPerms implementation for the BungeeCord API. @@ -95,7 +97,7 @@ import java.util.stream.Collectors; public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { private long startTime; - private LuckPermsScheduler scheduler; + private SchedulerAdapter scheduler; private CommandManager commandManager; private LuckPermsConfiguration configuration; private UserManager userManager; @@ -103,7 +105,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { 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 Logger log; @@ -121,7 +123,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { @Override public void onLoad() { // setup minimal functionality in order to load initial dependencies - scheduler = new LPBungeeScheduler(this); + scheduler = new BungeeSchedulerAdapter(this); localeManager = new NoopLocaleManager(); senderFactory = new BungeeSenderFactory(this); log = new SenderLogger(this, getConsoleSender()); @@ -138,15 +140,15 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { logDispatcher = new LogDispatcher(this); getLog().info("Loading configuration..."); - configuration = new BungeeConfig(this); + configuration = new AbstractConfiguration(this, new BungeeConfigAdapter(this)); configuration.init(); - configuration.loadAll(); Set storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2); DependencyManager.loadStorageDependencies(this, storageTypes); // register events - getProxy().getPluginManager().registerListener(this, new BungeeListener(this)); + getProxy().getPluginManager().registerListener(this, new BungeeConnectionListener(this)); + getProxy().getPluginManager().registerListener(this, new BungeePermissionCheckListener(this)); if (getConfiguration().get(ConfigKeys.WATCH_FILES)) { fileWatcher = new FileWatcher(this); @@ -168,7 +170,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { // register commands commandManager = new CommandManager(this); - getProxy().getPluginManager().registerCommand(this, new BungeeCommand(this, commandManager)); + getProxy().getPluginManager().registerCommand(this, new BungeeCommandExecutor(this, commandManager)); // disable the default Bungee /perms command so it gets handled by the Bukkit plugin getProxy().getDisabledCommands().add("perms"); @@ -237,6 +239,15 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { getLog().info("Goodbye!"); } + @Override + public Optional getMessagingService() { + return Optional.ofNullable(messagingService); + } + + public Optional getFileWatcher() { + return Optional.ofNullable(fileWatcher); + } + @Override public String getVersion() { return getDescription().getVersion(); @@ -300,13 +311,13 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { } @Override - public List getPlayerList() { - return getProxy().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()); + public Stream getPlayerList() { + return getProxy().getPlayers().stream().map(ProxiedPlayer::getName); } @Override - public Set getOnlinePlayers() { - return getProxy().getPlayers().stream().map(ProxiedPlayer::getUniqueId).collect(Collectors.toSet()); + public Stream getOnlinePlayers() { + return getProxy().getPlayers().stream().map(ProxiedPlayer::getUniqueId); } @Override @@ -316,10 +327,11 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { } @Override - public List getOnlineSenders() { - return getProxy().getPlayers().stream() - .map(p -> getSenderFactory().wrap(p)) - .collect(Collectors.toList()); + public Stream getOnlineSenders() { + return Stream.concat( + Stream.of(getConsoleSender()), + getProxy().getPlayers().stream().map(p -> getSenderFactory().wrap(p)) + ); } @Override diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/calculators/BungeeCalculatorFactory.java b/bungee/src/main/java/me/lucko/luckperms/bungee/calculators/BungeeCalculatorFactory.java index b6786be5..95bdb836 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/calculators/BungeeCalculatorFactory.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/calculators/BungeeCalculatorFactory.java @@ -61,11 +61,8 @@ public class BungeeCalculatorFactory extends AbstractCalculatorFactory { processors.add(new WildcardProcessor()); } - 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 diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java similarity index 76% rename from bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java rename to bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java index c718d643..9d62cc79 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeeConnectionListener.java @@ -23,24 +23,20 @@ * SOFTWARE. */ -package me.lucko.luckperms.bungee; +package me.lucko.luckperms.bungee.listeners; import lombok.RequiredArgsConstructor; -import me.lucko.luckperms.api.Contexts; -import me.lucko.luckperms.api.Tristate; -import me.lucko.luckperms.bungee.event.TristateCheckEvent; +import me.lucko.luckperms.bungee.LPBungeePlugin; import me.lucko.luckperms.common.config.ConfigKeys; 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.verbose.CheckOrigin; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.LoginEvent; -import net.md_5.bungee.api.event.PermissionCheckEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.plugin.Listener; @@ -50,7 +46,7 @@ import net.md_5.bungee.event.EventPriority; import java.util.concurrent.TimeUnit; @RequiredArgsConstructor -public class BungeeListener implements Listener { +public class BungeeConnectionListener implements Listener { private final LPBungeePlugin plugin; @EventHandler(priority = EventPriority.LOW) @@ -91,7 +87,7 @@ public class BungeeListener implements Listener { } - plugin.doAsync(() -> { + plugin.getScheduler().doAsync(() -> { plugin.getUniqueConnections().add(c.getUniqueId()); /* Actually process the login for the connection. @@ -163,50 +159,4 @@ public class BungeeListener implements Listener { plugin.getUserManager().scheduleUnload(e.getPlayer().getUniqueId()); } - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerPermissionCheck(PermissionCheckEvent e) { - if (!(e.getSender() instanceof ProxiedPlayer)) { - return; - } - - final ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); - - User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId())); - if (user == null) { - e.setHasPermission(false); - return; - } - - Contexts contexts = plugin.getContextManager().getApplicableContexts(player); - Tristate result = user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_PERMISSION_CHECK); - if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { - return; // just use the result provided by the proxy when the event was created - } - - e.setHasPermission(result.asBoolean()); - } - - @EventHandler(priority = EventPriority.HIGH) - public void onPlayerTristateCheck(TristateCheckEvent e) { - if (!(e.getSender() instanceof ProxiedPlayer)) { - return; - } - - final ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); - - User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId())); - if (user == null) { - e.setResult(Tristate.UNDEFINED); - return; - } - - Contexts contexts = plugin.getContextManager().getApplicableContexts(player); - Tristate result = user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_LOOKUP_CHECK); - if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { - return; // just use the result provided by the proxy when the event was created - } - - e.setResult(result); - } - } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java new file mode 100644 index 00000000..2b1a0e61 --- /dev/null +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java @@ -0,0 +1,93 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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.bungee.listeners; + +import lombok.RequiredArgsConstructor; + +import me.lucko.luckperms.api.Contexts; +import me.lucko.luckperms.api.Tristate; +import me.lucko.luckperms.bungee.LPBungeePlugin; +import me.lucko.luckperms.bungee.event.TristateCheckEvent; +import me.lucko.luckperms.common.config.ConfigKeys; +import me.lucko.luckperms.common.model.User; +import me.lucko.luckperms.common.verbose.CheckOrigin; + +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PermissionCheckEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.event.EventPriority; + +@RequiredArgsConstructor +public class BungeePermissionCheckListener implements Listener { + private final LPBungeePlugin plugin; + + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerPermissionCheck(PermissionCheckEvent e) { + if (!(e.getSender() instanceof ProxiedPlayer)) { + return; + } + + final ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); + + User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId())); + if (user == null) { + e.setHasPermission(false); + return; + } + + Contexts contexts = plugin.getContextManager().getApplicableContexts(player); + Tristate result = user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_PERMISSION_CHECK); + if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { + return; // just use the result provided by the proxy when the event was created + } + + e.setHasPermission(result.asBoolean()); + } + + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerTristateCheck(TristateCheckEvent e) { + if (!(e.getSender() instanceof ProxiedPlayer)) { + return; + } + + final ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); + + User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId())); + if (user == null) { + e.setResult(Tristate.UNDEFINED); + return; + } + + Contexts contexts = plugin.getContextManager().getApplicableContexts(player); + Tristate result = user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_LOOKUP_CHECK); + if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { + return; // just use the result provided by the proxy when the event was created + } + + e.setResult(result); + } +} diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingFactory.java b/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingFactory.java index b70abf7f..4bb355c8 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingFactory.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingFactory.java @@ -26,7 +26,7 @@ package me.lucko.luckperms.bungee.messaging; import me.lucko.luckperms.bungee.LPBungeePlugin; -import me.lucko.luckperms.common.messaging.InternalMessagingService; +import me.lucko.luckperms.common.messaging.ExtendedMessagingService; import me.lucko.luckperms.common.messaging.MessagingFactory; public class BungeeMessagingFactory extends MessagingFactory { @@ -35,7 +35,7 @@ public class BungeeMessagingFactory extends MessagingFactory { } @Override - protected InternalMessagingService getServiceFor(String messagingType) { + protected ExtendedMessagingService getServiceFor(String messagingType) { if (messagingType.equals("bungee")) { BungeeMessagingService bungeeMessaging = new BungeeMessagingService(getPlugin()); bungeeMessaging.init(); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingService.java b/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingService.java index ce7e8347..34079111 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingService.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/BungeeMessagingService.java @@ -31,6 +31,7 @@ import com.google.common.io.ByteStreams; import me.lucko.luckperms.bungee.LPBungeePlugin; import me.lucko.luckperms.common.messaging.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.ExtendedMessagingService; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -39,7 +40,7 @@ import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; /** - * 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 Listener { private final LPBungeePlugin plugin; @@ -60,7 +61,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements } @Override - protected void sendMessage(String channel, String message) { + protected void sendMessage(String message) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(message); @@ -68,7 +69,7 @@ public class BungeeMessagingService extends AbstractMessagingService implements byte[] data = out.toByteArray(); for (ServerInfo server : plugin.getProxy().getServers().values()) { - server.sendData(channel, data, true); + server.sendData(CHANNEL, data, true); } } @@ -87,9 +88,9 @@ public class BungeeMessagingService extends AbstractMessagingService implements ByteArrayDataInput in = ByteStreams.newDataInput(e.getData()); String msg = in.readUTF(); - onMessage(e.getTag(), msg, u -> { + onMessage(msg, u -> { // Forward to other servers - plugin.doAsync(() -> sendMessage(CHANNEL, u)); + plugin.getScheduler().doAsync(() -> sendMessage(u)); }); } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/RedisBungeeMessagingService.java b/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/RedisBungeeMessagingService.java index 84caee58..3c02dad8 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/RedisBungeeMessagingService.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/messaging/RedisBungeeMessagingService.java @@ -31,12 +31,13 @@ import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent; import me.lucko.luckperms.bungee.LPBungeePlugin; import me.lucko.luckperms.common.messaging.AbstractMessagingService; +import me.lucko.luckperms.common.messaging.ExtendedMessagingService; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; /** - * An implementation of {@link me.lucko.luckperms.api.MessagingService} using Redis, via RedisBungee's API. + * An implementation of {@link ExtendedMessagingService} using Redis, via RedisBungee's API. */ public class RedisBungeeMessagingService extends AbstractMessagingService implements Listener { private final LPBungeePlugin plugin; @@ -63,12 +64,16 @@ public class RedisBungeeMessagingService extends AbstractMessagingService implem } @Override - protected void sendMessage(String channel, String message) { - redisBungee.sendChannelMessage(channel, message); + protected void sendMessage(String message) { + redisBungee.sendChannelMessage(CHANNEL, message); } @EventHandler public void onMessage(PubSubMessageEvent e) { - onMessage(e.getChannel(), e.getMessage(), null); + if (!e.getChannel().equals(CHANNEL)) { + return; + } + + onMessage(e.getMessage(), null); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java b/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java index 2ae492aa..db1b6927 100644 --- a/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java +++ b/common/src/main/java/me/lucko/luckperms/common/actionlog/LogDispatcher.java @@ -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 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 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 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)); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java index 3babfac5..0d90cd79 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/ApiProvider.java @@ -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 getMessagingService() { - InternalMessagingService service = plugin.getMessagingService(); - return service instanceof NoopMessagingService ? Optional.empty() : Optional.of(service); + return plugin.getMessagingService().map(Function.identity()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java b/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java index 70915b7e..afa8f1c5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java +++ b/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java @@ -32,7 +32,7 @@ public class UpdateTaskBuffer extends BufferedRequest { private final LuckPermsPlugin plugin; public UpdateTaskBuffer(LuckPermsPlugin plugin) { - super(250L, 50L, plugin::doAsync); + super(250L, 50L, plugin.getScheduler().async()); this.plugin = plugin; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java index f02cdeb1..b8e7b501 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/abstraction/SubCommand.java @@ -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 extends Command { } if (!sender.isImport()) { - InternalMessagingService messagingService = plugin.getMessagingService(); - if (!(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) { - messagingService.getUpdateBuffer().request(); + Optional 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 extends Command { } if (!sender.isImport()) { - InternalMessagingService messagingService = plugin.getMessagingService(); - if (!(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) { - messagingService.getUpdateBuffer().request(); + Optional 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 extends Command { } if (!sender.isImport()) { - InternalMessagingService messagingService = plugin.getMessagingService(); - if (!(messagingService instanceof NoopMessagingService) && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) { - messagingService.getUpdateBuffer().request(); + Optional messagingService = plugin.getMessagingService(); + if (messagingService.isPresent() && plugin.getConfiguration().get(ConfigKeys.AUTO_PUSH_UPDATES)) { + messagingService.get().getUpdateBuffer().request(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java index b4df5b45..3724a4bf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddChatMeta.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java index 1f1b1c11..addc3a69 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaAddTempChatMeta.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java index ac438ceb..9ab8a283 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveChatMeta.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java index 08c5dfc3..2f8ec82a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaRemoveTempChatMeta.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java index 8408f78a..9a761502 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaSetTemp.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java index 7aa40270..0dc1b5b1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/meta/MetaUnsetTemp.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderShowTracks.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderShowTracks.java index 74d9d7f2..e1128c9d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderShowTracks.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/other/HolderShowTracks.java @@ -46,7 +46,7 @@ import java.util.stream.Collectors; public class HolderShowTracks extends SubCommand { 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java index e35edfd5..fea4004a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentAddTemp.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java index 6f7e7927..ab1a6d29 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/parent/ParentRemoveTemp.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java index c16dec4a..ca3f740b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionSetTemp.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java index 481a93f1..45380ef6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionUnsetTemp.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java index d48011f5..4b2e41bc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupListMembers.java @@ -67,7 +67,7 @@ import java.util.stream.Collectors; public class GroupListMembers extends SubCommand { 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupSetWeight.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupSetWeight.java index 3e6df627..70cc3a6f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupSetWeight.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/group/GroupSetWeight.java @@ -44,7 +44,7 @@ import java.util.List; public class GroupSetWeight extends SubCommand { 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java index 4f4e48a2..e03fe43e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java @@ -76,11 +76,11 @@ public class CheckCommand extends SingleCommand { @Override public List tabComplete(LuckPermsPlugin plugin, Sender sender, List 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); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ExportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ExportCommand.java index 2e770dd7..20d46928 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ExportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ExportCommand.java @@ -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 { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ImportCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ImportCommand.java index 986fb610..f2c992d7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ImportCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/ImportCommand.java @@ -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 { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java index 11d6135f..7e600a2c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/InfoCommand.java @@ -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(), diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java index 4a6bfdd2..0ad76783 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/NetworkSyncCommand.java @@ -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 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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java index abf4238c..51cc7164 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserMainCommand.java @@ -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 { @@ -143,6 +144,6 @@ public class UserMainCommand extends MainCommand { @Override protected List getTargets(LuckPermsPlugin plugin) { - return plugin.getPlayerList(); + return plugin.getPlayerList().collect(Collectors.toList()); } } \ No newline at end of file diff --git a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java index 999136f2..049e5624 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java @@ -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, Optional> { // 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, Optional> cache = Caffeine.newBuilder().build(this::loadKeyValue); + @Getter(AccessLevel.NONE) + private final LoadingCache, Optional> 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 loadKeyValue(ConfigKey key) { - return Optional.ofNullable(key.get(this)); + @Override + public Optional load(ConfigKey key) { + return Optional.ofNullable(key.get(adapter)); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java index 79babef2..8f5729c2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java @@ -38,9 +38,9 @@ public interface ConfigKey { *

The {@link LuckPermsConfiguration#get(ConfigKey)} method should be used to * retrieve the value, as opposed to calling this directly.

* - * @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); } diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/NoopMessagingService.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigurationAdapter.java similarity index 67% rename from common/src/main/java/me/lucko/luckperms/common/messaging/NoopMessagingService.java rename to common/src/main/java/me/lucko/luckperms/common/config/ConfigurationAdapter.java index af81e16b..6d456f70 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/NoopMessagingService.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigurationAdapter.java @@ -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 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 getList(String path, List def); + + List getObjectList(String path, List def); + + Map getMap(String path, Map def); - } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java index 79e12d8b..6a996a06 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/LuckPermsConfiguration.java @@ -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 get(ConfigKey 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 getList(String path, List def); - - List getObjectList(String path, List def); - - Map getMap(String path, Map def); - } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/AbstractKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/AbstractKey.java index 8b979765..489d65ba 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/AbstractKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/AbstractKey.java @@ -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 implements ConfigKey { - private final Function function; + private final Function function; @Override - public T get(LuckPermsConfiguration config) { - return function.apply(config); + public T get(ConfigurationAdapter adapter) { + return function.apply(adapter); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java index 1d80c4d9..837d93c7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java @@ -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 { @@ -36,7 +36,7 @@ public class BooleanKey implements ConfigKey { 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); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java index d75b4ae0..ad0f381e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java @@ -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 { @@ -36,7 +36,7 @@ public class IntegerKey implements ConfigKey { 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); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java index 7b5d01c4..80a2212c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java @@ -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 { @@ -36,7 +36,7 @@ public class LowercaseStringKey implements ConfigKey { 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(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java index 7f7b1a4b..b8327afb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java @@ -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> { private final String path; @Override - public Map get(LuckPermsConfiguration config) { - return ImmutableMap.copyOf(config.getMap(path, ImmutableMap.of())); + public Map get(ConfigurationAdapter adapter) { + return ImmutableMap.copyOf(adapter.getMap(path, ImmutableMap.of())); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/StaticKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/StaticKey.java index 315841a3..2dd9b193 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/StaticKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/StaticKey.java @@ -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 implements ConfigKey { private final T val; @Override - public T get(LuckPermsConfiguration config) { + public T get(ConfigurationAdapter adapter) { return val; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java index bb16c705..e38463a5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java @@ -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 { @@ -36,7 +36,7 @@ public class StringKey implements ConfigKey { 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); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/CommandPermission.java b/common/src/main/java/me/lucko/luckperms/common/constants/CommandPermission.java index 7caf8aad..ee4843d8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/CommandPermission.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/CommandPermission.java @@ -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), diff --git a/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventBus.java b/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventBus.java index 39fe3278..5477c37e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventBus.java +++ b/common/src/main/java/me/lucko/luckperms/common/event/LuckPermsEventBus.java @@ -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)); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/GenericUserManager.java b/common/src/main/java/me/lucko/luckperms/common/managers/GenericUserManager.java index 35b01adb..e44c998f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/managers/GenericUserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/managers/GenericUserManager.java @@ -113,12 +113,10 @@ public class GenericUserManager extends AbstractManager im @Override public CompletableFuture 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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java b/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java index 84f4e2a8..4d28c875 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/AbstractMessagingService.java @@ -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 callback) { - if (!channel.equals(CHANNEL)) { - return; - } + protected abstract void sendMessage(String message); + protected void onMessage(String msg, Consumer 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 { public PushUpdateBuffer(LuckPermsPlugin plugin) { - super(3000L, 200L, plugin::doAsync); + super(3000L, 200L, plugin.getScheduler().async()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java b/common/src/main/java/me/lucko/luckperms/common/messaging/ExtendedMessagingService.java similarity index 96% rename from common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java rename to common/src/main/java/me/lucko/luckperms/common/messaging/ExtendedMessagingService.java index 5d69a17d..425f5439 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/InternalMessagingService.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/ExtendedMessagingService.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java b/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java index 41f20850..5c69b858 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/MessagingFactory.java @@ -38,28 +38,28 @@ public class MessagingFactory

{ @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); diff --git a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessagingService.java b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessagingService.java index 662a5856..e0d2b3db 100644 --- a/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessagingService.java +++ b/common/src/main/java/me/lucko/luckperms/common/messaging/RedisMessagingService.java @@ -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); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/model/User.java b/common/src/main/java/me/lucko/luckperms/common/model/User.java index e596f9b2..43faef68 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/User.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/User.java @@ -68,10 +68,10 @@ public class User extends PermissionHolder implements Identifiable refreshBuffer = new UserRefreshBuffer(this); + private BufferedRequest refreshBuffer; @Getter private final UserDelegate delegate = new UserDelegate(this); @@ -80,16 +80,22 @@ public class User extends PermissionHolder implements Identifiable { 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; } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java index dc7e4670..dfb20310 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java @@ -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 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 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 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 getPlayerList(); + Stream getPlayerList(); /** * Gets the UUIDs of the users online on the platform * * @return a {@link Set} of UUIDs */ - Set getOnlinePlayers(); + Stream 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 getOnlineSenders(); + Stream getOnlineSenders(); /** * Gets the console. diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsScheduler.java b/common/src/main/java/me/lucko/luckperms/common/plugin/SchedulerAdapter.java similarity index 98% rename from common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsScheduler.java rename to common/src/main/java/me/lucko/luckperms/common/plugin/SchedulerAdapter.java index b3f21926..1236d96b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsScheduler.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/SchedulerAdapter.java @@ -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 diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java index 502e9f0c..c6b8ff3f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java @@ -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()) diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java index 2b03e15e..c6a17048 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java @@ -161,12 +161,11 @@ public class MongoDao extends AbstractDao { try { MongoCollection 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()); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java index 4b763bf8..7865ecba 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java @@ -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()); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index d7f67263..1e470690 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -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 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 getMessagingService() { + return Optional.ofNullable(messagingService); + } + + public Optional 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 getPlayerList() { - return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()) : new ArrayList<>(); + public Stream getPlayerList() { + return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getName) : Stream.empty(); } @Override - public Set getOnlinePlayers() { - return game.isServerAvailable() ? game.getServer().getOnlinePlayers().stream().map(Player::getUniqueId).collect(Collectors.toSet()) : new HashSet<>(); + public Stream 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 getOnlineSenders() { + public Stream 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()); - } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java similarity index 79% rename from sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java rename to sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java index 000f3eed..981705ce 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommand.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCommandExecutor.java @@ -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 processArgs(CommandSource source, String s) { - List args = Util.stripQuotes(Splitter.on(COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(s)); - - // resolve selectors - ListIterator 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 arguments = processSelectors(source, Util.stripQuotes(ARGUMENT_SPLITTER.splitToList(s))); + + onCommand(lpSender, "lp", arguments); return CommandResult.success(); } @Override - public List getSuggestions(CommandSource source, String s, @Nullable Location location) throws CommandException { - return onTabComplete(plugin.getSenderFactory().wrap(source), processArgs(source, s)); + public List getSuggestions(CommandSource source, String s, @Nullable Location location) { + Sender lpSender = plugin.getSenderFactory().wrap(source); + List 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 processSelectors(CommandSource source, List args) { + ListIterator 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; + } + } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfigAdapter.java similarity index 97% rename from sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java rename to sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfigAdapter.java index 77af7963..7ba8e67f 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfigAdapter.java @@ -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; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeScheduler.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSchedulerAdapter.java similarity index 94% rename from sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeScheduler.java rename to sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSchedulerAdapter.java index 39fb539e..cca3d85b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeScheduler.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeSchedulerAdapter.java @@ -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 tasks = ConcurrentHashMap.newKeySet(); - public LPSpongeScheduler(LPSpongePlugin plugin) { + public SpongeSchedulerAdapter(LPSpongePlugin plugin) { this.plugin = plugin; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/SpongeCalculatorFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/SpongeCalculatorFactory.java index 2e09ad31..edd184ee 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/SpongeCalculatorFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/calculators/SpongeCalculatorFactory.java @@ -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 diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java similarity index 91% rename from sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java rename to sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java index e10fae05..51481d5c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeListener.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongeConnectionListener.java @@ -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 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)); - } - } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongePlatformListener.java b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongePlatformListener.java new file mode 100644 index 00000000..2075556d --- /dev/null +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/listeners/SpongePlatformListener.java @@ -0,0 +1,51 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * 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)); + } + } +} diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java index 30770275..24e1877a 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java @@ -198,12 +198,10 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection { @Override public CompletableFuture 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()); } /* ------------------------------------------ diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/BungeeMessagingService.java b/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/BungeeMessagingService.java index 63a6b9d4..9d7f234b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/BungeeMessagingService.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/BungeeMessagingService.java @@ -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); } } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java index 11290983..85e3c3fa 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/messaging/SpongeMessagingFactory.java @@ -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 { } @Override - protected InternalMessagingService getServiceFor(String messagingType) { + protected ExtendedMessagingService getServiceFor(String messagingType) { if (messagingType.equals("bungee")) { BungeeMessagingService bungeeMessaging = new BungeeMessagingService(getPlugin()); bungeeMessaging.init(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java index 9cc7ae25..5e59a73d 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java @@ -79,16 +79,14 @@ public class PersistedSubject implements LPSubject { .expireAfterAccess(20, TimeUnit.MINUTES) .build(lookup -> lookupOptionValue(lookup.getContexts(), lookup.getKey())); - private final BufferedRequest saveBuffer = new BufferedRequest(1000L, 500L, r -> PersistedSubject.this.service.getPlugin().doAsync(r)) { + private final BufferedRequest saveBuffer = new BufferedRequest(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; } };