Search in sources :

Example 36 with PluginContainer

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

the class LanternPluginManager method loadPlugin.

private void loadPlugin(PluginCandidate candidate) {
    final String id = candidate.getId();
    final LanternClassLoader classLoader = LanternClassLoader.get();
    if (candidate.getSource().isPresent()) {
        try {
            classLoader.addBaseURL(candidate.getSource().get().toUri().toURL());
        } catch (MalformedURLException e) {
            throw new RuntimeException("Failed to add plugin '" + id + "' from " + candidate.getDisplaySource() + " to classpath", e);
        }
    }
    final PluginMetadata metadata = candidate.getMetadata();
    checkNotNull(metadata, "metadata");
    final String name = firstNonNull(metadata.getName(), id);
    final String version = firstNonNull(metadata.getVersion(), "unknown");
    try {
        final Class<?> pluginClass = Class.forName(candidate.getPluginClass());
        final PluginContainer container = new LanternPluginContainer(id, this.injector, pluginClass, metadata, candidate.getSource().orElse(null));
        registerPlugin(container);
        registerPluginInstance(container);
        this.eventManager.registerListeners(container, container.getInstance().get());
        this.logger.info("Loaded plugin: {} {} (from {})", name, version, candidate.getDisplaySource());
    } catch (Throwable e) {
        this.logger.error("Failed to load plugin: {} {} (from {})", name, version, candidate.getDisplaySource(), e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) LanternClassLoader(org.lanternpowered.launch.LanternClassLoader) PluginContainer(org.spongepowered.api.plugin.PluginContainer) PluginMetadata(org.spongepowered.plugin.meta.PluginMetadata)

Example 37 with PluginContainer

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

the class LanternTaskBuilder method submit.

@Override
public Task submit(Object plugin) {
    final PluginContainer pluginContainer = checkPlugin(plugin, "plugin");
    checkState(this.consumer != null, "consumer not set");
    final String name;
    if (this.name == null) {
        name = this.scheduler.getNameFor(pluginContainer, this.syncType);
    } else {
        name = this.name;
    }
    long delay = this.delay;
    long interval = this.interval;
    boolean delayIsTicks = this.delayIsTicks;
    boolean intervalIsTicks = this.intervalIsTicks;
    if (this.syncType == ScheduledTask.TaskSynchronicity.ASYNCHRONOUS) {
        delay = delayIsTicks ? delay * LanternGame.TICK_DURATION_NS : delay;
        interval = intervalIsTicks ? interval * LanternGame.TICK_DURATION_NS : interval;
        delayIsTicks = intervalIsTicks = false;
    }
    ScheduledTask task = new ScheduledTask(this.syncType, this.consumer, name, delay, delayIsTicks, interval, intervalIsTicks, pluginContainer);
    this.scheduler.submit(task);
    return task;
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 38 with PluginContainer

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

the class SimpleDispatcher method process.

@Override
public CommandResult process(CommandSource source, String commandLine) throws CommandException {
    final String[] argSplit = commandLine.split(" ", 2);
    Optional<CommandMapping> cmdOptional = get(argSplit[0], source);
    if (!cmdOptional.isPresent()) {
        // TODO: Fix properly to use a SpongeTranslation??
        throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]);
    }
    final String arguments = argSplit.length > 1 ? argSplit[1] : "";
    CommandMapping mapping = cmdOptional.get();
    Optional<PluginContainer> pluginOwner = Sponge.getCommandManager().getOwner(mapping);
    if (pluginOwner.isPresent()) {
        Sponge.getCauseStackManager().pushCause(pluginOwner.get());
    }
    final CommandCallable spec = mapping.getCallable();
    try {
        return spec.process(source, arguments);
    } catch (CommandNotFoundException e) {
        throw new CommandException(t("No such child command: %s", e.getCommand()));
    } finally {
        if (pluginOwner.isPresent()) {
            Sponge.getCauseStackManager().popCause();
        }
    }
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ImmutableCommandMapping(org.spongepowered.api.command.ImmutableCommandMapping) CommandMapping(org.spongepowered.api.command.CommandMapping) CommandException(org.spongepowered.api.command.CommandException) CommandNotFoundException(org.spongepowered.api.command.CommandNotFoundException) CommandCallable(org.spongepowered.api.command.CommandCallable)

Example 39 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project Almura by AlmuraDev.

the class SimpleAboutMenu method construct.

@SuppressWarnings({ "unchecked" })
@Override
public void construct() {
    super.construct();
    this.list = new BasicList<>(this, 125, UIComponent.INHERITED);
    this.list.setPosition(4, 0);
    this.list.setItemComponentSpacing(4);
    this.list.setCanDeselect(false);
    final List<AboutItemData> elementDataList = Lists.newArrayList();
    // Static entry
    elementDataList.add(new AboutItemData(this.list, new UIImage(this, new GuiTexture(GuiConfig.Location.ALMURA_MAN), null), 5, 0, 23, 32, 8, AboutConfig.TITLE, AboutConfig.STORY));
    // Dynamic entry
    AboutConfig.ENTRIES.forEach(entry -> {
        Text titles = Text.EMPTY;
        for (final String title : entry.titles) {
            titles = titles.toBuilder().append(Text.of("  • ", I18n.format(title)), Text.NEW_LINE).build();
        }
        elementDataList.add(new AboutItemData(this.list, new UIImage(this, new GuiRemoteTexture(GuiConfig.Location.GENERIC_AVATAR, new ResourceLocation(Almura.ID, "textures/gui/skins/avatars/" + entry.uniqueId + ".png"), String.format(GuiConfig.Url.SKINS, entry.uniqueId, 32), 32, 32), null), 2, 0, 32, 32, 4, Text.of(entry.color, I18n.format(entry.name)), Text.of(TextColors.WHITE, I18n.format(entry.description), Text.NEW_LINE, Text.NEW_LINE, TextStyles.BOLD, I18n.format("almura.menu.about.titles"), TextStyles.RESET, TextColors.RESET, Text.NEW_LINE, titles)));
    });
    final UIButton doneButton = new UIButtonBuilder(this).text(I18n.format("gui.done")).size(98, 20).position(0, -15, 1).anchor(Anchor.BOTTOM | Anchor.CENTER).listener(this).build("button.done");
    this.textField = new UITextField(this, "", true);
    this.textField.setPosition(BasicScreen.getPaddedX(this.list, 4), 0);
    this.textField.setEditable(false);
    this.textField.setFontOptions(FontOptions.builder().from(FontColors.WHITE_FO).shadow(false).build());
    this.list.setItemComponentFactory(AboutItemComponent::new);
    this.list.setItems(elementDataList);
    this.list.setSelectConsumer(i -> this.textField.setText(TextSerializers.LEGACY_FORMATTING_CODE.serialize(i.getContent())));
    this.list.setSelectedItem(elementDataList.get(0));
    this.getContainer().add(this.list, this.textField);
    // SpongeForge
    final UILabel spongeForgeVersionLabel = new UILabel(this, TextFormatting.WHITE + "SpongeForge: " + ((Optional<String>) Sponge.getPlatform().asMap().get("ImplementationVersion")).orElse("dev"));
    spongeForgeVersionLabel.setPosition(4, -24, Anchor.LEFT | Anchor.BOTTOM);
    // Forge
    final PluginContainer forgeContainer = Sponge.getPluginManager().getPlugin("Forge").orElseThrow(NullPointerException::new);
    final UILabel forgeVersionLabel = new UILabel(this, TextFormatting.WHITE + "Forge: " + forgeContainer.getVersion().orElse("dev"));
    forgeVersionLabel.setPosition(4, -14, Anchor.LEFT | Anchor.BOTTOM);
    addToScreen(forgeVersionLabel);
    // Almura
    final PluginContainer almuraContainer = Sponge.getPluginManager().getPlugin("almura").orElseThrow(NullPointerException::new);
    final UILabel almuraVersionLabel = new UILabel(this, TextFormatting.WHITE + "Almura 3.1 - " + Almura.buildNumber);
    almuraVersionLabel.setPosition(4, -4, Anchor.LEFT | Anchor.BOTTOM);
    addToScreen(almuraVersionLabel);
    addToScreen(doneButton);
    addToScreen(spongeForgeVersionLabel);
}
Also used : UILabel(net.malisis.core.client.gui.component.decoration.UILabel) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Optional(java.util.Optional) Text(org.spongepowered.api.text.Text) UITextField(net.malisis.core.client.gui.component.interaction.UITextField) GuiRemoteTexture(com.almuradev.almura.shared.client.texture.GuiRemoteTexture) GuiTexture(net.malisis.core.client.gui.GuiTexture) UIButtonBuilder(net.malisis.core.client.gui.component.interaction.button.builder.UIButtonBuilder) ResourceLocation(net.minecraft.util.ResourceLocation) UIButton(net.malisis.core.client.gui.component.interaction.UIButton) UIImage(net.malisis.core.client.gui.component.decoration.UIImage)

Example 40 with PluginContainer

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

the class SpongeCommandFactory method sendContainerMeta.

public static void sendContainerMeta(CommandSource src, CommandContext args, String argumentName) {
    for (PluginContainer container : args.<PluginContainer>getAll(argumentName)) {
        Text.Builder builder = Text.builder().append(title(container.getName()));
        container.getVersion().ifPresent(version -> builder.append(Text.of((" v" + version))));
        appendPluginMeta(builder, "ID", container.getId());
        appendPluginMeta(builder, "Description", container.getDescription());
        appendPluginMeta(builder, "URL", container.getUrl().map(url -> {
            ClickAction.OpenUrl action = null;
            try {
                // make the url clickable
                action = TextActions.openUrl(new URL(url));
            } catch (MalformedURLException e) {
            // or not
            }
            return Text.builder(url).onClick(action);
        }));
        if (!container.getAuthors().isEmpty()) {
            appendPluginMeta(builder, "Authors", String.join(", ", container.getAuthors()));
        }
        appendPluginMeta(builder, "Main class", container.getInstance().map(instance -> instance.getClass().getCanonicalName()));
        src.sendMessage(builder.build());
    }
}
Also used : IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) ClickAction(org.spongepowered.api.text.action.ClickAction) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) DimensionType(org.spongepowered.api.world.DimensionType) URL(java.net.URL) CommandCallable(org.spongepowered.api.command.CommandCallable) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) GenericArguments(org.spongepowered.api.command.args.GenericArguments) GenericArguments.choices(org.spongepowered.api.command.args.GenericArguments.choices) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinDimensionType(org.spongepowered.common.interfaces.world.IMixinDimensionType) GenericArguments.plugin(org.spongepowered.api.command.args.GenericArguments.plugin) WorldConfig(org.spongepowered.common.config.type.WorldConfig) SpongeTimingsFactory(co.aikar.timings.SpongeTimingsFactory) TextActions(org.spongepowered.api.text.action.TextActions) User(org.spongepowered.api.entity.living.player.User) GenericArguments.dimension(org.spongepowered.api.command.args.GenericArguments.dimension) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) Collection(java.util.Collection) GenericArguments.optional(org.spongepowered.api.command.args.GenericArguments.optional) Sponge(org.spongepowered.api.Sponge) Instant(java.time.Instant) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) MixinEnvironment(org.spongepowered.asm.mixin.MixinEnvironment) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) EntityUtil(org.spongepowered.common.entity.EntityUtil) BlockState(org.spongepowered.api.block.BlockState) List(java.util.List) SpongeApiTranslationHelper(org.spongepowered.api.util.SpongeApiTranslationHelper) World(org.spongepowered.api.world.World) DimensionConfig(org.spongepowered.common.config.type.DimensionConfig) CommandManager(org.spongepowered.api.command.CommandManager) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) SpongeConfig(org.spongepowered.common.config.SpongeConfig) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) SpongeImpl(org.spongepowered.common.SpongeImpl) Timings(co.aikar.timings.Timings) GenericArguments.firstParsing(org.spongepowered.api.command.args.GenericArguments.firstParsing) SpongeImplHooks(org.spongepowered.common.SpongeImplHooks) LocalDateTime(java.time.LocalDateTime) CommandMapping(org.spongepowered.api.command.CommandMapping) ArgumentParseException(org.spongepowered.api.command.args.ArgumentParseException) CommandArgs(org.spongepowered.api.command.args.CommandArgs) Function(java.util.function.Function) TreeSet(java.util.TreeSet) IMPLEMENTATION(org.spongepowered.api.Platform.Component.IMPLEMENTATION) ArrayList(java.util.ArrayList) PaginationList(org.spongepowered.api.service.pagination.PaginationList) RayTraceResult(net.minecraft.util.math.RayTraceResult) GenericArguments.seq(org.spongepowered.api.command.args.GenericArguments.seq) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) StartsWithPredicate(org.spongepowered.api.util.StartsWithPredicate) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Chunk(net.minecraft.world.chunk.Chunk) WorldServer(net.minecraft.world.WorldServer) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) GenericArguments.literal(org.spongepowered.api.command.args.GenericArguments.literal) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) GenericArguments.world(org.spongepowered.api.command.args.GenericArguments.world) Entity(net.minecraft.entity.Entity) CommandResult(org.spongepowered.api.command.CommandResult) MalformedURLException(java.net.MalformedURLException) SpongeHooks(org.spongepowered.common.util.SpongeHooks) WorldManager(org.spongepowered.common.world.WorldManager) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) GenericArguments.string(org.spongepowered.api.command.args.GenericArguments.string) DecimalFormat(java.text.DecimalFormat) BlockUtil(org.spongepowered.common.block.BlockUtil) GeneralConfigBase(org.spongepowered.common.config.type.GeneralConfigBase) File(java.io.File) CommandException(org.spongepowered.api.command.CommandException) IBlockState(net.minecraft.block.state.IBlockState) ChildCommandElementExecutor(org.spongepowered.api.command.args.ChildCommandElementExecutor) DateTimeFormatter(java.time.format.DateTimeFormatter) GenericArguments.flags(org.spongepowered.api.command.args.GenericArguments.flags) GenericArguments.optionalWeak(org.spongepowered.api.command.args.GenericArguments.optionalWeak) GlobalConfig(org.spongepowered.common.config.type.GlobalConfig) Comparator(java.util.Comparator) MalformedURLException(java.net.MalformedURLException) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Text(org.spongepowered.api.text.Text) URL(java.net.URL)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)75 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