Search in sources :

Example 51 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeForge by SpongePowered.

the class SpongeModNetworkManager method createRawChannel.

@Override
public RawDataChannel createRawChannel(Object plugin, String channelName) throws ChannelRegistrationException {
    SpongeRawChannel channel;
    PluginContainer pluginContainer = checkCreateChannelArgs(plugin, channelName);
    try {
        channel = new SpongeRawChannel(this, channelName, pluginContainer);
    } catch (Exception e) {
        throw new ChannelRegistrationException("Error registering channel \"" + channelName + "\" to " + pluginContainer, e);
    }
    return this.registerChannel(channel);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException)

Example 52 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeForge by SpongePowered.

the class SpongeModNetworkManager method createChannel.

@Override
public IndexedMessageChannel createChannel(Object plugin, String channelName) throws ChannelRegistrationException {
    SpongeIndexedMessageChannel channel;
    PluginContainer pluginContainer = checkCreateChannelArgs(plugin, channelName);
    try {
        channel = new SpongeIndexedMessageChannel(this, channelName, pluginContainer);
    } catch (Exception e) {
        throw new ChannelRegistrationException("Error registering channel \"" + channelName + "\" to " + pluginContainer, e);
    }
    return this.registerChannel(channel);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException)

Example 53 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project SpongeForge by SpongePowered.

the class SpongeModPluginContainer method constructMod.

@Subscribe
public void constructMod(FMLConstructionEvent event) {
    try {
        if (this.invalid) {
            throw new InvalidPluginException();
        }
        // Add source file to classloader so we can load it.
        ModClassLoader modClassLoader = event.getModClassLoader();
        modClassLoader.addFile(getSource());
        modClassLoader.clearNegativeCacheFor(this.candidate.getClassList());
        Class<?> pluginClazz = Class.forName(this.className, true, modClassLoader);
        Injector injector = spongeInjector.getParent().createChildInjector(new PluginModule((PluginContainer) this, pluginClazz));
        this.injector = injector;
        this.instance = injector.getInstance(pluginClazz);
        // TODO: Detect Scala or use meta to know if we're scala and use proper adapter here...
        ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), new ILanguageAdapter.JavaAdapter());
        Sponge.getEventManager().registerListeners(this, this.instance);
    } catch (Throwable t) {
        this.controller.errorOccurred(this, t);
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ModClassLoader(net.minecraftforge.fml.common.ModClassLoader) ProxyInjector(net.minecraftforge.fml.common.ProxyInjector) Injector(com.google.inject.Injector) ILanguageAdapter(net.minecraftforge.fml.common.ILanguageAdapter) PluginModule(org.spongepowered.common.inject.plugin.PluginModule) Subscribe(com.google.common.eventbus.Subscribe)

Example 54 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project core by CubeEngine.

the class CubeCommandManager method registerSpongeCommand.

private Optional<CommandMapping> registerSpongeCommand(CommandDescriptor descriptor) {
    ArrayList<String> aliasList = new ArrayList<>();
    aliasList.add(descriptor.getName().toLowerCase());
    for (AliasConfiguration alias : descriptor.getAliases()) {
        if ((alias.getDispatcher() == null || (alias.getDispatcher() != null && alias.getDispatcher().length == 0))) {
            aliasList.add(alias.getName().toLowerCase());
        }
    }
    PluginContainer plugin = mm.getPlugin(descriptor.getOwner()).orElse(mm.getPlugin(LibCube.class).get());
    return baseDispatcher.register(plugin, new ProxyCallable(this, commandTime, descriptor.getName(), logger), aliasList);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ArrayList(java.util.ArrayList) AliasConfiguration(org.cubeengine.butler.alias.AliasConfiguration)

Example 55 with PluginContainer

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

the class CommandWhitelist method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.child(CommandSpec.builder().arguments(GenericArguments.string(Text.of("player"))).executor((src, args) -> {
        final String playerName = args.<String>getOne("player").get();
        final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
        Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
            if (error != null) {
                src.sendMessage(t("commands.whitelist.add.failed", playerName));
            } else {
                src.sendMessage(t("commands.whitelist.add.success", playerName));
                service.addProfile(((LanternGameProfile) profile).withoutProperties());
            }
        });
        return CommandResult.success();
    }).build(), "add").child(CommandSpec.builder().arguments(GenericArguments.string(Text.of("player"))).executor((src, args) -> {
        final String playerName = args.<String>getOne("player").get();
        final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
        Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
            if (error != null || !service.isWhitelisted(profile = ((LanternGameProfile) profile).withoutProperties())) {
                src.sendMessage(t("commands.whitelist.remove.failed", playerName));
            } else {
                src.sendMessage(t("commands.whitelist.remove.success", playerName));
                service.removeProfile(profile);
            }
        });
        return CommandResult.success();
    }).build(), "remove").child(CommandSpec.builder().executor((src, args) -> {
        final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
        final List<String> whitelisted = service.getWhitelistedProfiles().stream().map(p -> p.getName().get()).collect(Collectors.toList());
        src.sendMessage(t("commands.whitelist.list", whitelisted.size(), Sponge.getServer().getOnlinePlayers().size()));
        src.sendMessage(Text.of(Joiner.on(", ").join(whitelisted)));
        return CommandResult.success();
    }).build(), "list").child(CommandSpec.builder().executor((src, args) -> {
        Lantern.getGame().getGlobalConfig().setWhitelistEnabled(true);
        src.sendMessage(t("commands.whitelist.enabled"));
        return CommandResult.success();
    }).build(), "on").child(CommandSpec.builder().executor((src, args) -> {
        Lantern.getGame().getGlobalConfig().setWhitelistEnabled(false);
        src.sendMessage(t("commands.whitelist.disabled"));
        return CommandResult.success();
    }).build(), "off").child(CommandSpec.builder().executor((src, args) -> {
        final WhitelistService service = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
        if (service instanceof Reloadable) {
            try {
                ((Reloadable) service).reload();
            } catch (Exception e) {
                throw new CommandException(t("commands.whitelist.reload.failed", e.getMessage()), e);
            }
        } else {
            src.sendMessage(t("commands.whitelist.reload.not_supported"));
            return CommandResult.empty();
        }
        return CommandResult.success();
    }).build(), "reload");
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) Sponge(org.spongepowered.api.Sponge) GenericArguments(org.spongepowered.api.command.args.GenericArguments) Collectors(java.util.stream.Collectors) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) WhitelistService(org.spongepowered.api.service.whitelist.WhitelistService) CommandException(org.spongepowered.api.command.CommandException) List(java.util.List) Text(org.spongepowered.api.text.Text) Lantern(org.lanternpowered.server.game.Lantern) Reloadable(org.lanternpowered.server.util.Reloadable) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Joiner(com.google.common.base.Joiner) WhitelistService(org.spongepowered.api.service.whitelist.WhitelistService) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) List(java.util.List) CommandException(org.spongepowered.api.command.CommandException) Reloadable(org.lanternpowered.server.util.Reloadable) CommandException(org.spongepowered.api.command.CommandException)

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