Search in sources :

Example 1 with DiscordListener

use of net.essentialsx.discord.listeners.DiscordListener in project Essentials by drtshock.

the class JDADiscordService method startup.

public void startup() throws LoginException, InterruptedException {
    shutdown();
    invalidStartup = true;
    logger.log(Level.INFO, tl("discordLoggingIn"));
    if (plugin.getSettings().getBotToken().replace("INSERT-TOKEN-HERE", "").trim().isEmpty()) {
        throw new IllegalArgumentException(tl("discordErrorNoToken"));
    }
    jda = JDABuilder.createDefault(plugin.getSettings().getBotToken()).addEventListeners(new DiscordListener(this)).enableCache(CacheFlag.EMOTE).disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE).setContextEnabled(false).build().awaitReady();
    invalidStartup = false;
    updatePresence();
    logger.log(Level.INFO, tl("discordLoggingInDone", jda.getSelfUser().getAsTag()));
    if (jda.getGuilds().isEmpty()) {
        invalidStartup = true;
        throw new IllegalArgumentException(tl("discordErrorNoGuildSize"));
    }
    guild = jda.getGuildById(plugin.getSettings().getGuildId());
    if (guild == null) {
        invalidStartup = true;
        throw new IllegalArgumentException(tl("discordErrorNoGuild"));
    }
    interactionController = new InteractionControllerImpl(this);
    // Each will throw an exception if disabled
    try {
        interactionController.registerCommand(new ExecuteCommand(this));
    } catch (InteractionException ignored) {
    }
    try {
        interactionController.registerCommand(new MessageCommand(this));
    } catch (InteractionException ignored) {
    }
    try {
        interactionController.registerCommand(new ListCommand(this));
    } catch (InteractionException ignored) {
    }
    // Load emotes into cache, JDA will handle updates from here on out.
    guild.retrieveEmotes().queue();
    updatePrimaryChannel();
    updateConsoleRelay();
    updateTypesRelay();
    // We will see you in the future :balloon:
    // DiscordUtil.cleanWebhooks(guild, DiscordUtil.CONSOLE_RELAY_NAME);
    // DiscordUtil.cleanWebhooks(guild, DiscordUtil.ADVANCED_RELAY_NAME);
    Bukkit.getPluginManager().registerEvents(new BukkitListener(this), plugin);
    try {
        if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_12_0_R01)) {
            try {
                Class.forName("io.papermc.paper.advancement.AdvancementDisplay");
                Bukkit.getPluginManager().registerEvents(new PaperAdvancementListenerProvider(), plugin);
            } catch (ClassNotFoundException e) {
                Bukkit.getPluginManager().registerEvents(new AdvancementListenerProvider(), plugin);
            }
        } else {
            Bukkit.getPluginManager().registerEvents(new AchievementListenerProvider(), plugin);
        }
    } catch (final Throwable e) {
        logger.log(Level.WARNING, "Error while loading the achievement/advancement listener. You will not receive achievement/advancement notifications on Discord.", e);
    }
    getPlugin().getEss().scheduleSyncDelayedTask(() -> DiscordUtil.dispatchDiscordMessage(JDADiscordService.this, MessageType.DefaultTypes.SERVER_START, getSettings().getStartMessage(), true, null, null, null));
    Bukkit.getServicesManager().register(DiscordService.class, this, plugin, ServicePriority.Normal);
}
Also used : ListCommand(net.essentialsx.discord.interactions.commands.ListCommand) MessageCommand(net.essentialsx.discord.interactions.commands.MessageCommand) AchievementListenerProvider(net.ess3.nms.refl.providers.AchievementListenerProvider) InteractionControllerImpl(net.essentialsx.discord.interactions.InteractionControllerImpl) BukkitListener(net.essentialsx.discord.listeners.BukkitListener) InteractionException(net.essentialsx.api.v2.services.discord.InteractionException) AdvancementListenerProvider(net.ess3.nms.refl.providers.AdvancementListenerProvider) PaperAdvancementListenerProvider(net.ess3.provider.providers.PaperAdvancementListenerProvider) ExecuteCommand(net.essentialsx.discord.interactions.commands.ExecuteCommand) PaperAdvancementListenerProvider(net.ess3.provider.providers.PaperAdvancementListenerProvider) DiscordListener(net.essentialsx.discord.listeners.DiscordListener)

Example 2 with DiscordListener

use of net.essentialsx.discord.listeners.DiscordListener in project Essentials by EssentialsX.

the class JDADiscordService method startup.

public void startup() throws LoginException, InterruptedException {
    shutdown();
    invalidStartup = true;
    logger.log(Level.INFO, tl("discordLoggingIn"));
    if (plugin.getSettings().getBotToken().replace("INSERT-TOKEN-HERE", "").trim().isEmpty()) {
        throw new IllegalArgumentException(tl("discordErrorNoToken"));
    }
    jda = JDABuilder.createDefault(plugin.getSettings().getBotToken()).addEventListeners(new DiscordListener(this)).enableCache(CacheFlag.EMOTE).disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE).setContextEnabled(false).build().awaitReady();
    invalidStartup = false;
    updatePresence();
    logger.log(Level.INFO, tl("discordLoggingInDone", jda.getSelfUser().getAsTag()));
    if (jda.getGuilds().isEmpty()) {
        invalidStartup = true;
        throw new IllegalArgumentException(tl("discordErrorNoGuildSize"));
    }
    guild = jda.getGuildById(plugin.getSettings().getGuildId());
    if (guild == null) {
        invalidStartup = true;
        throw new IllegalArgumentException(tl("discordErrorNoGuild"));
    }
    interactionController = new InteractionControllerImpl(this);
    // Each will throw an exception if disabled
    try {
        interactionController.registerCommand(new ExecuteCommand(this));
    } catch (InteractionException ignored) {
    }
    try {
        interactionController.registerCommand(new MessageCommand(this));
    } catch (InteractionException ignored) {
    }
    try {
        interactionController.registerCommand(new ListCommand(this));
    } catch (InteractionException ignored) {
    }
    // Load emotes into cache, JDA will handle updates from here on out.
    guild.retrieveEmotes().queue();
    updatePrimaryChannel();
    updateConsoleRelay();
    updateTypesRelay();
    // We will see you in the future :balloon:
    // DiscordUtil.cleanWebhooks(guild, DiscordUtil.CONSOLE_RELAY_NAME);
    // DiscordUtil.cleanWebhooks(guild, DiscordUtil.ADVANCED_RELAY_NAME);
    Bukkit.getPluginManager().registerEvents(new BukkitListener(this), plugin);
    try {
        if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_12_0_R01)) {
            try {
                Class.forName("io.papermc.paper.advancement.AdvancementDisplay");
                Bukkit.getPluginManager().registerEvents(new PaperAdvancementListenerProvider(), plugin);
            } catch (ClassNotFoundException e) {
                Bukkit.getPluginManager().registerEvents(new AdvancementListenerProvider(), plugin);
            }
        } else {
            Bukkit.getPluginManager().registerEvents(new AchievementListenerProvider(), plugin);
        }
    } catch (final Throwable e) {
        logger.log(Level.WARNING, "Error while loading the achievement/advancement listener. You will not receive achievement/advancement notifications on Discord.", e);
    }
    getPlugin().getEss().scheduleSyncDelayedTask(() -> DiscordUtil.dispatchDiscordMessage(JDADiscordService.this, MessageType.DefaultTypes.SERVER_START, getSettings().getStartMessage(), true, null, null, null));
    Bukkit.getServicesManager().register(DiscordService.class, this, plugin, ServicePriority.Normal);
}
Also used : ListCommand(net.essentialsx.discord.interactions.commands.ListCommand) MessageCommand(net.essentialsx.discord.interactions.commands.MessageCommand) AchievementListenerProvider(net.ess3.nms.refl.providers.AchievementListenerProvider) InteractionControllerImpl(net.essentialsx.discord.interactions.InteractionControllerImpl) BukkitListener(net.essentialsx.discord.listeners.BukkitListener) InteractionException(net.essentialsx.api.v2.services.discord.InteractionException) AdvancementListenerProvider(net.ess3.nms.refl.providers.AdvancementListenerProvider) PaperAdvancementListenerProvider(net.ess3.provider.providers.PaperAdvancementListenerProvider) ExecuteCommand(net.essentialsx.discord.interactions.commands.ExecuteCommand) PaperAdvancementListenerProvider(net.ess3.provider.providers.PaperAdvancementListenerProvider) DiscordListener(net.essentialsx.discord.listeners.DiscordListener)

Aggregations

AchievementListenerProvider (net.ess3.nms.refl.providers.AchievementListenerProvider)2 AdvancementListenerProvider (net.ess3.nms.refl.providers.AdvancementListenerProvider)2 PaperAdvancementListenerProvider (net.ess3.provider.providers.PaperAdvancementListenerProvider)2 InteractionException (net.essentialsx.api.v2.services.discord.InteractionException)2 InteractionControllerImpl (net.essentialsx.discord.interactions.InteractionControllerImpl)2 ExecuteCommand (net.essentialsx.discord.interactions.commands.ExecuteCommand)2 ListCommand (net.essentialsx.discord.interactions.commands.ListCommand)2 MessageCommand (net.essentialsx.discord.interactions.commands.MessageCommand)2 BukkitListener (net.essentialsx.discord.listeners.BukkitListener)2 DiscordListener (net.essentialsx.discord.listeners.DiscordListener)2