Search in sources :

Example 76 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer 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)

Example 77 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method gameInit.

@Listener
public void gameInit(GamePreInitializationEvent event) {
    logger = LoggerFactory.getLogger(pC.getName());
    instance = this;
    huskyAPI = new HuskyAPI();
    forceStopIDs.clear();
    for (PluginContainer pc : Sponge.getPluginManager().getPlugins()) {
        if (pc.getId().equalsIgnoreCase("inventorytweaks") || pc.getId().equalsIgnoreCase("inventorysorter") || pc.getId().equalsIgnoreCase("mousetweaks")) {
            forceStopIDs.add(pc.getName() + "(" + pc.getId() + ")");
            logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            logger.error(pc.getName() + " is loaded! This plugin or mod is on a blacklist for HuskyCrates, and as a result, HuskyCrates is not starting. ");
            logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            forceStop = true;
        }
    }
    if (forceStop)
        return;
    CommentedConfigurationNode conf = null;
    try {
        conf = crateConfig.load();
        if (!conf.getNode("lang").isVirtual()) {
            langData = new LangData(conf.getNode("lang"));
        } else
            logger.info("Using default lang settings.");
    } catch (Exception e) {
        crateUtilities.exceptionHandler(e);
    }
// logger.info("Let's not init VCrates here anymore. ://)");
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) LangData(com.codehusky.huskycrates.lang.LangData) SQLException(java.sql.SQLException) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) IOException(java.io.IOException) Listener(org.spongepowered.api.event.Listener)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)77 Text (org.spongepowered.api.text.Text)15 CommandResult (org.spongepowered.api.command.CommandResult)13 GenericArguments (org.spongepowered.api.command.args.GenericArguments)13 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)13 List (java.util.List)12 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)11 CommandException (org.spongepowered.api.command.CommandException)11 ArrayList (java.util.ArrayList)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)9 Sponge (org.spongepowered.api.Sponge)9 Player (org.spongepowered.api.entity.living.player.Player)8 Collection (java.util.Collection)7 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 CommandSource (org.spongepowered.api.command.CommandSource)7 GenericArguments2 (org.lanternpowered.server.command.element.GenericArguments2)6 CommandMapping (org.spongepowered.api.command.CommandMapping)6 ArgumentParseException (org.spongepowered.api.command.args.ArgumentParseException)6