Search in sources :

Example 1 with CommandManager

use of org.spongepowered.api.command.CommandManager in project ChangeSkin by games647.

the class ChangeSkinSponge method onInit.

@Listener
public void onInit(GameInitializationEvent initEvent) {
    if (!initialized)
        return;
    CommandManager cmdManager = Sponge.getCommandManager();
    // command and event register
    cmdManager.register(this, injector.getInstance(SelectCommand.class).buildSpec(), "skin-select", "skinselect");
    cmdManager.register(this, injector.getInstance(InfoCommand.class).buildSpec(), "skin-info");
    cmdManager.register(this, injector.getInstance(UploadCommand.class).buildSpec(), "skin-upload");
    cmdManager.register(this, injector.getInstance(SetCommand.class).buildSpec(), "changeskin", "setskin", "skin");
    cmdManager.register(this, injector.getInstance(InvalidateCommand.class).buildSpec(), "skininvalidate", "skin-invalidate");
    Sponge.getEventManager().registerListeners(this, injector.getInstance(LoginListener.class));
    RawDataChannel pluginChannel = Sponge.getChannelRegistrar().createRawChannel(this, PomData.ARTIFACT_ID);
    pluginChannel.addListener(injector.getInstance(BungeeListener.class));
}
Also used : CommandManager(org.spongepowered.api.command.CommandManager) RawDataChannel(org.spongepowered.api.network.ChannelBinding.RawDataChannel) Listener(org.spongepowered.api.event.Listener)

Example 2 with CommandManager

use of org.spongepowered.api.command.CommandManager in project SpongeForge by SpongePowered.

the class SpongeMod method onServerStopped.

@Subscribe
public void onServerStopped(FMLServerStoppedEvent event) throws IOException {
    try {
        CommandManager service = this.game.getCommandManager();
        service.getCommands().stream().filter(mapping -> mapping.getCallable() instanceof MinecraftCommandWrapper).forEach(service::removeMapping);
        ((SqlServiceImpl) this.game.getServiceManager().provideUnchecked(SqlService.class)).close();
    } catch (Throwable t) {
        this.controller.errorOccurred(this, t);
    }
    // used by client
    WorldManager.unregisterAllWorldSettings();
}
Also used : SpongeProfession(org.spongepowered.common.entity.SpongeProfession) IMixinVillagerProfession(org.spongepowered.mod.interfaces.IMixinVillagerProfession) EntityEntry(net.minecraftforge.fml.common.registry.EntityEntry) SpongeModPluginContainer(org.spongepowered.mod.plugin.SpongeModPluginContainer) Inject(com.google.inject.Inject) ChunkTicketManager(org.spongepowered.api.world.ChunkTicketManager) SpongeModule(org.spongepowered.common.inject.SpongeModule) SpongePermissionService(org.spongepowered.common.service.permission.SpongePermissionService) Type(org.objectweb.asm.Type) PermissionService(org.spongepowered.api.service.permission.PermissionService) SpongePlayerDataHandler(org.spongepowered.common.world.storage.SpongePlayerDataHandler) MinecraftServer(net.minecraft.server.MinecraftServer) Side(net.minecraftforge.fml.relauncher.Side) RegistryEvent(net.minecraftforge.event.RegistryEvent) DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) StaticMixinForgeHelper(org.spongepowered.mod.util.StaticMixinForgeHelper) FMLConstructionEvent(net.minecraftforge.fml.common.event.FMLConstructionEvent) NbtDataUtil(org.spongepowered.common.data.util.NbtDataUtil) SpongeEventHooks(org.spongepowered.mod.event.SpongeEventHooks) IMixinServerCommandManager(org.spongepowered.common.interfaces.IMixinServerCommandManager) SpongeChunkTicketManager(org.spongepowered.mod.service.world.SpongeChunkTicketManager) SoundType(org.spongepowered.api.effect.sound.SoundType) SpongeGameData(org.spongepowered.mod.registry.SpongeGameData) ModContainerFactory(net.minecraftforge.fml.common.ModContainerFactory) Sponge(org.spongepowered.api.Sponge) MinecraftCommandWrapper(org.spongepowered.common.command.MinecraftCommandWrapper) SqlService(org.spongepowered.api.service.sql.SqlService) SpongeGuice(org.spongepowered.common.inject.SpongeGuice) ForgeModContainer(net.minecraftforge.common.ForgeModContainer) FMLLoadCompleteEvent(net.minecraftforge.fml.common.event.FMLLoadCompleteEvent) Stage(com.google.inject.Stage) SpongeModMessageHandler(org.spongepowered.mod.network.SpongeModMessageHandler) SpongeBootstrap(org.spongepowered.common.SpongeBootstrap) SpongeForgeModuleRegistry(org.spongepowered.mod.registry.SpongeForgeModuleRegistry) FMLFileResourcePack(net.minecraftforge.fml.client.FMLFileResourcePack) CraftingRecipe(org.spongepowered.api.item.recipe.crafting.CraftingRecipe) BlockType(org.spongepowered.api.block.BlockType) CommandManager(org.spongepowered.api.command.CommandManager) SpongeScheduler(org.spongepowered.common.scheduler.SpongeScheduler) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) SpongeImpl(org.spongepowered.common.SpongeImpl) SpongeForgeModule(org.spongepowered.mod.inject.SpongeForgeModule) SqlServiceImpl(org.spongepowered.common.service.sql.SqlServiceImpl) Min(com.flowpowered.noise.module.combiner.Min) PotionEffectType(org.spongepowered.api.effect.potion.PotionEffectType) ProfessionRegistryModule(org.spongepowered.common.registry.type.entity.ProfessionRegistryModule) SpongeContextCalculator(org.spongepowered.common.service.permission.SpongeContextCalculator) EnchantmentType(org.spongepowered.api.item.enchantment.EnchantmentType) SpongeCraftingRecipeRegistry(org.spongepowered.common.item.recipe.crafting.SpongeCraftingRecipeRegistry) FMLPostInitializationEvent(net.minecraftforge.fml.common.event.FMLPostInitializationEvent) SpongeInternalListeners(org.spongepowered.common.SpongeInternalListeners) EventBus(com.google.common.eventbus.EventBus) FMLServerStoppedEvent(net.minecraftforge.fml.common.event.FMLServerStoppedEvent) Minecraft(net.minecraft.client.Minecraft) BlockTypeRegistryModule(org.spongepowered.common.registry.type.BlockTypeRegistryModule) FMLPreInitializationEvent(net.minecraftforge.fml.common.event.FMLPreInitializationEvent) Subscribe(com.google.common.eventbus.Subscribe) LoadController(net.minecraftforge.fml.common.LoadController) FMLInitializationEvent(net.minecraftforge.fml.common.event.FMLInitializationEvent) SoundRegistryModule(org.spongepowered.common.registry.type.effect.SoundRegistryModule) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) PluginContainer(org.spongepowered.api.plugin.PluginContainer) PotionEffectTypeRegistryModule(org.spongepowered.common.registry.type.effect.PotionEffectTypeRegistryModule) IMixinBlock(org.spongepowered.common.interfaces.block.IMixinBlock) IRecipe(net.minecraft.item.crafting.IRecipe) Logger(org.slf4j.Logger) Event(org.spongepowered.api.event.Event) SpongeHooks(org.spongepowered.common.util.SpongeHooks) WorldManager(org.spongepowered.common.world.WorldManager) IOException(java.io.IOException) SpongeEntityAICommonSuperclass(org.spongepowered.common.entity.ai.SpongeEntityAICommonSuperclass) EntityTypeRegistryModule(org.spongepowered.common.registry.type.entity.EntityTypeRegistryModule) File(java.io.File) FMLFolderResourcePack(net.minecraftforge.fml.client.FMLFolderResourcePack) SpongeGame(org.spongepowered.common.SpongeGame) ItemTypeRegistryModule(org.spongepowered.common.registry.type.ItemTypeRegistryModule) Plugin(org.spongepowered.api.plugin.Plugin) MinecraftForge(net.minecraftforge.common.MinecraftForge) FMLServerStartedEvent(net.minecraftforge.fml.common.event.FMLServerStartedEvent) MetaModContainer(org.spongepowered.mod.plugin.MetaModContainer) Launch(net.minecraft.launchwrapper.Launch) ForgeRegistries(net.minecraftforge.fml.common.registry.ForgeRegistries) EnchantmentRegistryModule(org.spongepowered.common.registry.type.item.EnchantmentRegistryModule) IntegratedServer(net.minecraft.server.integrated.IntegratedServer) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) Guice(com.google.inject.Guice) FMLStateEvent(net.minecraftforge.fml.common.event.FMLStateEvent) Preconditions(com.google.common.base.Preconditions) FMLServerAboutToStartEvent(net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent) VillagerRegistry(net.minecraftforge.fml.common.registry.VillagerRegistry) ItemType(org.spongepowered.api.item.ItemType) SpongeForgeVillagerRegistry(org.spongepowered.mod.registry.SpongeForgeVillagerRegistry) EntityRegistry(net.minecraftforge.fml.common.registry.EntityRegistry) IMixinServerCommandManager(org.spongepowered.common.interfaces.IMixinServerCommandManager) CommandManager(org.spongepowered.api.command.CommandManager) SqlServiceImpl(org.spongepowered.common.service.sql.SqlServiceImpl) SqlService(org.spongepowered.api.service.sql.SqlService) MinecraftCommandWrapper(org.spongepowered.common.command.MinecraftCommandWrapper) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with CommandManager

use of org.spongepowered.api.command.CommandManager in project Nucleus by NucleusPowered.

the class InfoCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    // Sponge versions
    List<String> information = Lists.newArrayList();
    String separator = "------------";
    information.add(separator);
    information.add("Nucleus Diagnostics");
    information.add(separator);
    information.add("This file contains information about Nucleus and the environment it runs in.");
    information.add(separator);
    information.add("Environment");
    information.add(separator);
    Platform platform = Sponge.getPlatform();
    PluginContainer game = platform.getContainer(Platform.Component.GAME);
    PluginContainer implementation = platform.getContainer(Platform.Component.IMPLEMENTATION);
    PluginContainer api = platform.getContainer(Platform.Component.API);
    information.add(String.format("Minecraft Version: %s %s", game.getName(), game.getVersion().orElse("unknown")));
    information.add(String.format("Sponge Version: %s %s", implementation.getName(), implementation.getVersion().orElse("unknown")));
    information.add(String.format("Sponge API Version: %s %s", api.getName(), api.getVersion().orElse("unknown")));
    information.add("Nucleus Version: " + PluginInfo.VERSION + " (Git: " + PluginInfo.GIT_HASH + ")");
    information.add(separator);
    information.add("Plugins");
    information.add(separator);
    Sponge.getPluginManager().getPlugins().forEach(x -> information.add(x.getName() + " (" + x.getId() + ") version " + x.getVersion().orElse("unknown")));
    information.add(separator);
    information.add("Registered Commands");
    information.add(separator);
    final Map<String, String> commands = Maps.newHashMap();
    final Map<String, String> plcmds = Maps.newHashMap();
    final CommandManager manager = Sponge.getCommandManager();
    manager.getPrimaryAliases().forEach(x -> {
        Optional<? extends CommandMapping> ocm = manager.get(x);
        if (ocm.isPresent()) {
            Set<String> a = ocm.get().getAllAliases();
            Optional<PluginContainer> optionalPC = manager.getOwner(ocm.get());
            if (optionalPC.isPresent()) {
                PluginContainer container = optionalPC.get();
                String id = container.getId();
                String info = " - " + container.getName() + " (" + id + ") version " + container.getVersion().orElse("unknown");
                a.forEach(y -> {
                    if (y.startsWith(id + ":")) {
                        // /nucleus:<blah>
                        plcmds.put(y, "/" + y + info);
                    } else {
                        commands.put(y, "/" + y + info);
                    }
                });
            } else {
                String info = " - unknown (plugin container not present)";
                a.forEach(y -> commands.put(y, "/" + y + info));
            }
        } else {
            commands.put(x, "/" + x + " - unknown (mapping not present)");
        }
    });
    commands.entrySet().stream().sorted(Comparator.comparing(x -> x.getKey().toLowerCase())).forEachOrdered(x -> information.add(x.getValue()));
    information.add(separator);
    information.add("Namespaced commands");
    information.add(separator);
    plcmds.entrySet().stream().sorted(Comparator.comparing(x -> x.getKey().toLowerCase())).forEachOrdered(x -> information.add(x.getValue()));
    information.add(separator);
    information.add("Nucleus: Enabled Modules");
    information.add(separator);
    plugin.getModuleContainer().getModules().stream().sorted().forEach(information::add);
    Set<String> disabled = plugin.getModuleContainer().getModules(ModuleContainer.ModuleStatusTristate.DISABLE);
    if (!disabled.isEmpty()) {
        information.add(separator);
        information.add("Nucleus: Disabled Modules");
        information.add(separator);
        disabled.stream().sorted().forEach(information::add);
    }
    String fileName = "nucleus-info-" + DateTimeFormatter.BASIC_ISO_DATE.format(LocalDateTime.now()) + "-" + DateTimeFormatter.ofPattern("HHmmss").format(LocalDateTime.now()) + ".txt";
    try (BufferedWriter fw = new BufferedWriter(new FileWriter(fileName, false))) {
        for (String s : information) {
            fw.write(s);
            fw.newLine();
        }
        fw.flush();
    } catch (Exception e) {
        throw new TextMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.info.fileerror"), e);
    }
    src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.info.saved", fileName));
    return CommandResult.success();
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) Platform(org.spongepowered.api.Platform) FileWriter(java.io.FileWriter) TextMessageException(org.spongepowered.api.util.TextMessageException) BufferedWriter(java.io.BufferedWriter) CommandManager(org.spongepowered.api.command.CommandManager) TextMessageException(org.spongepowered.api.util.TextMessageException)

Aggregations

CommandManager (org.spongepowered.api.command.CommandManager)3 PluginContainer (org.spongepowered.api.plugin.PluginContainer)2 Min (com.flowpowered.noise.module.combiner.Min)1 Preconditions (com.google.common.base.Preconditions)1 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 Guice (com.google.inject.Guice)1 Inject (com.google.inject.Inject)1 Stage (com.google.inject.Stage)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Minecraft (net.minecraft.client.Minecraft)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 Launch (net.minecraft.launchwrapper.Launch)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 DedicatedServer (net.minecraft.server.dedicated.DedicatedServer)1 IntegratedServer (net.minecraft.server.integrated.IntegratedServer)1 ResourceLocation (net.minecraft.util.ResourceLocation)1