use of net.essentialsx.api.v2.services.discord.InteractionException 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);
}
use of net.essentialsx.api.v2.services.discord.InteractionException in project Essentials by drtshock.
the class InteractionControllerImpl method registerCommand.
@Override
public void registerCommand(InteractionCommand command) throws InteractionException {
if (command.isDisabled()) {
throw new InteractionException("The given command has been disabled!");
}
if (commandMap.containsKey(command.getName())) {
throw new InteractionException("A command with that name is already registered!");
}
if (!initialBatchRegistration) {
if (jda.isDebug()) {
logger.info("Marked guild command for batch registration: " + command.getName());
}
batchRegistrationQueue.put(command.getName(), command);
return;
}
final CommandData data = new CommandData(command.getName(), command.getDescription());
if (command.getArguments() != null) {
for (final InteractionCommandArgument argument : command.getArguments()) {
data.addOption(OptionType.valueOf(argument.getType().name()), argument.getName(), argument.getDescription(), argument.isRequired());
}
}
jda.getGuild().upsertCommand(data).queue(success -> {
commandMap.put(command.getName(), command);
if (jda.isDebug()) {
logger.info("Registered guild command " + success.getName() + " with id " + success.getId());
}
}, failure -> {
if (failure instanceof ErrorResponseException && ((ErrorResponseException) failure).getErrorResponse() == ErrorResponse.MISSING_ACCESS) {
logger.severe(tl("discordErrorCommand"));
return;
}
logger.log(Level.SEVERE, "Error while registering command", failure);
});
}
use of net.essentialsx.api.v2.services.discord.InteractionException in project Essentials by EssentialsX.
the class InteractionControllerImpl method registerCommand.
@Override
public void registerCommand(InteractionCommand command) throws InteractionException {
if (command.isDisabled()) {
throw new InteractionException("The given command has been disabled!");
}
if (commandMap.containsKey(command.getName())) {
throw new InteractionException("A command with that name is already registered!");
}
if (!initialBatchRegistration) {
if (jda.isDebug()) {
logger.info("Marked guild command for batch registration: " + command.getName());
}
batchRegistrationQueue.put(command.getName(), command);
return;
}
final CommandData data = new CommandData(command.getName(), command.getDescription());
if (command.getArguments() != null) {
for (final InteractionCommandArgument argument : command.getArguments()) {
data.addOption(OptionType.valueOf(argument.getType().name()), argument.getName(), argument.getDescription(), argument.isRequired());
}
}
jda.getGuild().upsertCommand(data).queue(success -> {
commandMap.put(command.getName(), command);
if (jda.isDebug()) {
logger.info("Registered guild command " + success.getName() + " with id " + success.getId());
}
}, failure -> {
if (failure instanceof ErrorResponseException && ((ErrorResponseException) failure).getErrorResponse() == ErrorResponse.MISSING_ACCESS) {
logger.severe(tl("discordErrorCommand"));
return;
}
logger.log(Level.SEVERE, "Error while registering command", failure);
});
}
use of net.essentialsx.api.v2.services.discord.InteractionException 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);
}
Aggregations