Search in sources :

Example 16 with PluginContainer

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

the class SpongePlatform method createPlatformMetadata.

protected void createPlatformMetadata() {
    final PluginContainer apiPlugin = Launch.instance().apiPlugin();
    final PluginContainer commonPlugin = Launch.instance().commonPlugin();
    final PluginContainer platformPlugin = Launch.instance().platformPlugin();
    this.platformMap.put("Type", this.type());
    this.platformMap.put("APIName", apiPlugin.metadata().name());
    this.platformMap.put("APIVersion", apiPlugin.metadata().version());
    this.platformMap.put("CommonName", commonPlugin.metadata().name());
    this.platformMap.put("CommonVersion", commonPlugin.metadata().version());
    this.platformMap.put("PlatformName", platformPlugin.metadata().name());
    this.platformMap.put("PlatformVersion", platformPlugin.metadata().version());
    this.platformMap.put("MinecraftVersion", this.minecraftVersion());
}
Also used : PluginContainer(org.spongepowered.plugin.PluginContainer)

Example 17 with PluginContainer

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

the class SpongeCommand method pluginsInfoSubcommand.

@NonNull
private CommandResult pluginsInfoSubcommand(final CommandContext context) {
    final PluginContainer pluginContainer = context.requireOne(this.pluginContainerKey);
    context.sendMessage(Identity.nil(), this.createContainerMeta(pluginContainer.metadata()));
    return CommandResult.success();
}
Also used : PluginContainer(org.spongepowered.plugin.PluginContainer) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 18 with PluginContainer

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

the class SpongeCommand method pluginsRefreshSubcommandExecutor.

@NonNull
private CommandResult pluginsRefreshSubcommandExecutor(final CommandContext context) {
    final Optional<PluginContainer> pluginContainer = context.one(this.pluginContainerKey);
    final RefreshGameEvent event = SpongeEventFactory.createRefreshGameEvent(PhaseTracker.getCauseStackManager().currentCause(), SpongeCommon.game());
    if (pluginContainer.isPresent()) {
        // just send the reload event to that
        context.sendMessage(Identity.nil(), Component.text("Sending refresh event to " + pluginContainer.get().metadata().id() + ", please wait..."));
        ((SpongeEventManager) SpongeCommon.game().eventManager()).postToPlugin(event, pluginContainer.get());
    } else {
        context.sendMessage(Identity.nil(), Component.text("Sending refresh event to all plugins, please wait..."));
        SpongeCommon.game().eventManager().post(event);
    }
    context.sendMessage(Identity.nil(), Component.text("Completed plugin refresh."));
    return CommandResult.success();
}
Also used : PluginContainer(org.spongepowered.plugin.PluginContainer) SpongeEventManager(org.spongepowered.common.event.manager.SpongeEventManager) RefreshGameEvent(org.spongepowered.api.event.lifecycle.RefreshGameEvent) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 19 with PluginContainer

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

the class SpongeCommand method versionExecutor.

@NonNull
private CommandResult versionExecutor(final CommandContext context) {
    if (this.versionText == null) {
        final PluginContainer platformPlugin = Launch.instance().platformPlugin();
        final TextComponent.Builder builder = Component.text().append(Component.text(platformPlugin.metadata().name().get(), Style.style(NamedTextColor.YELLOW, TextDecoration.BOLD)));
        final Component colon = Component.text(": ", NamedTextColor.GRAY);
        for (final PluginContainer container : Launch.instance().launcherPlugins()) {
            final PluginMetadata metadata = container.metadata();
            builder.append(Component.newline(), SpongeCommand.INDENT_COMPONENT, Component.text(metadata.name().orElseGet(metadata::id), NamedTextColor.GRAY), colon, Component.text(container.metadata().version().toString()));
        }
        final String arch = System.getProperty("sun.arch.data.model");
        final String javaArch = arch != null ? arch + "-bit" : "UNKNOWN";
        final String javaVendor = System.getProperty("java.vendor");
        final String javaVersion = System.getProperty("java.version");
        final String osName = System.getProperty("os.name");
        final String osVersion = System.getProperty("os.version");
        final String osArch = System.getProperty("os.arch");
        builder.append(Component.newline(), SpongeCommand.INDENT_COMPONENT, Component.text("JVM", NamedTextColor.GRAY), colon, Component.text(javaVersion + "/" + javaArch + " (" + javaVendor + ")"), Component.newline(), SpongeCommand.INDENT_COMPONENT, Component.text("OS", NamedTextColor.GRAY), colon, Component.text(osName + "/" + osVersion + " (" + osArch + ")"));
        this.versionText = builder.build();
    }
    context.sendMessage(Identity.nil(), this.versionText);
    return CommandResult.success();
}
Also used : TextComponent(net.kyori.adventure.text.TextComponent) PluginContainer(org.spongepowered.plugin.PluginContainer) PluginMetadata(org.spongepowered.plugin.metadata.PluginMetadata) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 20 with PluginContainer

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

the class SpongeCommand method rootCommand.

@NonNull
private CommandResult rootCommand(final CommandContext context) {
    final PluginContainer platformPlugin = Launch.instance().platformPlugin();
    final PluginContainer apiPlugin = Launch.instance().apiPlugin();
    final PluginContainer minecraftPlugin = Launch.instance().minecraftPlugin();
    context.sendMessage(Identity.nil(), Component.text().append(Component.text("SpongePowered", NamedTextColor.YELLOW, TextDecoration.BOLD).append(Component.space()), Component.text("Plugin Platform (running on Minecraft " + minecraftPlugin.metadata().version() + ")"), Component.newline(), Component.text(apiPlugin.metadata().name().get() + ": " + apiPlugin.metadata().version()), Component.newline(), Component.text(platformPlugin.metadata().name().get() + ": " + platformPlugin.metadata().version())).build());
    final Optional<Command.Parameterized> parameterized = context.executedCommand();
    if (parameterized.isPresent()) {
        final String subcommands = parameterized.get().subcommands().stream().filter(x -> x.command().canExecute(context.cause())).flatMap(x -> x.aliases().stream()).collect(Collectors.joining(", "));
        if (!subcommands.isEmpty()) {
            context.sendMessage(Identity.nil(), Component.text().append(Component.newline(), Component.text("Available subcommands:"), Component.newline(), Component.text(subcommands)).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) PluginContainer(org.spongepowered.plugin.PluginContainer) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

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