Search in sources :

Example 21 with PluginContainer

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

the class SpongeCommand method pluginsListSubcommand.

@NonNull
private CommandResult pluginsListSubcommand(final CommandContext context) {
    final Collection<PluginContainer> plugins = Launch.instance().pluginManager().plugins();
    context.sendMessage(Identity.nil(), this.title("Plugins (" + plugins.size() + ")"));
    for (final PluginContainer specificContainer : plugins) {
        final PluginMetadata metadata = specificContainer.metadata();
        final TextComponent.Builder builder = Component.text();
        this.createShortContainerMeta(builder.append(SpongeCommand.INDENT_COMPONENT), metadata);
        builder.clickEvent(SpongeComponents.executeCallback(cause -> cause.sendMessage(Identity.nil(), this.createContainerMeta(metadata))));
        context.sendMessage(Identity.nil(), builder.build());
    }
    return CommandResult.success();
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) RefreshGameEvent(org.spongepowered.api.event.lifecycle.RefreshGameEvent) ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) Command(org.spongepowered.api.command.Command) URL(java.net.URL) SpongeGameConfigs(org.spongepowered.common.config.SpongeGameConfigs) ItemStack(org.spongepowered.api.item.inventory.ItemStack) PluginMetadata(org.spongepowered.plugin.metadata.PluginMetadata) Method(java.lang.reflect.Method) LinearComponents(net.kyori.adventure.text.LinearComponents) TextComponent(net.kyori.adventure.text.TextComponent) TextColor(net.kyori.adventure.text.format.TextColor) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Collection(java.util.Collection) Launch(org.spongepowered.common.launch.Launch) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Keys(org.spongepowered.api.data.Keys) List(java.util.List) Optional(java.util.Optional) JoinConfiguration(net.kyori.adventure.text.JoinConfiguration) Player(org.spongepowered.api.entity.living.player.Player) HoverEvent(net.kyori.adventure.text.event.HoverEvent) ServerLocation(org.spongepowered.api.world.server.ServerLocation) PluginContributor(org.spongepowered.plugin.metadata.model.PluginContributor) Timings(co.aikar.timings.Timings) NonNull(org.checkerframework.checker.nullness.qual.NonNull) ServerWorld(org.spongepowered.api.world.server.ServerWorld) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) ClickEvent(net.kyori.adventure.text.event.ClickEvent) ServerLevel(net.minecraft.server.level.ServerLevel) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Style(net.kyori.adventure.text.format.Style) SpongeEventManager(org.spongepowered.common.event.manager.SpongeEventManager) Parameter(org.spongepowered.api.command.parameter.Parameter) Component(net.kyori.adventure.text.Component) MBeanServer(javax.management.MBeanServer) ResourceKey(org.spongepowered.api.ResourceKey) RayTrace(org.spongepowered.api.util.blockray.RayTrace) ManagementFactory(java.lang.management.ManagementFactory) Nullable(org.checkerframework.checker.nullness.qual.Nullable) CommonParameters(org.spongepowered.api.command.parameter.CommonParameters) CommandResult(org.spongepowered.api.command.CommandResult) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Identity(net.kyori.adventure.identity.Identity) TextDecoration(net.kyori.adventure.text.format.TextDecoration) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) DecimalFormat(java.text.DecimalFormat) SpongeCommon(org.spongepowered.common.SpongeCommon) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) File(java.io.File) SpongeTimingsFactory(co.aikar.timings.sponge.SpongeTimingsFactory) CommandMapping(org.spongepowered.api.command.manager.CommandMapping) Entity(net.minecraft.world.entity.Entity) PluginContainer(org.spongepowered.plugin.PluginContainer) DateTimeFormatter(java.time.format.DateTimeFormatter) SpongeConfigs(org.spongepowered.common.applaunch.config.core.SpongeConfigs) CommandContext(org.spongepowered.api.command.parameter.CommandContext) SpongeComponents(org.spongepowered.api.adventure.SpongeComponents) Mth(net.minecraft.util.Mth) PluginContainer(org.spongepowered.plugin.PluginContainer) PluginMetadata(org.spongepowered.plugin.metadata.PluginMetadata) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 22 with PluginContainer

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

the class PluginScreen method init.

@Override
protected void init() {
    Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(true);
    final int listHeight = this.height - 122;
    this.selectionList = new PluginSelectionList(this, 4, 58, 175, listHeight, 26);
    this.contentPanel = new MetadataPanel(this.minecraft, this, this.width - this.selectionList.getWidth() - 12, listHeight, 58, this.selectionList.getRight() + 4);
    // Add plugin list
    this.selectionList.setSelectConsumer(e -> this.contentPanel.setMetadata(e == null ? null : e.metadata));
    this.generateEntries(Launch.instance().pluginManager().plugins().stream().map(PluginContainer::metadata).collect(Collectors.toList()));
    // Add search text field
    this.searchField = new EditBox(this.font, this.width / 2 - 100, 22, 200, 20, new TranslatableComponent(I18n.get("itemGroup.search")));
    this.searchField.setResponder(value -> {
        this.selectionList.setFilterSupplier(() -> {
            // Filter based on ID/Name
            final List<PluginSelectionList.Entry> filteredList = this.selectionList.children().stream().filter(entry -> entry.metadata.name().orElse("").toLowerCase(Locale.ROOT).contains(value.toLowerCase(Locale.ROOT)) || entry.metadata.id().toLowerCase(Locale.ROOT).contains(value.toLowerCase(Locale.ROOT))).collect(Collectors.toList());
            // If the current selection doesn't exist, then select what we can at the top of the filtered list
            if (!filteredList.contains(this.selectionList.getSelected())) {
                this.selectionList.setSelected(filteredList.stream().findFirst().orElse(null));
            }
            return filteredList;
        });
    });
    // Add controls
    this.children.addAll(Arrays.asList(this.selectionList, this.contentPanel, this.searchField));
    // Add the 'Done' button
    this.addButton(new Button(this.width / 2 - 50, this.height - 40, 100, 20, new TranslatableComponent(I18n.get("gui.done")), (p_214323_1_) -> Minecraft.getInstance().setScreen(this.previousScreen)));
}
Also used : Arrays(java.util.Arrays) PluginSelectionList(org.spongepowered.vanilla.client.gui.widget.list.PluginSelectionList) Widget(net.minecraft.client.gui.components.Widget) Collection(java.util.Collection) Screen(net.minecraft.client.gui.screens.Screen) Launch(org.spongepowered.common.launch.Launch) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) MetadataPanel(org.spongepowered.vanilla.client.gui.widget.MetadataPanel) Collectors(java.util.stream.Collectors) PoseStack(com.mojang.blaze3d.vertex.PoseStack) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) I18n(net.minecraft.client.resources.language.I18n) PluginContainer(org.spongepowered.plugin.PluginContainer) PluginMetadata(org.spongepowered.plugin.metadata.PluginMetadata) Minecraft(net.minecraft.client.Minecraft) Locale(java.util.Locale) EditBox(net.minecraft.client.gui.components.EditBox) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Button(net.minecraft.client.gui.components.Button) PluginContainer(org.spongepowered.plugin.PluginContainer) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Button(net.minecraft.client.gui.components.Button) MetadataPanel(org.spongepowered.vanilla.client.gui.widget.MetadataPanel) EditBox(net.minecraft.client.gui.components.EditBox) PluginSelectionList(org.spongepowered.vanilla.client.gui.widget.list.PluginSelectionList)

Aggregations

PluginContainer (org.spongepowered.plugin.PluginContainer)22 NonNull (org.checkerframework.checker.nullness.qual.NonNull)6 Collection (java.util.Collection)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Component (net.kyori.adventure.text.Component)4 EventManager (org.spongepowered.api.event.EventManager)4 PluginMetadata (org.spongepowered.plugin.metadata.PluginMetadata)4 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 Identity (net.kyori.adventure.identity.Identity)3 TextComponent (net.kyori.adventure.text.TextComponent)3 Nullable (org.checkerframework.checker.nullness.qual.Nullable)3 Test (org.junit.jupiter.api.Test)3 Sponge (org.spongepowered.api.Sponge)3 Command (org.spongepowered.api.command.Command)3 CommandResult (org.spongepowered.api.command.CommandResult)3 Parameter (org.spongepowered.api.command.parameter.Parameter)3 RefreshGameEvent (org.spongepowered.api.event.lifecycle.RefreshGameEvent)3 SpongeEventManager (org.spongepowered.common.event.manager.SpongeEventManager)3