Search in sources :

Example 6 with CommandContext

use of org.spongepowered.api.command.parameter.CommandContext 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 7 with CommandContext

use of org.spongepowered.api.command.parameter.CommandContext in project SpongeCommon by SpongePowered.

the class SpongeCommand method whichExecutor.

@NonNull
private CommandResult whichExecutor(final CommandContext context) {
    final CommandMapping mapping = context.requireOne(this.commandMappingKey);
    context.sendMessage(Identity.nil(), Component.text().append(this.title("Aliases: "), Component.join(JoinConfiguration.separator(Component.text(", ")), mapping.allAliases().stream().map(x -> Component.text(x, NamedTextColor.YELLOW)).collect(Collectors.toList())), Component.newline(), this.title("Owned by: "), this.hl(mapping.plugin().map(x -> x.metadata().name().orElseGet(() -> x.metadata().id())).orElse("unknown"))).build());
    return CommandResult.success();
}
Also used : 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) CommandMapping(org.spongepowered.api.command.manager.CommandMapping) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Identity (net.kyori.adventure.identity.Identity)7 Component (net.kyori.adventure.text.Component)7 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)7 ResourceKey (org.spongepowered.api.ResourceKey)7 Sponge (org.spongepowered.api.Sponge)7 Command (org.spongepowered.api.command.Command)7 CommandResult (org.spongepowered.api.command.CommandResult)7 CommandContext (org.spongepowered.api.command.parameter.CommandContext)7 Parameter (org.spongepowered.api.command.parameter.Parameter)7 Collection (java.util.Collection)6 Optional (java.util.Optional)6 UUID (java.util.UUID)6 CommonParameters (org.spongepowered.api.command.parameter.CommonParameters)6 ServerWorld (org.spongepowered.api.world.server.ServerWorld)6 PluginContainer (org.spongepowered.plugin.PluginContainer)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 CompletableFuture (java.util.concurrent.CompletableFuture)5