Search in sources :

Example 1 with RefreshGameEvent

use of org.spongepowered.api.event.lifecycle.RefreshGameEvent 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)

Aggregations

NonNull (org.checkerframework.checker.nullness.qual.NonNull)1 RefreshGameEvent (org.spongepowered.api.event.lifecycle.RefreshGameEvent)1 SpongeEventManager (org.spongepowered.common.event.manager.SpongeEventManager)1 PluginContainer (org.spongepowered.plugin.PluginContainer)1