From f30d3fdb9bf22580785d48f03c1e26f49ca43895 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Mon, 11 Apr 2022 17:56:19 +0900 Subject: [PATCH 1/4] apply fix (SpotBugs) --- build.gradle | 3 ++ .../jdautilities/command/CommandBuilder.java | 16 +++--- .../jdautilities/command/CommandClient.java | 2 +- .../command/CommandClientBuilder.java | 11 ++-- .../command/SlashCommandEvent.java | 2 - .../command/impl/CommandClientImpl.java | 6 +-- .../commons/waiter/EventWaiter.java | 4 +- .../examples/command/RoleinfoCommand.java | 8 +-- .../menu/ButtonEmbedPaginator.java | 7 +-- .../jagrosh/jdautilities/menu/ButtonMenu.java | 54 +++++++++---------- .../jdautilities/menu/EmbedPaginator.java | 6 +-- .../jdautilities/menu/OrderedMenu.java | 10 ++-- .../jagrosh/jdautilities/menu/Paginator.java | 10 ++-- .../jdautilities/menu/SelectionDialog.java | 4 +- .../jagrosh/jdautilities/menu/Slideshow.java | 8 +-- .../jdautilities/oauth2/OAuth2Client.java | 6 +-- .../entities/impl/OAuth2ClientImpl.java | 10 ++-- .../oauth2/requests/OAuth2Action.java | 4 +- .../oauth2/requests/OAuth2Requester.java | 7 +-- .../oauth2/requests/OAuth2URL.java | 2 +- .../session/DefaultSessionController.java | 2 +- .../oauth2/session/SessionData.java | 14 +++-- 22 files changed, 97 insertions(+), 99 deletions(-) diff --git a/build.gradle b/build.gradle index abd33203..7857ddce 100644 --- a/build.gradle +++ b/build.gradle @@ -155,6 +155,9 @@ subprojects { } compileJava { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + source = sourcesForRelease.destinationDir classpath = sourceSets.main.compileClasspath diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java index e5943713..83b6cc28 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java @@ -19,8 +19,8 @@ import net.dv8tion.jda.api.Permission; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -50,8 +50,8 @@ public class CommandBuilder private int cooldown = 0; private Permission[] userPermissions = new Permission[0]; private Permission[] botPermissions = new Permission[0]; - private final LinkedList aliases = new LinkedList<>(); - private final LinkedList children = new LinkedList<>(); + private final ArrayList aliases = new ArrayList<>(); + private final ArrayList children = new ArrayList<>(); private BiConsumer helpBiConsumer = null; private boolean usesTopicTags = true; private CooldownScope cooldownScope = CooldownScope.USER; @@ -215,7 +215,7 @@ public CommandBuilder setUserPermissions(Collection userPermissions) if(userPermissions == null) this.userPermissions = new Permission[0]; else - this.userPermissions = (Permission[]) userPermissions.toArray(); + this.userPermissions = userPermissions.toArray(new Permission[0]); return this; } @@ -251,7 +251,7 @@ public CommandBuilder setBotPermissions(Collection botPermissions) if(botPermissions == null) this.botPermissions = new Permission[0]; else - this.botPermissions = (Permission[]) botPermissions.toArray(); + this.botPermissions = botPermissions.toArray(new Permission[0]); return this; } @@ -490,8 +490,8 @@ public Command build(BiConsumer execution) { return new BlankCommand(name, help, category, arguments, guildOnly, requiredRole, ownerCommand, cooldown, - userPermissions, botPermissions, aliases.toArray(new String[aliases.size()]), - children.toArray(new Command[children.size()]), helpBiConsumer, usesTopicTags, + userPermissions, botPermissions, aliases.toArray(new String[0]), + children.toArray(new Command[0]), helpBiConsumer, usesTopicTags, cooldownScope, hidden) { @Override @@ -502,7 +502,7 @@ protected void execute(CommandEvent event) }; } - private abstract class BlankCommand extends Command + private abstract static class BlankCommand extends Command { BlankCommand(String name, String help, Category category, String arguments, boolean guildOnly, String requiredRole, diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java index 2a4de64e..8c7851e6 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java @@ -592,7 +592,7 @@ public interface CommandClient * * @return The GuildSettingsManager, or {@code null} if one was not provided when building this CommandClient. */ - M getSettingsManager(); + > M getSettingsManager(); /** * Shuts down internals of the Command Client, such as the threadpool and guild settings manager diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java index e51d7c0d..e2501c53 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -58,9 +57,9 @@ public class CommandClientBuilder private String error; private String carbonKey; private String botsKey; - private final LinkedList commands = new LinkedList<>(); - private final LinkedList slashCommands = new LinkedList<>(); - private final LinkedList contextMenus = new LinkedList<>(); + private final ArrayList commands = new ArrayList<>(); + private final ArrayList slashCommands = new ArrayList<>(); + private final ArrayList contextMenus = new ArrayList<>(); private String forcedGuildId = null; private boolean manualUpsert = false; private CommandListener listener; @@ -71,7 +70,7 @@ public class CommandClientBuilder private ScheduledExecutorService executor; private int linkedCacheSize = 0; private AnnotatedModuleCompiler compiler = new AnnotatedModuleCompilerImpl(); - private GuildSettingsManager manager = null; + private GuildSettingsManager manager = null; /** * Builds a {@link com.jagrosh.jdautilities.command.impl.CommandClientImpl CommandClientImpl} @@ -707,7 +706,7 @@ public CommandClientBuilder setLinkedCacheSize(int linkedCacheSize) * * @return This builder */ - public CommandClientBuilder setGuildSettingsManager(GuildSettingsManager manager) + public CommandClientBuilder setGuildSettingsManager(GuildSettingsManager manager) { this.manager = manager; return this; diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/SlashCommandEvent.java b/command/src/main/java/com/jagrosh/jdautilities/command/SlashCommandEvent.java index 919a60a7..0ae9a7fc 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/SlashCommandEvent.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/SlashCommandEvent.java @@ -15,7 +15,6 @@ */ package com.jagrosh.jdautilities.command; -import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.ChannelType; import net.dv8tion.jda.api.entities.GuildChannel; import net.dv8tion.jda.api.entities.IMentionable; @@ -26,7 +25,6 @@ import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; -import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java index dbd47911..3fcdec8f 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java @@ -143,7 +143,7 @@ public class CommandClientImpl implements CommandClient, EventListener private final String helpWord; private final ScheduledExecutorService executor; private final AnnotatedModuleCompiler compiler; - private final GuildSettingsManager manager; + private final GuildSettingsManager manager; private String textPrefix; private CommandListener listener = null; @@ -152,7 +152,7 @@ public class CommandClientImpl implements CommandClient, EventListener public CommandClientImpl(String ownerId, String[] coOwnerIds, String prefix, String altprefix, String[] prefixes, Function prefixFunction, Function commandPreProcessFunction, BiFunction commandPreProcessBiFunction, Activity activity, OnlineStatus status, String serverInvite, String success, String warning, String error, String carbonKey, String botsKey, ArrayList commands, ArrayList slashCommands, ArrayList contextMenus, String forcedGuildId, boolean manualUpsert, boolean useHelp, boolean shutdownAutomatically, Consumer helpConsumer, String helpWord, ScheduledExecutorService executor, - int linkedCacheSize, AnnotatedModuleCompiler compiler, GuildSettingsManager manager) + int linkedCacheSize, AnnotatedModuleCompiler compiler, GuildSettingsManager manager) { Checks.check(ownerId != null, "Owner ID was set null or not set! Please provide an User ID to register as the owner!"); @@ -603,7 +603,7 @@ public S getSettingsFor(Guild guild) @SuppressWarnings("unchecked") @Override - public M getSettingsManager() + public > M getSettingsManager() { return (M) manager; } diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java index cdb3d793..71867b0e 100644 --- a/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java +++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java @@ -234,7 +234,7 @@ public void waitForEvent(Class classType, Predicate cond @SuppressWarnings("unchecked") public final void onEvent(GenericEvent event) { - Class c = event.getClass(); + Class c = event.getClass(); // Runs at least once for the fired Event, at most // once for each superclass (excluding Object) because @@ -275,7 +275,7 @@ public void shutdown() threadpool.shutdown(); } - private class WaitingEvent + private static class WaitingEvent { final Predicate condition; final Consumer action; diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java index fd27a955..08e7dcd1 100644 --- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java +++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java @@ -108,11 +108,11 @@ else if(found.size()>1) private static String listOfRoles(List list, String query) { - String out = String.format("**Multiple roles found matching \"%s\":**", query); + StringBuilder out = new StringBuilder(String.format("**Multiple roles found matching \"%s\":**", query)); for(int i = 0; i < 6 && i < list.size(); i++) - out += "\n - " + list.get(i).getName() + " (ID:" + list.get(i).getId() + ")"; + out.append("\n - ").append(list.get(i).getName()).append(" (ID:").append(list.get(i).getId()).append(")"); if(list.size() > 6) - out += "\n**And " + (list.size() - 6) + " more...**"; - return out; + out.append("\n**And ").append(list.size() - 6).append(" more...**"); + return out.toString(); } } diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java index d50a14f9..03ad386d 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java @@ -34,7 +34,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -234,9 +233,7 @@ private void handleButtonInteraction(ButtonInteractionEvent event, Message messa } int n = newPageNum; - event.deferEdit().queue(interactionHook -> { - message.editMessage(renderPage(n)).setActionRow(buildButtons()).queue(m -> pagination(m, n)); - }); + event.deferEdit().queue(interactionHook -> message.editMessage(renderPage(n)).setActionRow(buildButtons()).queue(m -> pagination(m, n))); } private Message renderPage(int pageNum) { @@ -259,7 +256,7 @@ public static class Builder extends Menu.Builder private boolean wrapPageEnds = false; private ButtonStyle style = ButtonStyle.SECONDARY; - private final List embeds = new LinkedList<>(); + private final List embeds = new ArrayList<>(); /** * Builds the {@link ButtonEmbedPaginator} with this Builder. diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java index f220eaba..8be02d82 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java @@ -16,7 +16,7 @@ package com.jagrosh.jdautilities.menu; import java.awt.Color; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -112,36 +112,34 @@ private void initialize(RestAction ra) else { // This is the last reaction added. - r.queue(v -> { - waiter.waitForEvent(MessageReactionAddEvent.class, event -> { - // If the message is not the same as the ButtonMenu - // currently being displayed. - if(!event.getMessageId().equals(m.getId())) - return false; + r.queue(v -> waiter.waitForEvent(MessageReactionAddEvent.class, event -> { + // If the message is not the same as the ButtonMenu + // currently being displayed. + if(!event.getMessageId().equals(m.getId())) + return false; - // If the reaction is an Emote we get the Snowflake, - // otherwise we get the unicode value. - String re = event.getReaction().getReactionEmote().isEmote() - ? event.getReaction().getReactionEmote().getId() - : event.getReaction().getReactionEmote().getName(); + // If the reaction is an Emote we get the Snowflake, + // otherwise we get the unicode value. + String re = event.getReaction().getReactionEmote().isEmote() + ? event.getReaction().getReactionEmote().getId() + : event.getReaction().getReactionEmote().getName(); - // If the value we got is not registered as a button to - // the ButtonMenu being displayed we return false. - if(!choices.contains(re)) - return false; + // If the value we got is not registered as a button to + // the ButtonMenu being displayed we return false. + if(!choices.contains(re)) + return false; - // Last check is that the person who added the reaction - // is a valid user. - return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); - }, (MessageReactionAddEvent event) -> { - // What happens next is after a valid event - // is fired and processed above. + // Last check is that the person who added the reaction + // is a valid user. + return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); + }, (MessageReactionAddEvent event) -> { + // What happens next is after a valid event + // is fired and processed above. - // Preform the specified action with the ReactionEmote - action.accept(event.getReaction().getReactionEmote()); - finalAction.accept(m); - }, timeout, unit, () -> finalAction.accept(m)); - }); + // Preform the specified action with the ReactionEmote + action.accept(event.getReaction().getReactionEmote()); + finalAction.accept(m); + }, timeout, unit, () -> finalAction.accept(m))); } } }); @@ -169,7 +167,7 @@ public static class Builder extends Menu.Builder private Color color; private String text; private String description; - private final List choices = new LinkedList<>(); + private final List choices = new ArrayList<>(); private Consumer action; private Consumer finalAction = (m) -> {}; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java index c4ab4553..bb436f75 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java @@ -216,9 +216,9 @@ else if(event instanceof MessageReceivedEvent) int pages = embeds.size(); final int targetPage; - if(leftText != null && rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) - targetPage = pageNum - 1 < 1 && wrapPageEnds ? pages : pageNum - 1; - else if(rightText != null && rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) + if(rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) + targetPage = pageNum - 1 < 1 ? pages : pageNum - 1; + else if(rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) targetPage = pageNum + 1 > pages && wrapPageEnds ? 1 : pageNum + 1; else targetPage = Integer.parseInt(rawContent); diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java index 8a862b10..0a71df2e 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java @@ -16,7 +16,7 @@ package com.jagrosh.jdautilities.menu; import java.awt.Color; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Set; @@ -246,9 +246,7 @@ else if (e instanceof MessageReceivedEvent) private void waitReactionOnly(Message m) { // This one is only for reactions - waiter.waitForEvent(MessageReactionAddEvent.class, e -> { - return isValidReaction(m, e); - }, e -> { + waiter.waitForEvent(MessageReactionAddEvent.class, e -> isValidReaction(m, e), e -> { m.delete().queue(); if(e.getReaction().getReactionEmote().getName().equals(CANCEL)) cancel.accept(m); @@ -270,7 +268,7 @@ private Message getMessage() for(int i=0; i private Color color; private String text; private String description; - private final List choices = new LinkedList<>(); + private final List choices = new ArrayList<>(); private BiConsumer selection; private Consumer cancel = (m) -> {}; private boolean useLetters = false; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java index 98f88f1f..0229e25f 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java @@ -17,7 +17,7 @@ import java.awt.Color; import java.util.Arrays; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -256,9 +256,9 @@ else if(event instanceof MessageReceivedEvent) final int targetPage; - if(leftText != null && rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) - targetPage = pageNum - 1 < 1 && wrapPageEnds? pages : pageNum - 1; - else if(rightText != null && rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) + if(rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) + targetPage = pageNum - 1 < 1 ? pages : pageNum - 1; + else if(rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) targetPage = pageNum + 1 > pages && wrapPageEnds? 1 : pageNum + 1; else { @@ -413,7 +413,7 @@ public static class Builder extends Menu.Builder private String textToRight = null; private boolean allowTextInput = false; - private final List strings = new LinkedList<>(); + private final List strings = new ArrayList<>(); /** * Builds the {@link com.jagrosh.jdautilities.menu.Paginator Paginator} diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java index 913dd649..b685a58f 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java @@ -17,7 +17,7 @@ import java.awt.Color; import java.util.Arrays; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -249,7 +249,7 @@ private Message render(int selection) */ public static class Builder extends Menu.Builder { - private final List choices = new LinkedList<>(); + private final List choices = new ArrayList<>(); private String leftEnd = ""; private String rightEnd = ""; private String defaultLeft = ""; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java index 2273712e..d60a91bb 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java @@ -17,7 +17,7 @@ import java.awt.Color; import java.util.Arrays; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -234,9 +234,9 @@ else if(event instanceof MessageReceivedEvent) int pages = urls.size(); final int targetPage; - if(leftText != null && rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) + if(rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) targetPage = pageNum - 1 < 1 && wrapPageEnds? pages : pageNum - 1; - else if(rightText != null && rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) + else if(rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) targetPage = pageNum + 1 > pages && wrapPageEnds? 1 : pageNum + 1; else { @@ -371,7 +371,7 @@ public static class Builder extends Menu.Builder private String textToRight = null; private boolean allowTextInput = false; - private final List strings = new LinkedList<>(); + private final List strings = new ArrayList<>(); /** * Builds the {@link com.jagrosh.jdautilities.menu.Slideshow Slideshow} diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java index 81a782de..a43ae41a 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java @@ -153,7 +153,7 @@ public interface OAuth2Client * * @return The client's SessionController. */ - SessionController getSessionController(); + SessionController getSessionController(); /** * Builder for creating OAuth2Client instances. @@ -165,7 +165,7 @@ class Builder { private long clientId = -1; private String clientSecret; - private SessionController sessionController; + private SessionController sessionController; private StateController stateController; private OkHttpClient client; @@ -225,7 +225,7 @@ public Builder setClientSecret(String clientSecret) * * @return This builder. */ - public Builder setSessionController(SessionController sessionController) + public Builder setSessionController(SessionController sessionController) { this.sessionController = sessionController; return this; diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java index 09821eed..1009a10e 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java @@ -45,7 +45,7 @@ import java.io.IOException; import java.io.InputStream; import java.time.OffsetDateTime; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; /** @@ -58,12 +58,12 @@ public class OAuth2ClientImpl implements OAuth2Client private final long clientId; private final String clientSecret; - private final SessionController sessionController; + private final SessionController sessionController; private final StateController stateController; private final OkHttpClient httpClient; private final OAuth2Requester requester; - public OAuth2ClientImpl(long clientId, String clientSecret, SessionController sessionController, + public OAuth2ClientImpl(long clientId, String clientSecret, SessionController sessionController, StateController stateController, OkHttpClient httpClient) { Checks.check(clientId >= 0, "Invalid Client ID"); @@ -181,7 +181,7 @@ protected List handle(Response response) throws IOException throw failure(response); JSONArray body = new JSONArray(new JSONTokener(IOUtil.getBody(response))); - List list = new LinkedList<>(); + List list = new ArrayList<>(); JSONObject obj; for(int i = 0; i < body.length(); i++) { @@ -214,7 +214,7 @@ public StateController getStateController() } @Override - public SessionController getSessionController() + public SessionController getSessionController() { return sessionController; } diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java index a5c3bec1..f0c3eef2 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java @@ -40,9 +40,7 @@ public abstract class OAuth2Action { protected static final Consumer DEFAULT_SUCCESS = t -> {}; - protected static final Consumer DEFAULT_FAILURE = t -> { - OAuth2Requester.LOGGER.error("Requester encountered an error while processing response!", t); - }; + protected static final Consumer DEFAULT_FAILURE = t -> OAuth2Requester.LOGGER.error("Requester encountered an error while processing response!", t); protected final OAuth2ClientImpl client; protected final Method method; diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java index 42a78cfc..640eb017 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java @@ -18,6 +18,7 @@ import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; import net.dv8tion.jda.internal.utils.JDALogger; import okhttp3.*; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import java.io.IOException; @@ -44,7 +45,7 @@ void submitAsync(OAuth2Action request, Consumer success, Consumer T submitSync(OAuth2Action request) throws IOException } } - private static void logSuccessfulRequest(OAuth2Action request) + private static void logSuccessfulRequest(OAuth2Action request) { LOGGER.debug("Got a response for {} - {}\nHeaders: {}", request.getMethod(), request.getUrl(), request.getHeaders()); diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java index 87314239..feade3f1 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java @@ -62,7 +62,7 @@ public enum OAuth2URL b.append(queryParams[i]); } - this.formattableRoute = route + b.toString(); + this.formattableRoute = route + b; this.queryParams = b.toString(); } else diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java index 1ff4ea1b..ef206c60 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java @@ -43,7 +43,7 @@ public DefaultSession createSession(SessionData data) return created; } - public class DefaultSession implements Session + public static class DefaultSession implements Session { private final String accessToken, refreshToken, tokenType; private final OffsetDateTime expiration; diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java index 6a0fe93d..6a129a48 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java @@ -105,12 +105,18 @@ public Scope[] getScopes() @Override public boolean equals(Object obj) { - if(!(obj instanceof SessionData)) - return false; + if (obj instanceof SessionData) { + SessionData data = ((SessionData) obj); - SessionData data = ((SessionData) obj); + return getIdentifier().equals(data.getIdentifier()) && getTokenType().equals(data.getTokenType()); + } else { + return false; + } + } - return getIdentifier().equals(data.getIdentifier()) && getTokenType().equals(data.getTokenType()); + @Override + public int hashCode() { + return getIdentifier().hashCode() + getTokenType().hashCode(); } @Override From dd2e0b55ea990c04bc5bb1555ced3ccbaeb98062 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 20 May 2022 05:12:23 +0900 Subject: [PATCH 2/4] Update command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java Co-authored-by: Andre_601 --- .../java/com/jagrosh/jdautilities/command/CommandBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java index 83b6cc28..3aae831f 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java @@ -50,8 +50,8 @@ public class CommandBuilder private int cooldown = 0; private Permission[] userPermissions = new Permission[0]; private Permission[] botPermissions = new Permission[0]; - private final ArrayList aliases = new ArrayList<>(); - private final ArrayList children = new ArrayList<>(); + private final List aliases = new ArrayList<>(); + private final List children = new ArrayList<>(); private BiConsumer helpBiConsumer = null; private boolean usesTopicTags = true; private CooldownScope cooldownScope = CooldownScope.USER; From 73fac685536fd85d02cf8fc229e903af02c13aad Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 20 May 2022 05:13:56 +0900 Subject: [PATCH 3/4] Update CommandClientBuilder.java --- .../jagrosh/jdautilities/command/CommandClientBuilder.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java index e2501c53..bfd4e407 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -57,9 +58,9 @@ public class CommandClientBuilder private String error; private String carbonKey; private String botsKey; - private final ArrayList commands = new ArrayList<>(); - private final ArrayList slashCommands = new ArrayList<>(); - private final ArrayList contextMenus = new ArrayList<>(); + private final List commands = new ArrayList<>(); + private final List slashCommands = new ArrayList<>(); + private final List contextMenus = new ArrayList<>(); private String forcedGuildId = null; private boolean manualUpsert = false; private CommandListener listener; From 98150b6de4b970f8f6e1c79b0c819c6f03e1255a Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Fri, 20 May 2022 05:14:18 +0900 Subject: [PATCH 4/4] Update CommandBuilder.java --- .../java/com/jagrosh/jdautilities/command/CommandBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java index 3aae831f..a206355b 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer;