Search in sources :

Example 11 with CommandManager

use of com.velocitypowered.api.command.CommandManager in project MiraiMC by DreamVoid.

the class VelocityPlugin method onProxyInitialization.

@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
    // load 阶段2
    try {
        new VelocityConfig(this).loadConfig();
        if (Config.Gen_MiraiCoreVersion.equalsIgnoreCase("latest")) {
            MiraiLoader.loadMiraiCore();
        } else {
            MiraiLoader.loadMiraiCore(Config.Gen_MiraiCoreVersion);
        }
        MiraiEvent = new MiraiEvent(this);
    } catch (Exception e) {
        getLogger().warn("An error occurred while loading plugin.");
        e.printStackTrace();
    }
    // enable
    getLogger().info("Mirai working dir: " + Config.Gen_MiraiWorkingDir);
    if (Config.Gen_AddProperties_MiraiNoDesktop)
        System.setProperty("mirai.no-desktop", "MiraiMC");
    if (Config.Gen_AddProperties_MiraiSliderCaptchaSupported)
        System.setProperty("mirai.slider.captcha.supported", "MiraiMC");
    getLogger().info("Starting Mirai-Events listener.");
    MiraiEvent.startListenEvent();
    // getLogger().info("Loading auto-login file.");
    // MiraiAutoLogin.loadFile();
    // MiraiAutoLogin.doStartUpAutoLogin(); // 服务器启动完成后执行自动登录机器人
    getLogger().info("Registering commands.");
    CommandManager manager = server.getCommandManager();
    CommandMeta mirai = manager.metaBuilder("mirai").build();
    CommandMeta miraimc = manager.metaBuilder("miraimc").build();
    CommandMeta miraiverify = manager.metaBuilder("miraiverify").build();
    manager.register(mirai, new MiraiCommand(this));
    manager.register(miraimc, new MiraiMcCommand(this));
    manager.register(miraiverify, new MiraiVerifyCommand());
    if (Config.Bot_LogEvents) {
        getLogger().info("Registering events.");
        server.getEventManager().register(this, new Events());
    }
    switch(Config.DB_Type.toLowerCase()) {
        case "sqlite":
        default:
            {
                getLogger().info("Initializing SQLite database.");
                try {
                    Utils.initializeSQLite();
                } catch (SQLException | ClassNotFoundException ex) {
                    getLogger().warn("Failed to initialize SQLite database, reason: " + ex);
                }
                break;
            }
        case "mysql":
            {
                getLogger().info("Initializing MySQL database.");
                Utils.initializeMySQL();
                break;
            }
    }
    // bStats统计
    if (Config.Gen_AllowBStats) {
        getLogger().info("Initializing bStats metrics.");
        int pluginId = 13887;
        metricsFactory.make(this, pluginId);
    }
    // 安全警告
    if (!(Config.Gen_DisableSafeWarningMessage)) {
        getLogger().warn("确保您正在使用开源的MiraiMC插件,未知来源的插件可能会盗取您的账号!");
        getLogger().warn("请始终从Github或作者指定的其他途径下载插件: https://github.com/DreamVoid/MiraiMC");
    }
    pluginContainer = server.getPluginManager().getPlugin("miraimc").orElse(null);
    getLogger().info("All tasks done. Welcome to use MiraiMC!");
}
Also used : CommandManager(com.velocitypowered.api.command.CommandManager) MiraiCommand(me.dreamvoid.miraimc.velocity.commands.MiraiCommand) MiraiMcCommand(me.dreamvoid.miraimc.velocity.commands.MiraiMcCommand) MiraiVerifyCommand(me.dreamvoid.miraimc.velocity.commands.MiraiVerifyCommand) CommandMeta(com.velocitypowered.api.command.CommandMeta) SQLException(java.sql.SQLException) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

CommandManager (com.velocitypowered.api.command.CommandManager)11 Subscribe (com.velocitypowered.api.event.Subscribe)6 CommandMeta (com.velocitypowered.api.command.CommandMeta)5 IOException (java.io.IOException)3 Inject (com.google.inject.Inject)2 CommandSource (com.velocitypowered.api.command.CommandSource)2 ProxyInitializeEvent (com.velocitypowered.api.event.proxy.ProxyInitializeEvent)2 Dependency (com.velocitypowered.api.plugin.Dependency)2 Plugin (com.velocitypowered.api.plugin.Plugin)2 PluginContainer (com.velocitypowered.api.plugin.PluginContainer)2 DataDirectory (com.velocitypowered.api.plugin.annotation.DataDirectory)2 Player (com.velocitypowered.api.proxy.Player)2 ProxyServer (com.velocitypowered.api.proxy.ProxyServer)2 File (java.io.File)2 InetAddress (java.net.InetAddress)2 Path (java.nio.file.Path)2 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 SimplePie (org.bstats.charts.SimplePie)2 Metrics (org.bstats.velocity.Metrics)2