Search in sources :

Example 1 with CommandPermission

use of me.lucko.luckperms.common.command.access.CommandPermission in project LuckPerms by lucko.

the class LPBukkitPlugin method performFinalSetup.

@Override
protected void performFinalSetup() {
    // register permissions
    try {
        PluginManager pm = this.bootstrap.getServer().getPluginManager();
        PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE;
        for (CommandPermission p : CommandPermission.values()) {
            pm.addPermission(new Permission(p.getPermission(), permDefault));
        }
    } catch (Exception e) {
    // this throws an exception if the plugin is /reloaded, grr
    }
    if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
        this.bootstrap.getScheduler().doSync(() -> this.bootstrap.getServer().getOperators().forEach(o -> o.setOp(false)));
    }
    // replace the temporary executor when the Bukkit one starts
    this.bootstrap.getServer().getScheduler().runTaskAsynchronously(this.bootstrap, () -> this.bootstrap.getScheduler().setUseFallback(false));
    // Load any online users (in the case of a reload)
    for (Player player : this.bootstrap.getServer().getOnlinePlayers()) {
        this.bootstrap.getScheduler().doAsync(() -> {
            try {
                User user = this.connectionListener.loadUser(player.getUniqueId(), player.getName());
                if (user != null) {
                    this.bootstrap.getScheduler().doSync(() -> {
                        try {
                            LPPermissible lpPermissible = new LPPermissible(player, user, this);
                            PermissibleInjector.inject(player, lpPermissible);
                        } catch (Throwable t) {
                            t.printStackTrace();
                        }
                    });
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) ContextManager(me.lucko.luckperms.common.contexts.ContextManager) Arrays(java.util.Arrays) BukkitContextManager(me.lucko.luckperms.bukkit.contexts.BukkitContextManager) Contexts(me.lucko.luckperms.api.Contexts) Player(org.bukkit.entity.Player) StandardGroupManager(me.lucko.luckperms.common.managers.group.StandardGroupManager) LPSubscriptionMap(me.lucko.luckperms.bukkit.model.server.LPSubscriptionMap) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) InjectorDefaultsMap(me.lucko.luckperms.bukkit.model.server.InjectorDefaultsMap) ExpireTemporaryTask(me.lucko.luckperms.common.tasks.ExpireTemporaryTask) ConnectionListener(me.lucko.luckperms.common.listener.ConnectionListener) LPPermissible(me.lucko.luckperms.bukkit.model.permissible.LPPermissible) Map(java.util.Map) CacheHousekeepingTask(me.lucko.luckperms.common.tasks.CacheHousekeepingTask) AbstractLuckPermsPlugin(me.lucko.luckperms.common.plugin.AbstractLuckPermsPlugin) StandardTrackManager(me.lucko.luckperms.common.managers.track.StandardTrackManager) StandardUserManager(me.lucko.luckperms.common.managers.user.StandardUserManager) PlatformCalculatorFactory(me.lucko.luckperms.common.calculators.PlatformCalculatorFactory) BukkitConnectionListener(me.lucko.luckperms.bukkit.listeners.BukkitConnectionListener) LPPermissionMap(me.lucko.luckperms.bukkit.model.server.LPPermissionMap) BukkitMessagingFactory(me.lucko.luckperms.bukkit.messaging.BukkitMessagingFactory) MessagingFactory(me.lucko.luckperms.common.messaging.MessagingFactory) ServicePriority(org.bukkit.plugin.ServicePriority) VaultHookManager(me.lucko.luckperms.bukkit.vault.VaultHookManager) LPDefaultsMap(me.lucko.luckperms.bukkit.model.server.LPDefaultsMap) PermissionDefault(org.bukkit.permissions.PermissionDefault) InjectorSubscriptionMap(me.lucko.luckperms.bukkit.model.server.InjectorSubscriptionMap) ConfigurationAdapter(me.lucko.luckperms.common.config.adapter.ConfigurationAdapter) PermissibleInjector(me.lucko.luckperms.bukkit.model.permissible.PermissibleInjector) Sender(me.lucko.luckperms.common.sender.Sender) PluginCommand(org.bukkit.command.PluginCommand) File(java.io.File) Permission(org.bukkit.permissions.Permission) BukkitPlatformListener(me.lucko.luckperms.bukkit.listeners.BukkitPlatformListener) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Stream(java.util.stream.Stream) InjectorPermissionMap(me.lucko.luckperms.bukkit.model.server.InjectorPermissionMap) LuckPermsApi(me.lucko.luckperms.api.LuckPermsApi) BukkitCalculatorFactory(me.lucko.luckperms.bukkit.calculators.BukkitCalculatorFactory) Optional(java.util.Optional) PermissibleMonitoringInjector(me.lucko.luckperms.bukkit.model.permissible.PermissibleMonitoringInjector) WorldCalculator(me.lucko.luckperms.bukkit.contexts.WorldCalculator) User(me.lucko.luckperms.common.model.User) PluginManager(org.bukkit.plugin.PluginManager) LPPermissible(me.lucko.luckperms.bukkit.model.permissible.LPPermissible) Player(org.bukkit.entity.Player) User(me.lucko.luckperms.common.model.User) PermissionDefault(org.bukkit.permissions.PermissionDefault) Permission(org.bukkit.permissions.Permission) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission)

Example 2 with CommandPermission

use of me.lucko.luckperms.common.command.access.CommandPermission in project LuckPerms by lucko.

the class CommandManager method sendCommandUsage.

private void sendCommandUsage(Sender sender, String label) {
    MessageUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + this.plugin.getBootstrap().getVersion() + "&2.");
    this.mainCommands.stream().filter(Command::shouldDisplay).filter(c -> c.isAuthorized(sender)).forEach(c -> {
        @SuppressWarnings("unchecked") String permission = (String) c.getPermission().map(p -> ((CommandPermission) p).getPermission()).orElse("None");
        TextComponent component = TextUtils.fromLegacy("&3> &a" + String.format(c.getUsage(), label), AMPERSAND_CHAR).toBuilder().applyDeep(comp -> {
            comp.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&bCommand: &2" + c.getName(), "&bDescription: &2" + c.getDescription(), "&bUsage: &2" + String.format(c.getUsage(), label), "&bPermission: &2" + permission, " ", "&7Click to auto-complete."), AMPERSAND_CHAR)));
            comp.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format(c.getUsage(), label)));
        }).build();
        sender.sendMessage(component);
    });
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) InfoCommand(me.lucko.luckperms.common.commands.misc.InfoCommand) BulkUpdateCommand(me.lucko.luckperms.common.commands.misc.BulkUpdateCommand) ListGroups(me.lucko.luckperms.common.commands.group.ListGroups) ListIterator(java.util.ListIterator) TextUtils(me.lucko.luckperms.common.utils.TextUtils) ImportCommand(me.lucko.luckperms.common.commands.misc.ImportCommand) HoverEvent(net.kyori.text.event.HoverEvent) ExportCommand(me.lucko.luckperms.common.commands.misc.ExportCommand) CheckCommand(me.lucko.luckperms.common.commands.misc.CheckCommand) EditorCommand(me.lucko.luckperms.common.commands.misc.EditorCommand) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) VerboseCommand(me.lucko.luckperms.common.commands.misc.VerboseCommand) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) ListTracks(me.lucko.luckperms.common.commands.track.ListTracks) UUID(java.util.UUID) TextComponent(net.kyori.text.TextComponent) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) List(java.util.List) CreateTrack(me.lucko.luckperms.common.commands.track.CreateTrack) Optional(java.util.Optional) TreeCommand(me.lucko.luckperms.common.commands.misc.TreeCommand) Pattern(java.util.regex.Pattern) DeleteGroup(me.lucko.luckperms.common.commands.group.DeleteGroup) MigrationMainCommand(me.lucko.luckperms.common.commands.migration.MigrationMainCommand) TrackMainCommand(me.lucko.luckperms.common.commands.track.TrackMainCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) CompletableFuture(java.util.concurrent.CompletableFuture) LogMainCommand(me.lucko.luckperms.common.commands.log.LogMainCommand) Command(me.lucko.luckperms.common.command.abstraction.Command) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) SearchCommand(me.lucko.luckperms.common.commands.misc.SearchCommand) DebugCommand(me.lucko.luckperms.common.commands.misc.DebugCommand) ImmutableList(com.google.common.collect.ImmutableList) UserMainCommand(me.lucko.luckperms.common.commands.user.UserMainCommand) ClickEvent(net.kyori.text.event.ClickEvent) SyncCommand(me.lucko.luckperms.common.commands.misc.SyncCommand) ExecutorService(java.util.concurrent.ExecutorService) CreateGroup(me.lucko.luckperms.common.commands.group.CreateGroup) ApplyEditsCommand(me.lucko.luckperms.common.commands.misc.ApplyEditsCommand) NetworkSyncCommand(me.lucko.luckperms.common.commands.misc.NetworkSyncCommand) Executor(java.util.concurrent.Executor) Sender(me.lucko.luckperms.common.sender.Sender) ReloadConfigCommand(me.lucko.luckperms.common.commands.misc.ReloadConfigCommand) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) GroupMainCommand(me.lucko.luckperms.common.commands.group.GroupMainCommand) DeleteTrack(me.lucko.luckperms.common.commands.track.DeleteTrack) Collections(java.util.Collections) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) InfoCommand(me.lucko.luckperms.common.commands.misc.InfoCommand) BulkUpdateCommand(me.lucko.luckperms.common.commands.misc.BulkUpdateCommand) ImportCommand(me.lucko.luckperms.common.commands.misc.ImportCommand) ExportCommand(me.lucko.luckperms.common.commands.misc.ExportCommand) CheckCommand(me.lucko.luckperms.common.commands.misc.CheckCommand) EditorCommand(me.lucko.luckperms.common.commands.misc.EditorCommand) VerboseCommand(me.lucko.luckperms.common.commands.misc.VerboseCommand) TreeCommand(me.lucko.luckperms.common.commands.misc.TreeCommand) MigrationMainCommand(me.lucko.luckperms.common.commands.migration.MigrationMainCommand) TrackMainCommand(me.lucko.luckperms.common.commands.track.TrackMainCommand) LogMainCommand(me.lucko.luckperms.common.commands.log.LogMainCommand) Command(me.lucko.luckperms.common.command.abstraction.Command) SearchCommand(me.lucko.luckperms.common.commands.misc.SearchCommand) DebugCommand(me.lucko.luckperms.common.commands.misc.DebugCommand) UserMainCommand(me.lucko.luckperms.common.commands.user.UserMainCommand) SyncCommand(me.lucko.luckperms.common.commands.misc.SyncCommand) ApplyEditsCommand(me.lucko.luckperms.common.commands.misc.ApplyEditsCommand) NetworkSyncCommand(me.lucko.luckperms.common.commands.misc.NetworkSyncCommand) ReloadConfigCommand(me.lucko.luckperms.common.commands.misc.ReloadConfigCommand) GroupMainCommand(me.lucko.luckperms.common.commands.group.GroupMainCommand) ClickEvent(net.kyori.text.event.ClickEvent)

Example 3 with CommandPermission

use of me.lucko.luckperms.common.command.access.CommandPermission in project LuckPerms by lucko.

the class LPNukkitPlugin method performFinalSetup.

@Override
protected void performFinalSetup() {
    // register permissions
    try {
        PluginManager pm = this.bootstrap.getServer().getPluginManager();
        PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE;
        for (CommandPermission p : CommandPermission.values()) {
            pm.addPermission(new Permission(p.getPermission(), null, permDefault.toString()));
        }
    } catch (Exception e) {
    // this throws an exception if the plugin is /reloaded, grr
    }
    if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
        Config ops = this.bootstrap.getServer().getOps();
        ops.getKeys(false).forEach(ops::remove);
    }
    // replace the temporary executor when the Nukkit one starts
    this.bootstrap.getServer().getScheduler().scheduleTask(this.bootstrap, () -> this.bootstrap.getScheduler().setUseFallback(false), true);
    // Load any online users (in the case of a reload)
    for (Player player : this.bootstrap.getServer().getOnlinePlayers().values()) {
        this.bootstrap.getScheduler().doAsync(() -> {
            try {
                User user = this.connectionListener.loadUser(player.getUniqueId(), player.getName());
                if (user != null) {
                    this.bootstrap.getScheduler().doSync(() -> {
                        try {
                            LPPermissible lpPermissible = new LPPermissible(player, user, this);
                            PermissibleInjector.inject(player, lpPermissible);
                        } catch (Throwable t) {
                            t.printStackTrace();
                        }
                    });
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
Also used : PluginManager(cn.nukkit.plugin.PluginManager) LPPermissible(me.lucko.luckperms.nukkit.model.permissible.LPPermissible) Player(cn.nukkit.Player) User(me.lucko.luckperms.common.model.User) PermissionDefault(me.lucko.luckperms.nukkit.model.PermissionDefault) Config(cn.nukkit.utils.Config) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) Permission(cn.nukkit.permission.Permission) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission)

Aggregations

CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)3 Optional (java.util.Optional)2 Player (cn.nukkit.Player)1 Permission (cn.nukkit.permission.Permission)1 PluginManager (cn.nukkit.plugin.PluginManager)1 Config (cn.nukkit.utils.Config)1 ImmutableList (com.google.common.collect.ImmutableList)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Executor (java.util.concurrent.Executor)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Pattern (java.util.regex.Pattern)1