Search in sources :

Example 56 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class DefaultCommandsCollection method load.

public void load() {
    final Multimap<PluginContainer, CommandProvider> commandProviders = HashMultimap.create();
    // Minecraft Commands
    commandProviders.put(this.minecraft, new CommandBan());
    commandProviders.put(this.minecraft, new CommandBanIp());
    commandProviders.put(this.minecraft, new CommandBorder());
    commandProviders.put(this.minecraft, new CommandDeop());
    commandProviders.put(this.minecraft, new CommandDifficulty());
    commandProviders.put(this.minecraft, new CommandGameMode());
    commandProviders.put(this.minecraft, new CommandGameRule());
    commandProviders.put(this.minecraft, new CommandHelp());
    commandProviders.put(this.minecraft, new CommandKick());
    commandProviders.put(this.minecraft, new CommandListBans());
    commandProviders.put(this.minecraft, new CommandListPlayers());
    commandProviders.put(this.minecraft, new CommandMe());
    commandProviders.put(this.minecraft, new CommandOp());
    commandProviders.put(this.minecraft, new CommandPardon());
    commandProviders.put(this.minecraft, new CommandPardonIp());
    commandProviders.put(this.minecraft, new CommandParticle());
    commandProviders.put(this.implementation, new CommandParticleEffect());
    commandProviders.put(this.minecraft, new CommandPlaySound());
    commandProviders.put(this.minecraft, new CommandSay());
    commandProviders.put(this.minecraft, new CommandScoreboard());
    commandProviders.put(this.implementation, new CommandSetData());
    commandProviders.put(this.minecraft, new CommandSetIdleTimeout());
    commandProviders.put(this.minecraft, new CommandSetSpawn());
    commandProviders.put(this.minecraft, new CommandStop());
    commandProviders.put(this.minecraft, new CommandStopSound());
    commandProviders.put(this.minecraft, new CommandTeleport());
    commandProviders.put(this.minecraft, new CommandTell());
    commandProviders.put(this.minecraft, new CommandTime());
    commandProviders.put(this.minecraft, new CommandTitle());
    commandProviders.put(this.minecraft, new CommandToggleDownfall());
    commandProviders.put(this.minecraft, new CommandTp());
    commandProviders.put(this.implementation, new CommandVersion());
    commandProviders.put(this.minecraft, new CommandWeather());
    commandProviders.put(this.minecraft, new CommandWhitelist());
    // Testing Commands
    commandProviders.put(this.implementation, new CommandOpenTestContainer());
    for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
        final PluginContainer plugin = entry.getKey();
        this.commandManager.register(plugin, entry.getValue().buildSpecFor(plugin), entry.getValue().getAliases());
    }
    final PermissionService permissionService = this.permissionService.get();
    if (permissionService instanceof LanternPermissionService) {
        final LanternPermissionService lanternPermissionService = (LanternPermissionService) permissionService;
        // noinspection Convert2streamapi
        for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
            entry.getValue().getOpPermissionLevel().ifPresent(level -> lanternPermissionService.getGroupForOpLevel(level).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE));
        }
    } else {
        // noinspection Convert2streamapi
        for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
            if (entry.getValue().getOpPermissionLevel().orElse(0) == 0) {
                permissionService.getDefaults().getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE);
            }
        }
    }
}
Also used : LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) PermissionService(org.spongepowered.api.service.permission.PermissionService) CommandOpenTestContainer(org.lanternpowered.server.command.test.CommandOpenTestContainer) PluginContainer(org.spongepowered.api.plugin.PluginContainer) LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) Map(java.util.Map)

Example 57 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternCommandManager method register.

@Override
public Optional<CommandMapping> register(Object plugin, CommandCallable callable, List<String> aliases, Function<List<String>, List<String>> callback) {
    checkNotNull(plugin, "plugin");
    Optional<PluginContainer> containerOptional = Sponge.getGame().getPluginManager().fromInstance(plugin);
    if (!containerOptional.isPresent()) {
        throw new IllegalArgumentException("The provided plugin object does not have an associated plugin container " + "(in other words, is 'plugin' actually your plugin object?");
    }
    PluginContainer container = containerOptional.get();
    synchronized (this.lock) {
        // <namespace>:<alias> for all commands
        final List<String> aliasesWithPrefix = new ArrayList<>(aliases.size() * 2);
        for (String alias : aliases) {
            final Collection<CommandMapping> ownedCommands = this.owners.get(container);
            for (CommandMapping mapping : this.dispatcher.getAll(alias)) {
                if (ownedCommands.contains(mapping)) {
                    throw new IllegalArgumentException("A plugin may not register multiple commands for the same alias ('" + alias + "')!");
                }
            }
            aliasesWithPrefix.add(alias);
            aliasesWithPrefix.add(container.getId() + ':' + alias);
        }
        final Optional<CommandMapping> mapping = this.dispatcher.register(callable, aliasesWithPrefix, callback);
        if (mapping.isPresent()) {
            this.owners.put(container, mapping.get());
            this.reverseOwners.put(mapping.get(), container);
        }
        return mapping;
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) CommandMapping(org.spongepowered.api.command.CommandMapping) ArrayList(java.util.ArrayList)

Example 58 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternConfigManager method getPluginConfig.

@Override
public ConfigRoot getPluginConfig(Object instance) {
    final PluginContainer pluginContainer = checkPlugin(instance, "instance");
    final String name = pluginContainer.getId().toLowerCase();
    return new LanternConfigRoot(getMapperFactory(pluginContainer), name, this.configFolder.resolve(name));
}
Also used : LanternPluginContainer(org.lanternpowered.server.plugin.LanternPluginContainer) PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 59 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternConfigManager method getSharedConfig.

@Override
public ConfigRoot getSharedConfig(Object instance) {
    final PluginContainer pluginContainer = checkPlugin(instance, "instance");
    final String name = pluginContainer.getId().toLowerCase();
    return new LanternConfigRoot(getMapperFactory(pluginContainer), name, this.configFolder);
}
Also used : LanternPluginContainer(org.lanternpowered.server.plugin.LanternPluginContainer) PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 60 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternSmeltingRecipeBuilder method build.

@SuppressWarnings("ConstantConditions")
@Override
public ISmeltingRecipe build(String id, Object plugin) {
    check();
    checkNotNull(id, "id");
    checkNotNull(plugin, "plugin");
    final PluginContainer container = checkPlugin(plugin, "plugin");
    final int index = id.indexOf(':');
    if (index != -1) {
        final String pluginId = id.substring(0, index);
        checkState(pluginId.equals(container.getId()), "Plugin ids mismatch, " + "found %s in the id but got %s from the container", pluginId, container.getId());
        id = id.substring(index + 1);
    }
    return build0(id, container);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)77 Text (org.spongepowered.api.text.Text)15 CommandResult (org.spongepowered.api.command.CommandResult)13 GenericArguments (org.spongepowered.api.command.args.GenericArguments)13 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)13 List (java.util.List)12 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)11 CommandException (org.spongepowered.api.command.CommandException)11 ArrayList (java.util.ArrayList)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)9 Sponge (org.spongepowered.api.Sponge)9 Player (org.spongepowered.api.entity.living.player.Player)8 Collection (java.util.Collection)7 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 CommandSource (org.spongepowered.api.command.CommandSource)7 GenericArguments2 (org.lanternpowered.server.command.element.GenericArguments2)6 CommandMapping (org.spongepowered.api.command.CommandMapping)6 ArgumentParseException (org.spongepowered.api.command.args.ArgumentParseException)6