From 30793ee827c24c970f93a415d91e907ccf8bc8aa Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Thu, 23 Jun 2022 21:46:07 +0200 Subject: [PATCH 01/23] bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 283cfd5d..3b3b88dc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,5 +21,5 @@ # group=tk.bluetree242 name=DiscordSRVUtils -version=1.2.9-DEV +version=1.2.10-DEV description=Utilities for your Discord Server! From 75eb11a68de5fa52cdc2437b3c6c393270c66e40 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Thu, 23 Jun 2022 21:48:46 +0200 Subject: [PATCH 02/23] fix description of /invites command --- .../commands/discord/invitetracking/InvitesCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/invitetracking/InvitesCommand.java b/core/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/invitetracking/InvitesCommand.java index 8e0d0941..fb6ebe01 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/invitetracking/InvitesCommand.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/commands/discord/invitetracking/InvitesCommand.java @@ -35,7 +35,7 @@ public class InvitesCommand extends Command { public InvitesCommand(DiscordSRVUtils core) { - super(core, "invites", "Get leveling info about a user or yourself", "[P]invites [user]", null, CommandCategory.INVITE_TRACKING, + super(core, "invites", "Get Amount of invites for a user", "[P]invites [user]", null, CommandCategory.INVITE_TRACKING, new OptionData(OptionType.USER, "user_mention", "User to get invites of", false)); } From 4128990bf012705eecbfc2e6e5bff37fe3e5b2a7 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Sat, 25 Jun 2022 12:38:11 +0200 Subject: [PATCH 03/23] fix onLink error when there is no action for leveling roles to do --- .../listeners/discordsrv/DiscordSRVListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java b/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java index f20ab497..8b965f63 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/discordsrv/DiscordSRVListener.java @@ -75,7 +75,7 @@ public void onLink(AccountLinkedEvent e) { if (toAdd != null && !member.getRoles().contains(toAdd)) { actions.add(core.getPlatform().getDiscordSRV().getMainGuild().addRoleToMember(member, toAdd).reason("Account Linked")); } - RestAction.allOf(actions).queue(); + if (!actions.isEmpty()) RestAction.allOf(actions).queue(); }); } From 8591c2e9f05b77545e4f12862c5f1a7debeb09f8 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Sun, 26 Jun 2022 01:30:48 +0200 Subject: [PATCH 04/23] fix opened ticket is being stored as closed when editing or creating new panel --- .../tk/bluetree242/discordsrvutils/systems/tickets/Panel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/tickets/Panel.java b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/tickets/Panel.java index 6090b118..3eb4cf36 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/tickets/Panel.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/tickets/Panel.java @@ -255,7 +255,7 @@ public Panel create(DSLContext conn) { .set(TicketPanelsTable.TICKET_PANELS.ID, panel.id) .set(TicketPanelsTable.TICKET_PANELS.CHANNEL, channelId) .set(TicketPanelsTable.TICKET_PANELS.MESSAGEID, msg.getIdLong()) - .set(TicketPanelsTable.TICKET_PANELS.OPENEDCATEGORY, closedCategory) + .set(TicketPanelsTable.TICKET_PANELS.OPENEDCATEGORY, openedCategory) .set(TicketPanelsTable.TICKET_PANELS.CLOSEDCATEGORY, closedCategory) .execute(); addAllowedRoles(conn, allowedRoles, panel); @@ -328,7 +328,7 @@ public Panel apply(DSLContext conn) { .set(TicketPanelsTable.TICKET_PANELS.NAME, name) .set(TicketPanelsTable.TICKET_PANELS.CHANNEL, channelId) .set(TicketPanelsTable.TICKET_PANELS.MESSAGEID, msg.getIdLong()) - .set(TicketPanelsTable.TICKET_PANELS.OPENEDCATEGORY, closedCategory) + .set(TicketPanelsTable.TICKET_PANELS.OPENEDCATEGORY, openedCategory) .set(TicketPanelsTable.TICKET_PANELS.CLOSEDCATEGORY, closedCategory) .where(TicketPanelsTable.TICKET_PANELS.ID.eq(panel.id)) .execute(); From 3cb94112245ffa66e508467916198c4e3e3117a6 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Sat, 30 Jul 2022 09:23:27 +0200 Subject: [PATCH 05/23] close connection when caching leveling --- .../discordsrvutils/systems/leveling/LevelingManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java index 495e7ac2..f09aeb9e 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java @@ -40,6 +40,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.sql.Connection; import java.sql.SQLException; import java.time.Duration; import java.util.*; @@ -81,7 +82,10 @@ public void reloadLevelingRoles() { .refreshAfterWrite(Duration.ofSeconds(30)) .build(key -> { adding = true; - PlayerStats stats = getPlayerStats(key, DiscordSRVUtils.get().getDatabaseManager().newJooqConnection()); + PlayerStats stats = null; + try (Connection conn = core.getDatabaseManager().getConnection()) { + stats = getPlayerStats(key, core.getDatabaseManager().jooq(conn)); + } catch (SQLException ignored) {} //not print trillion messages in console if something goes wrong adding = false; return stats; }); From 9d2f372781d82cead2535aabf4de7b2f714a7711 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Sat, 30 Jul 2022 09:43:18 +0200 Subject: [PATCH 06/23] update gradle --- build.gradle | 7 +++---- bukkit/build.gradle | 1 - core/build.gradle | 1 - gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 341eeb99..67b01b8d 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ import org.apache.tools.ant.filters.ReplaceTokens plugins { id 'java' id 'maven-publish' - id 'com.github.johnrengelman.shadow' version '6.1.0' + id 'com.github.johnrengelman.shadow' version '7.1.2' } compileJava.options.encoding 'UTF-8' build.finalizedBy shadowJar @@ -39,7 +39,7 @@ allprojects { url = uri('https://nexus.vankka.dev/repository/maven-public/') } maven { - url = uri('http://repo.extendedclip.com/content/repositories/placeholderapi/') + url = uri('https://repo.extendedclip.com/content/repositories/placeholderapi/') } maven { @@ -107,7 +107,6 @@ def commit = project.properties['commit'] == null ? "NONE" : project.properties[ System.out.println("Commit Hash is " + commit) subprojects { apply plugin: 'java' - apply plugin: 'maven' apply plugin: 'maven-publish' project.jar { archivesBaseName = 'DiscordSRVUtils-' + project.name @@ -123,7 +122,7 @@ subprojects { } } - + tasks.withType(Copy).all { duplicatesStrategy 'INCLUDE' } } shadowJar { classifier '' diff --git a/bukkit/build.gradle b/bukkit/build.gradle index a7f8f1e9..7682a20a 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -24,7 +24,6 @@ plugins { id 'java' id 'maven-publish' } -apply plugin: 'maven' apply plugin: 'maven-publish' publishing { publications { diff --git a/core/build.gradle b/core/build.gradle index 9e18c0f3..7686ef9e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -29,7 +29,6 @@ plugins { id 'nu.studer.jooq' version '7.1.1' id "org.flywaydb.flyway" version "8.5.3" } -apply plugin: 'maven' apply plugin: 'maven-publish' publishing { publications { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6a5ce897..29a7e31b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -21,6 +21,6 @@ # distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From a3b105c1a9c49b740cdb0d51f2462abb13ce8fe5 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Sat, 30 Jul 2022 09:43:37 +0200 Subject: [PATCH 07/23] fix core may not be initialized --- .../discordsrvutils/systems/leveling/LevelingManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java index f09aeb9e..f4671575 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java @@ -81,6 +81,7 @@ public void reloadLevelingRoles() { .expireAfterWrite(Duration.ofMinutes(1)) .refreshAfterWrite(Duration.ofSeconds(30)) .build(key -> { + DiscordSRVUtils core = DiscordSRVUtils.get(); adding = true; PlayerStats stats = null; try (Connection conn = core.getDatabaseManager().getConnection()) { From 0a0fac65c7d98ca9f55d9a92670d517cd5202380 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Sat, 30 Jul 2022 10:20:26 +0200 Subject: [PATCH 08/23] downgrade jooq and jooq plugin --- core/build.gradle | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 7686ef9e..2c452146 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -26,7 +26,7 @@ import nu.studer.gradle.jooq.JooqEdition plugins { id 'java' id 'maven-publish' - id 'nu.studer.jooq' version '7.1.1' + id 'nu.studer.jooq' version '5.2.2' id "org.flywaydb.flyway" version "8.5.3" } apply plugin: 'maven-publish' @@ -79,8 +79,8 @@ dependencies { //related to jooq implementation 'org.jooq:jooq:3.16.6' //using h2 database for code generation as it doesnt uppercase the table/column names, without it, we get into unfixable issues - testImplementation 'com.h2database:h2:2.1.210' - jooqGenerator 'com.h2database:h2:2.1.210' + testImplementation 'com.h2database:h2:1.4.197' + jooqGenerator 'com.h2database:h2:1.4.197' } @@ -97,7 +97,7 @@ afterEvaluate { evaluated -> } } flyway { - url = "jdbc:h2:file:${project.buildDir}/migration;MODE=Mysql;DATABASE_TO_UPPER=false;DATABASE_TO_LOWER=false" + url = "jdbc:h2:file:${project.buildDir}/migration;MODE=Mysql;DATABASE_TO_UPPER=false" user = 'SA' password = '' validateMigrationNaming = true @@ -106,7 +106,7 @@ flyway { } jooq { - version = '3.16.6' // default (can be omitted) + version = '3.14.12' // default (can be omitted) edition = JooqEdition.OSS // default (can be omitted) configurations { @@ -168,3 +168,7 @@ jooq { } } +repositories { + mavenCentral() +} + From 0f7c09f5fd33c9bf26e3c7faa4b011c807ead992 Mon Sep 17 00:00:00 2001 From: BlueTree242 Date: Wed, 3 Aug 2022 12:20:13 +0200 Subject: [PATCH 09/23] no storing of invites in database for bungee mode --- .../listeners/jda/WelcomerAndGoodByeListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java b/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java index d23eb953..0811828a 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/listeners/jda/WelcomerAndGoodByeListener.java @@ -67,7 +67,7 @@ public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent e) { } } //store in db - if (core.getMainConfig().track_invites() && invite != null) { + if (!core.getMainConfig().bungee_mode() && core.getMainConfig().track_invites() && invite != null) { try (Connection conn = core.getDatabaseManager().getConnection()) { core.getInviteTrackingManager().addInvite(core.getDatabaseManager().jooq(conn), e.getUser().getIdLong(), invite.getUserId(), invite.getGuildId()); } catch (SQLException ex) { From b97bc48bd91e289a17a31756371057b4661b444d Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Thu, 18 Aug 2022 10:36:00 +0200 Subject: [PATCH 10/23] replace debug domain with new domain --- .../bluetree242/discordsrvutils/bukkit/BukkitDebugger.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/BukkitDebugger.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/BukkitDebugger.java index 3dbaee46..b827a43e 100644 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/BukkitDebugger.java +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/BukkitDebugger.java @@ -128,7 +128,7 @@ public String run(String stacktrace) throws Exception { int aesBits = 256; String key = RandomStringUtils.randomAlphanumeric(aesBits == 256 ? 32 : 16); RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("data", Utils.b64Encode(encrypt(key.getBytes(), data.toString()))).build(); - Request request = new Request.Builder().post(body).url("https://mcdebug.bluetree242.tk/api/v1/createDebug").build(); + Request request = new Request.Builder().post(body).url("https://mcdebug.bluetree242.ml/api/v1/createDebug").build(); Response response = client.newCall(request).execute(); JSONObject bdy = new JSONObject(response.body().string()); @@ -136,7 +136,7 @@ public String run(String stacktrace) throws Exception { if (response.code() != 200) { return "ERROR: INVALID RESPONSE CODE " + response.code(); } - return "https://mcdebug.bluetree242.tk" + "/" + bdy.getString("id") + "#" + key; + return "https://mcdebug.bluetree242.ml" + "/" + bdy.getString("id") + "#" + key; } @@ -236,7 +236,7 @@ private String getActiveConfig() { Iterator iterator = activeConfig.allChildren().iterator(); while (iterator.hasNext()) { Dynamic child = iterator.next(); - if (child.allChildren().count() == 0) { + if (!child.allChildren().findAny().isPresent()) { stringBuilder.append(child.key().asObject()).append(": ").append(child.asObject()); } else { StringJoiner childJoiner = new StringJoiner(", "); From 1485d1ec5e58802d21519b7b606560b4a06eaeb2 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Thu, 18 Aug 2022 10:52:10 +0200 Subject: [PATCH 11/23] use jooq version which works with java 8 --- core/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 2c452146..2323dd8f 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -77,7 +77,7 @@ dependencies { implementation 'commons-io:commons-io:2.6' //related to jooq - implementation 'org.jooq:jooq:3.16.6' + implementation 'org.jooq:jooq:3.14.16' //using h2 database for code generation as it doesnt uppercase the table/column names, without it, we get into unfixable issues testImplementation 'com.h2database:h2:1.4.197' jooqGenerator 'com.h2database:h2:1.4.197' @@ -106,7 +106,7 @@ flyway { } jooq { - version = '3.14.12' // default (can be omitted) + version = '3.14.16' // default (can be omitted) edition = JooqEdition.OSS // default (can be omitted) configurations { From 7fd9a8e9bd5b2cbe4b1cf413d87d5805993ba1ab Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Thu, 18 Aug 2022 13:11:39 +0200 Subject: [PATCH 12/23] shade sl4j into the plugin --- core/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/core/build.gradle b/core/build.gradle index 2323dd8f..e2ff8b47 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -81,6 +81,7 @@ dependencies { //using h2 database for code generation as it doesnt uppercase the table/column names, without it, we get into unfixable issues testImplementation 'com.h2database:h2:1.4.197' jooqGenerator 'com.h2database:h2:1.4.197' + implementation 'org.slf4j:slf4j-api:1.7.30' } From b158c5d7b795b5ec4aaaaf448adf426099294c5a Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:41:29 +0200 Subject: [PATCH 13/23] shade log4j sl4j implementation in jar --- core/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/build.gradle b/core/build.gradle index e2ff8b47..1da32372 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -82,7 +82,7 @@ dependencies { testImplementation 'com.h2database:h2:1.4.197' jooqGenerator 'com.h2database:h2:1.4.197' implementation 'org.slf4j:slf4j-api:1.7.30' - + implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.18.0' } From 1b7f0d4070ce9d0842303840f1ead47cbe71f953 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Thu, 18 Aug 2022 18:46:41 +0200 Subject: [PATCH 14/23] exclude log4j api and implementation to be included in the jar --- core/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/build.gradle b/core/build.gradle index 1da32372..d51a964e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -82,7 +82,9 @@ dependencies { testImplementation 'com.h2database:h2:1.4.197' jooqGenerator 'com.h2database:h2:1.4.197' implementation 'org.slf4j:slf4j-api:1.7.30' - implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.18.0' + implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.18.0') { + exclude group: 'org.apache.logging.log4j' + } } From c07ff7dfc87293b352a07d7140da91432fcce949 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Mon, 22 Aug 2022 16:20:50 +0200 Subject: [PATCH 15/23] remove slf4j --- core/build.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index d51a964e..3e1de6e6 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -81,10 +81,6 @@ dependencies { //using h2 database for code generation as it doesnt uppercase the table/column names, without it, we get into unfixable issues testImplementation 'com.h2database:h2:1.4.197' jooqGenerator 'com.h2database:h2:1.4.197' - implementation 'org.slf4j:slf4j-api:1.7.30' - implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.18.0') { - exclude group: 'org.apache.logging.log4j' - } } From e7c267470ad1fd7bc50a2bb73158ffda4dc0ce5d Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Mon, 22 Aug 2022 16:45:03 +0200 Subject: [PATCH 16/23] use the new discordsrv slash commands api, and require it as the minimum version (1.26.0-SNAPSHOT) --- bukkit/build.gradle | 4 +- .../bukkit/DiscordSRVUtilsBukkit.java | 6 ++ .../discordsrv/SlashCommandProvider.java | 58 +++++++++++++++++++ core/build.gradle | 4 +- .../discordsrvutils/DiscordSRVUtils.java | 6 +- .../commandmanagement/CommandManager.java | 51 ---------------- 6 files changed, 73 insertions(+), 56 deletions(-) create mode 100644 bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 7682a20a..cfd7c775 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -56,7 +56,9 @@ dependencies { compileOnly urlFile("https://github.com/Zrips/CMI-API/releases/download/8.7.8.2/CMIAPI8.7.8.2.jar", "CMI-API") compileOnly 'net.lapismc:AFKPlus:3.3.13' implementation project(":core") - compileOnly('com.discordsrv:discordsrv:1.25.0') + compileOnly('com.discordsrv:discordsrv:1.26.0-SNAPSHOT') { + exclude group: 'net.kyori' + } compileOnly 'net.ess3:EssentialsX:2.17.2' } diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java index 52a6ffde..7a44dd02 100644 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java @@ -23,17 +23,20 @@ package tk.bluetree242.discordsrvutils.bukkit; import github.scarsz.discordsrv.DiscordSRV; +import lombok.Getter; import org.bstats.bukkit.Metrics; import org.bstats.charts.AdvancedPie; import org.bstats.charts.SimplePie; import org.bukkit.plugin.java.JavaPlugin; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; +import tk.bluetree242.discordsrvutils.bukkit.discordsrv.SlashCommandProvider; import tk.bluetree242.discordsrvutils.bukkit.listeners.jda.CustomDiscordAccountLinkListener; import java.util.HashMap; import java.util.Map; public class DiscordSRVUtilsBukkit extends JavaPlugin { + @Getter private DiscordSRVUtils core = null; public void onEnable() { @@ -69,6 +72,9 @@ public void onEnable() { })); metrics.addCustomChart(new SimplePie("discordsrv_versions", () -> DiscordSRV.getPlugin().getDescription().getVersion())); metrics.addCustomChart(new SimplePie("admins", () -> core.getJdaManager().getAdminIds().size() + "")); + + //discordsrv slash commands api + DiscordSRV.api.addSlashCommandProvider(new SlashCommandProvider(this)); } public void onDisable() { diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java new file mode 100644 index 00000000..49b50050 --- /dev/null +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java @@ -0,0 +1,58 @@ +/* + * LICENSE + * DiscordSRVUtils + * ------------- + * Copyright (C) 2020 - 2022 BlueTree242 + * ------------- + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * . + * END + */ + +package tk.bluetree242.discordsrvutils.bukkit.discordsrv; + +import github.scarsz.discordsrv.DiscordSRV; +import github.scarsz.discordsrv.api.commands.PluginSlashCommand; +import github.scarsz.discordsrv.dependencies.jda.api.interactions.commands.build.CommandData; +import lombok.RequiredArgsConstructor; +import tk.bluetree242.discordsrvutils.bukkit.DiscordSRVUtilsBukkit; +import tk.bluetree242.discordsrvutils.systems.commandmanagement.Command; +import tk.bluetree242.discordsrvutils.systems.commandmanagement.CommandManager; + +import java.util.HashSet; +import java.util.Set; + +@RequiredArgsConstructor +public class SlashCommandProvider implements github.scarsz.discordsrv.api.commands.SlashCommandProvider { + private final DiscordSRVUtilsBukkit core; + @Override + public Set getSlashCommands() { + Set commands = new HashSet<>(); + if (core.getCore() == null || !core.getCore().isEnabled() || !core.getCore().getMainConfig().register_slash()) return commands; + CommandManager manager = core.getCore().getCommandManager(); + for (Command command : manager.getCommands()) { + if (!command.isEnabled()) continue; + commands.add(getCmd(command.getCmd(), command)); + for (String alias : command.getAliases()) { + commands.add(getCmd(alias, command)); + } + } + return commands; + } + + + private PluginSlashCommand getCmd(String alias, Command cmd) { + return new PluginSlashCommand(core, new CommandData(alias, cmd.getDescription()).addOptions(cmd.getOptions()), DiscordSRV.getPlugin().getMainGuild() + ""); + } +} diff --git a/core/build.gradle b/core/build.gradle index 3e1de6e6..577f1611 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -69,7 +69,9 @@ dependencies { implementation 'com.zaxxer:HikariCP:3.4.5' implementation 'org.hsqldb:hsqldb:2.4.1' implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.0' - compileOnly('com.discordsrv:discordsrv:1.25.0') + compileOnly('com.discordsrv:discordsrv:1.26.0-SNAPSHOT') { + exclude group: 'net.kyori' + } implementation "org.flywaydb:flyway-core:7.5.3" implementation group: 'org.json', name: 'json', version: '20210307' implementation 'com.github.ben-manes.caffeine:caffeine:2.9.1' diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java b/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java index a9174144..c8269c31 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java @@ -23,6 +23,7 @@ package tk.bluetree242.discordsrvutils; import github.scarsz.discordsrv.DiscordSRV; +import github.scarsz.discordsrv.api.commands.SlashCommandProvider; import github.scarsz.discordsrv.dependencies.jda.api.JDA; import github.scarsz.discordsrv.dependencies.jda.api.OnlineStatus; import github.scarsz.discordsrv.dependencies.jda.api.entities.Message; @@ -219,7 +220,7 @@ public void onEnable() { "| &cDiscord: &rhttps://discordsrvutils.xyz/support\n" + "[]================================[]"); try { - Class.forName("github.scarsz.discordsrv.dependencies.jda.api.entities.Message").getDeclaredMethod("getInteraction"); + Class.forName("github.scarsz.discordsrv.api.ApiManager").getDeclaredMethod("addSlashCommandProvider", SlashCommandProvider.class); } catch (ClassNotFoundException | NoSuchMethodException e) { //DiscordSRV is out of date severe("Plugin could not enable because DiscordSRV is missing an important feature. This means your DiscordSRV is outdated, please update it for DSU to work"); @@ -326,8 +327,6 @@ public void whenReady() { public void setSettings() { if (!isReady()) return; - if (config.register_slash()) - commandManager.addSlashCommands(); OnlineStatus onlineStatus = getMainConfig().onlinestatus().equalsIgnoreCase("DND") ? OnlineStatus.DO_NOT_DISTURB : OnlineStatus.valueOf(getMainConfig().onlinestatus().toUpperCase()); getJDA().getPresence().setStatus(onlineStatus); levelingManager.cachedUUIDS.invalidateAll(); @@ -338,6 +337,7 @@ public void setSettings() { main.getStatusListener().register(); statusManager.reloadTimer(); } + DiscordSRV.api.updateSlashCommands(); } public RestAction queueMsg(Message msg, MessageChannel channel) { diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandManager.java b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandManager.java index 99f4064e..9042fe60 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandManager.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandManager.java @@ -23,12 +23,6 @@ package tk.bluetree242.discordsrvutils.systems.commandmanagement; -import github.scarsz.discordsrv.dependencies.jda.api.Permission; -import github.scarsz.discordsrv.dependencies.jda.api.exceptions.ErrorResponseException; -import github.scarsz.discordsrv.dependencies.jda.api.exceptions.RateLimitedException; -import github.scarsz.discordsrv.dependencies.jda.api.interactions.commands.build.CommandData; -import github.scarsz.discordsrv.dependencies.jda.api.requests.ErrorResponse; -import github.scarsz.discordsrv.dependencies.jda.api.requests.restaction.CommandListUpdateAction; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.commands.discord.HelpCommand; import tk.bluetree242.discordsrvutils.commands.discord.admin.EchoCommand; @@ -121,49 +115,4 @@ public Command getCommandByName(String name) { public List getCommandsWithoutAliases() { return commandswithoutaliases; } - - public void addSlashCommands() { - if (core.getPlatform().getDiscordSRV().getMainGuild() == null) { - core.severe("Default Guild not found (is the bot in a guild?)"); - return; - } - if (core.getJDA().getGuilds().size() >= 2) { - core.getLogger().warning("Found " + core.getJDA().getGuilds().size() + " Servers! Slash Commands will be added in " + core.getPlatform().getDiscordSRV().getMainGuild().getName()); - core.getLogger().warning("If you don't want this kick the bot from the servers and leave it on one server only."); - } - CommandListUpdateAction commands = core.getPlatform().getDiscordSRV().getMainGuild().updateCommands(); - for (Command command : this.commands) { - if (!command.isEnabled()) continue; - addCmd(command.getCmd(), command, commands); - for (String alias : command.getAliases()) { - addCmd(alias, command, commands); - } - } - commands.queue(null, r -> { - if (!(r instanceof ErrorResponseException)) { - if (r instanceof RateLimitedException) { - core.severe("Could not add slash commands due to rate limits."); - return; - } - core.severe("Could not add slash commands to discord server."); - r.printStackTrace(); - } else { - ErrorResponseException err = (ErrorResponseException) r; - if (err.getErrorResponse() == ErrorResponse.MISSING_ACCESS) { - core.getJDA().setRequiredScopes("applications.commands"); - String link = core.getJDA().getInviteUrl(Permission.ADMINISTRATOR); - core.severe("Could Not Add Slash Command to Server Because your bot is missing some scopes! Please use this invite " + link); - } else { - core.severe("Could not add slash commands to discord server."); - r.printStackTrace(); - } - } - }); - } - - private void addCmd(String alias, Command cmd, CommandListUpdateAction action) { - action.addCommands(new CommandData(alias, cmd.getDescription()).addOptions(cmd.getOptions())); - } - - } From 71282a10aaa0a44b1ee5b20c8ea5db24dd528079 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Tue, 23 Aug 2022 22:08:49 +0200 Subject: [PATCH 17/23] remove /dsu removeslash command --- .../commands/game/DiscordSRVUtilsCommand.java | 11 ----------- .../tk/bluetree242/discordsrvutils/config/Config.java | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/commands/game/DiscordSRVUtilsCommand.java b/core/src/main/java/tk/bluetree242/discordsrvutils/commands/game/DiscordSRVUtilsCommand.java index e7f09688..6a8da80a 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/commands/game/DiscordSRVUtilsCommand.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/commands/game/DiscordSRVUtilsCommand.java @@ -81,17 +81,6 @@ public void onRunAsync(String[] args, CommandUser sender, String label) throws T } return; } - } else if (args[0].equalsIgnoreCase("removeslash")) { - if (sender.hasPermission("discordsrvutils.removeslash")) { - if (!core.isReady()) { - sender.sendMessage("&cSorry but plugin isn't ready yet to do this action"); - } else { - core.getPlatform().getDiscordSRV().getMainGuild().updateCommands().queue( - s -> sender.sendMessage("&aSuccessfully Removed Slash Commands from &e" + core.getPlatform().getDiscordSRV().getMainGuild().getName()), - f -> sender.sendMessage("&cCould not remove slash commands from &e" + core.getPlatform().getDiscordSRV().getMainGuild().getName())); - } - return; - } } } sender.sendMessage("&cSubCommand not found"); diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java b/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java index 0695a176..4d8cdfbc 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java @@ -72,7 +72,7 @@ public interface Config { @AnnotationBasedSorter.Order(35) @ConfKey("register-slash-commands") - @ConfComments("# Should We register slash commands into your discord server?\n# This will not remove the currently registered commands, to remove them use /dsu removeslash") + @ConfComments("# Should We register slash commands into your discord server?") @ConfDefault.DefaultBoolean(true) boolean register_slash(); From 1cc4c153cac1b93b0621ebaf31df540c3e705bf8 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Tue, 23 Aug 2022 22:57:17 +0200 Subject: [PATCH 18/23] fix slash commands guild id not really valid, causing no slash commands to register --- .../bukkit/discordsrv/SlashCommandProvider.java | 2 +- .../tk/bluetree242/discordsrvutils/DiscordSRVUtils.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java index 49b50050..1b2eabe7 100644 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java @@ -53,6 +53,6 @@ public Set getSlashCommands() { private PluginSlashCommand getCmd(String alias, Command cmd) { - return new PluginSlashCommand(core, new CommandData(alias, cmd.getDescription()).addOptions(cmd.getOptions()), DiscordSRV.getPlugin().getMainGuild() + ""); + return new PluginSlashCommand(core, new CommandData(alias, cmd.getDescription()).addOptions(cmd.getOptions()), DiscordSRV.getPlugin().getMainGuild().getId()); } } diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java b/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java index c8269c31..43109422 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java @@ -294,14 +294,14 @@ public void reloadConfigs() throws IOException, InvalidConfigException { statusConfigConfManager.reloadConfig(); statusConfig = statusConfigConfManager.reloadConfigData(); levelingManager.reloadLevelingRoles(); - setSettings(); + setSettings(false); } public void whenReady() { //do it async, fixing tickets and suggestions can take long time asyncManager.executeAsync(() -> { registerListeners(); - setSettings(); + setSettings(true); pluginHookManager.hookAll(); //remove the discordsrv LinkAccount listener via reflections if (getMainConfig().remove_discordsrv_link_listener()) { @@ -325,8 +325,9 @@ public void whenReady() { } - public void setSettings() { + public void setSettings(boolean first) { if (!isReady()) return; + if (!first) DiscordSRV.api.updateSlashCommands(); OnlineStatus onlineStatus = getMainConfig().onlinestatus().equalsIgnoreCase("DND") ? OnlineStatus.DO_NOT_DISTURB : OnlineStatus.valueOf(getMainConfig().onlinestatus().toUpperCase()); getJDA().getPresence().setStatus(onlineStatus); levelingManager.cachedUUIDS.invalidateAll(); @@ -337,7 +338,6 @@ public void setSettings() { main.getStatusListener().register(); statusManager.reloadTimer(); } - DiscordSRV.api.updateSlashCommands(); } public RestAction queueMsg(Message msg, MessageChannel channel) { From 612ad08185d6936da842f442c421fd42b70e90e4 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Mon, 19 Sep 2022 23:49:33 +0200 Subject: [PATCH 19/23] listen for command event in the provider, and update some dependencies --- build.gradle | 8 +- bukkit/build.gradle | 15 ++-- .../bukkit/DiscordSRVUtilsBukkit.java | 1 + .../discordsrv/SlashCommandProvider.java | 60 +++++++++++++ .../discordsrvutils/JdaManager.java | 2 - .../commandmanagement/CommandEvent.java | 3 +- .../commandmanagement/CommandListener.java | 90 ------------------- 7 files changed, 75 insertions(+), 104 deletions(-) delete mode 100644 core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandListener.java diff --git a/build.gradle b/build.gradle index 67b01b8d..20a23798 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ allprojects { url = uri('https://repo.citizensnpcs.co') } maven { - url = uri('https://nexus.vankka.dev/repository/maven-public/') + url = uri('https://nexus.scarsz.me/repository/maven-public/') } maven { url = uri('https://repo.extendedclip.com/content/repositories/placeholderapi/') @@ -50,10 +50,6 @@ allprojects { url = uri('https://repo.codemc.org/repository/maven-public') } - maven { - url = uri('https://ci.ender.zone/plugin/repository/everything/') - } - maven { url = uri('https://papermc.io/repo/repository/maven-public/') } @@ -85,6 +81,8 @@ allprojects { maven { url "https://mvn-repo.arim.space/affero-gpl3" } maven { url "https://mvn-repo.arim.space/gpl3" } maven { url "https://mvn-repo.arim.space/lesser-gpl3" } + maven { url "https://repo.dmulloy2.net/repository/public/" } + maven { url "https://repo.essentialsx.net/releases/" } } } diff --git a/bukkit/build.gradle b/bukkit/build.gradle index cfd7c775..d2a83ecd 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -46,23 +46,28 @@ def urlFile = { url, name -> } dependencies { - implementation 'org.bstats:bstats-bukkit:2.2.1' + implementation 'org.bstats:bstats-bukkit:3.0.0' compileOnly 'org.spigotmc:spigot-api:1.16.3-R0.1-SNAPSHOT' compileOnly 'com.gitlab.ruany:LiteBansAPI:0.3.4' compileOnly 'space.arim.libertybans:bans-api:0.8.0' - compileOnly 'com.github.LeonMangler:SuperVanish:6.2.6-2' + compileOnly 'com.github.LeonMangler:SuperVanish:6.2.12' compileOnly 'com.github.DevLeoko:AdvancedBan:b4bbb6a' - compileOnly 'me.clip:placeholderapi:2.9.2' + compileOnly 'me.clip:placeholderapi:2.11.2' compileOnly urlFile("https://github.com/Zrips/CMI-API/releases/download/8.7.8.2/CMIAPI8.7.8.2.jar", "CMI-API") - compileOnly 'net.lapismc:AFKPlus:3.3.13' + compileOnly 'net.lapismc:AFKPlus:3.3.15' implementation project(":core") compileOnly('com.discordsrv:discordsrv:1.26.0-SNAPSHOT') { exclude group: 'net.kyori' } - compileOnly 'net.ess3:EssentialsX:2.17.2' + implementation 'org.jooq:jooq:3.14.16' + compileOnly 'net.essentialsx:EssentialsX:2.19.0' } test { useJUnitPlatform() +} + +repositories { + mavenCentral() } \ No newline at end of file diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java index 7a44dd02..0ef0a74a 100644 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java @@ -52,6 +52,7 @@ public void onEnable() { ((BukkitPlugin) core.getPlatform()).setDiscordSRVUtils(core); } core.onEnable(); + if (!isEnabled()) return; //bstats stuff Metrics metrics = new Metrics(this, 9456); metrics.addCustomChart(new AdvancedPie("features", () -> { diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java index 1b2eabe7..f4220b8d 100644 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java @@ -24,12 +24,20 @@ import github.scarsz.discordsrv.DiscordSRV; import github.scarsz.discordsrv.api.commands.PluginSlashCommand; +import github.scarsz.discordsrv.api.commands.SlashCommand; +import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; +import github.scarsz.discordsrv.dependencies.jda.api.events.interaction.SlashCommandEvent; +import github.scarsz.discordsrv.dependencies.jda.api.exceptions.InsufficientPermissionException; import github.scarsz.discordsrv.dependencies.jda.api.interactions.commands.build.CommandData; import lombok.RequiredArgsConstructor; +import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.bukkit.DiscordSRVUtilsBukkit; +import tk.bluetree242.discordsrvutils.embeds.Embed; import tk.bluetree242.discordsrvutils.systems.commandmanagement.Command; +import tk.bluetree242.discordsrvutils.systems.commandmanagement.CommandEvent; import tk.bluetree242.discordsrvutils.systems.commandmanagement.CommandManager; +import java.sql.SQLException; import java.util.HashSet; import java.util.Set; @@ -55,4 +63,56 @@ public Set getSlashCommands() { private PluginSlashCommand getCmd(String alias, Command cmd) { return new PluginSlashCommand(core, new CommandData(alias, cmd.getDescription()).addOptions(cmd.getOptions()), DiscordSRV.getPlugin().getMainGuild().getId()); } + + @SlashCommand(path = "*") + public void onCommand(SlashCommandEvent e) { + DiscordSRVUtils core = this.core.getCore(); + if (core.getMainConfig().bungee_mode()) return; + core.getAsyncManager().executeAsync(() -> { + String cmd = e.getName(); + Command executor = core.getCommandManager().getCommandHashMap().get(cmd); + if (executor == null || !executor.isEnabled()) return; + CommandEvent event = new CommandEvent(core, e.getMember(), e.getUser(), e.getChannel(), e.getJDA(), e); + try { + if (executor.getRequiredPermission() != null) { + if (e.getChannel() instanceof TextChannel) { + if (!e.getMember().hasPermission(executor.getRequiredPermission())) { + e.replyEmbeds(Embed.error("You don't have permission to use this command.", "Required: " + executor.getRequiredPermission())).queue(); + return; + } + } + } + if (e.getChannel() instanceof TextChannel) { + if (executor.isOwnerOnly()) { + if (!e.getMember().isOwner()) { + e.replyEmbeds(Embed.error("Only Guild Owner can use this command.")).queue(); + return; + } + } + if (executor.isAdminOnly()) { + if (!core.getJdaManager().isAdmin(e.getUser().getIdLong())) { + e.replyEmbeds(Embed.error("Only Admins can use this command.", "Your id must be in admin list on the config.yml")).queue(); + return; + } + } + } + core.getLogger().info(e.getUser().getAsTag() + " Used " + "/" + cmd + " Command"); + executor.run(event); + } catch (InsufficientPermissionException ex) { + ex.printStackTrace(); + e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!", "The bot is missing the following permission: " + ex.getPermission())).queue(); + } catch (Exception exception) { + exception.printStackTrace(); + e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!")).queue(); + } + if (event.isConnOpen()) { + try { + event.getConnection().configuration().connectionProvider().acquire().close(); + } catch (SQLException throwables) { + core.getErrorHandler().defaultHandle(throwables); + } + } + }); + + } } diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/JdaManager.java b/core/src/main/java/tk/bluetree242/discordsrvutils/JdaManager.java index 388f908d..900c17db 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/JdaManager.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/JdaManager.java @@ -30,7 +30,6 @@ import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; import lombok.Getter; import tk.bluetree242.discordsrvutils.listeners.jda.WelcomerAndGoodByeListener; -import tk.bluetree242.discordsrvutils.systems.commandmanagement.CommandListener; import tk.bluetree242.discordsrvutils.systems.invitetracking.listeners.InviteTrackingListener; import tk.bluetree242.discordsrvutils.systems.leveling.listeners.jda.DiscordLevelingListener; import tk.bluetree242.discordsrvutils.systems.suggestions.listeners.SuggestionListener; @@ -53,7 +52,6 @@ public class JdaManager { public JdaManager(DiscordSRVUtils core) { this.core = core; //Add The JDA Listeners to the List - listeners.add(new CommandListener(core)); listeners.add(new WelcomerAndGoodByeListener(core)); listeners.add(new CreatePanelListener(core)); listeners.add(new PaginationListener(core)); diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandEvent.java b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandEvent.java index c253b1ed..cdc836d9 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandEvent.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandEvent.java @@ -28,7 +28,6 @@ import github.scarsz.discordsrv.dependencies.jda.api.events.interaction.SlashCommandEvent; import github.scarsz.discordsrv.dependencies.jda.api.interactions.commands.OptionMapping; import github.scarsz.discordsrv.dependencies.jda.api.requests.restaction.interactions.ReplyAction; -import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.jooq.DSLContext; @@ -38,7 +37,7 @@ import tk.bluetree242.discordsrvutils.placeholder.PlaceholdObjectList; import tk.bluetree242.discordsrvutils.platform.PlatformPlayer; -@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +@RequiredArgsConstructor() public class CommandEvent { private final DiscordSRVUtils core; private final Member member; diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandListener.java b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandListener.java deleted file mode 100644 index 9c7fe307..00000000 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/commandmanagement/CommandListener.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * LICENSE - * DiscordSRVUtils - * ------------- - * Copyright (C) 2020 - 2022 BlueTree242 - * ------------- - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * END - */ - -package tk.bluetree242.discordsrvutils.systems.commandmanagement; - -import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel; -import github.scarsz.discordsrv.dependencies.jda.api.events.interaction.SlashCommandEvent; -import github.scarsz.discordsrv.dependencies.jda.api.exceptions.InsufficientPermissionException; -import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; -import lombok.RequiredArgsConstructor; -import org.jetbrains.annotations.NotNull; -import tk.bluetree242.discordsrvutils.DiscordSRVUtils; -import tk.bluetree242.discordsrvutils.embeds.Embed; - -import java.sql.SQLException; - -@RequiredArgsConstructor -public class CommandListener extends ListenerAdapter { - private final DiscordSRVUtils core; - - - public void onSlashCommand(@NotNull SlashCommandEvent e) { - if (core.getMainConfig().bungee_mode()) return; - core.getAsyncManager().executeAsync(() -> { - String cmd = e.getName(); - Command executor = core.getCommandManager().getCommandHashMap().get(cmd); - if (executor == null || !executor.isEnabled()) return; - CommandEvent event = new CommandEvent(core, e.getMember(), e.getUser(), e.getChannel(), e.getJDA(), e); - try { - if (executor.getRequiredPermission() != null) { - if (e.getChannel() instanceof TextChannel) { - if (!e.getMember().hasPermission(executor.getRequiredPermission())) { - e.replyEmbeds(Embed.error("You don't have permission to use this command.", "Required: " + executor.getRequiredPermission().toString())).queue(); - return; - } - } - } - if (e.getChannel() instanceof TextChannel) { - if (executor.isOwnerOnly()) { - if (!e.getMember().isOwner()) { - e.replyEmbeds(Embed.error("Only Guild Owner can use this command.")).queue(); - return; - } - } - if (executor.isAdminOnly()) { - if (!core.getJdaManager().isAdmin(e.getUser().getIdLong())) { - e.replyEmbeds(Embed.error("Only Admins can use this command.", "Your id must be in admin list on the config.yml")).queue(); - return; - } - } - } - core.getLogger().info(e.getUser().getAsTag() + " Used " + "/" + cmd + " Command"); - executor.run(event); - } catch (InsufficientPermissionException ex) { - ex.printStackTrace(); - e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!", "The bot is missing the following permission: " + ex.getPermission())).queue(); - } catch (Exception exception) { - exception.printStackTrace(); - e.replyEmbeds(Embed.error("An error happened while executing this Command. Please report to the devs!")).queue(); - } - if (event.isConnOpen()) { - try { - event.getConnection().configuration().connectionProvider().acquire().close(); - } catch (SQLException throwables) { - core.getErrorHandler().defaultHandle(throwables); - } - } - }); - - } -} From 1173e9206b83c7239a80bbc364b2cb82a3b3ef9b Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Tue, 20 Sep 2022 09:05:49 +0200 Subject: [PATCH 20/23] execute slash command on the thread the method is called instead of the thread pool --- .../discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java index f4220b8d..4ab80a65 100644 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/discordsrv/SlashCommandProvider.java @@ -68,7 +68,6 @@ private PluginSlashCommand getCmd(String alias, Command cmd) { public void onCommand(SlashCommandEvent e) { DiscordSRVUtils core = this.core.getCore(); if (core.getMainConfig().bungee_mode()) return; - core.getAsyncManager().executeAsync(() -> { String cmd = e.getName(); Command executor = core.getCommandManager().getCommandHashMap().get(cmd); if (executor == null || !executor.isEnabled()) return; @@ -112,7 +111,6 @@ public void onCommand(SlashCommandEvent e) { core.getErrorHandler().defaultHandle(throwables); } } - }); } } From 67cbddd6561a2f2ab50bfc78f3f1bc07e256d353 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Tue, 20 Sep 2022 21:33:45 +0200 Subject: [PATCH 21/23] fix leaderboard everyone being #1 (stupid mistake i made) --- .../discordsrvutils/systems/leveling/LevelingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java index f4671575..7b3c3ee8 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/systems/leveling/LevelingManager.java @@ -172,7 +172,7 @@ public List getLeaderboard(int max, DSLContext conn) { int num = 0; for (LevelingRecord record : records) { num++; - leaderboard.add(getPlayerStats(record, 1)); + leaderboard.add(getPlayerStats(record, num)); } return leaderboard; } From 541ae361d8de4b45a45b7bf8fd6850fce2ae8984 Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Tue, 20 Sep 2022 23:42:04 +0200 Subject: [PATCH 22/23] update to stable discordsrv --- bukkit/build.gradle | 4 +--- core/build.gradle | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bukkit/build.gradle b/bukkit/build.gradle index d2a83ecd..5436852a 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -56,9 +56,7 @@ dependencies { compileOnly urlFile("https://github.com/Zrips/CMI-API/releases/download/8.7.8.2/CMIAPI8.7.8.2.jar", "CMI-API") compileOnly 'net.lapismc:AFKPlus:3.3.15' implementation project(":core") - compileOnly('com.discordsrv:discordsrv:1.26.0-SNAPSHOT') { - exclude group: 'net.kyori' - } + compileOnly('com.discordsrv:discordsrv:1.26.0') implementation 'org.jooq:jooq:3.14.16' compileOnly 'net.essentialsx:EssentialsX:2.19.0' } diff --git a/core/build.gradle b/core/build.gradle index 577f1611..62ae1b4b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -69,9 +69,7 @@ dependencies { implementation 'com.zaxxer:HikariCP:3.4.5' implementation 'org.hsqldb:hsqldb:2.4.1' implementation 'org.mariadb.jdbc:mariadb-java-client:2.7.0' - compileOnly('com.discordsrv:discordsrv:1.26.0-SNAPSHOT') { - exclude group: 'net.kyori' - } + compileOnly('com.discordsrv:discordsrv:1.26.0') implementation "org.flywaydb:flyway-core:7.5.3" implementation group: 'org.json', name: 'json', version: '20210307' implementation 'com.github.ben-manes.caffeine:caffeine:2.9.1' From e133adbd19535d32a5adda62d5bd1a010809492e Mon Sep 17 00:00:00 2001 From: Blue Tree <69328929+BlueTree242@users.noreply.github.com> Date: Tue, 20 Sep 2022 23:42:30 +0200 Subject: [PATCH 23/23] remove custom link listener, removing discordsrv's link listener and custom link channel because they are useless now --- .../bukkit/DiscordSRVUtilsBukkit.java | 2 - .../jda/CustomDiscordAccountLinkListener.java | 73 ------------------- .../discordsrvutils/DiscordSRVUtils.java | 11 --- .../discordsrvutils/config/Config.java | 18 ----- 4 files changed, 104 deletions(-) delete mode 100644 bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/listeners/jda/CustomDiscordAccountLinkListener.java diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java index 0ef0a74a..c0f2bfe7 100644 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java +++ b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/DiscordSRVUtilsBukkit.java @@ -30,7 +30,6 @@ import org.bukkit.plugin.java.JavaPlugin; import tk.bluetree242.discordsrvutils.DiscordSRVUtils; import tk.bluetree242.discordsrvutils.bukkit.discordsrv.SlashCommandProvider; -import tk.bluetree242.discordsrvutils.bukkit.listeners.jda.CustomDiscordAccountLinkListener; import java.util.HashMap; import java.util.Map; @@ -92,7 +91,6 @@ public void onLoad() { if (getServer().getPluginManager().getPlugin("DiscordSRV") != null) { core = new DiscordSRVUtils(new BukkitPlugin(this)); ((BukkitPlugin) core.getPlatform()).setDiscordSRVUtils(core); - core.getJdaManager().getListeners().add(new CustomDiscordAccountLinkListener(core)); } } diff --git a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/listeners/jda/CustomDiscordAccountLinkListener.java b/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/listeners/jda/CustomDiscordAccountLinkListener.java deleted file mode 100644 index eee9dfef..00000000 --- a/bukkit/src/main/java/tk/bluetree242/discordsrvutils/bukkit/listeners/jda/CustomDiscordAccountLinkListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * LICENSE - * DiscordSRVUtils - * ------------- - * Copyright (C) 2020 - 2022 BlueTree242 - * ------------- - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * END - */ - -package tk.bluetree242.discordsrvutils.bukkit.listeners.jda; - -import github.scarsz.discordsrv.Debug; -import github.scarsz.discordsrv.DiscordSRV; -import github.scarsz.discordsrv.dependencies.jda.api.entities.Role; -import github.scarsz.discordsrv.dependencies.jda.api.events.guild.member.GuildMemberJoinEvent; -import github.scarsz.discordsrv.dependencies.jda.api.events.message.guild.GuildMessageReceivedEvent; -import github.scarsz.discordsrv.dependencies.jda.api.hooks.ListenerAdapter; -import github.scarsz.discordsrv.util.DiscordUtil; -import lombok.RequiredArgsConstructor; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.jetbrains.annotations.NotNull; -import tk.bluetree242.discordsrvutils.DiscordSRVUtils; - -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -@RequiredArgsConstructor -public class CustomDiscordAccountLinkListener extends ListenerAdapter { - private final DiscordSRVUtils core; - - // Original From DiscordAccountLinkListener DiscordSRV Class - public void onGuildMessageReceived(GuildMessageReceivedEvent event) { - if (event.getChannel().getIdLong() != core.getMainConfig().linkaccount_channel()) return; - if (core.getMainConfig().linkaccount_channel_delete_messages_delay() != 0L) - event.getMessage().delete().queueAfter(core.getMainConfig().linkaccount_channel_delete_messages_delay(), TimeUnit.SECONDS); - if (event.getAuthor().isBot()) return; - String response = DiscordSRV.getPlugin().getAccountLinkManager().process(event.getMessage().getContentRaw(), event.getAuthor().getId()); - if (response != null) event.getMessage().reply(response).queue(); - } - - - public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) { - if (!core.isRemovedDiscordSRVAccountLinkListener()) return; - // add linked role and nickname back to people when they rejoin the server - UUID uuid = DiscordSRV.getPlugin().getAccountLinkManager().getUuid(event.getUser().getId()); - if (uuid != null) { - Role roleToAdd = DiscordUtil.resolveRole(DiscordSRV.config().getString("MinecraftDiscordAccountLinkedRoleNameToAddUserTo")); - if (roleToAdd != null) DiscordUtil.addRoleToMember(event.getMember(), roleToAdd); - else DiscordSRV.debug(Debug.GROUP_SYNC, "Couldn't add user to null role"); - - if (DiscordSRV.config().getBoolean("NicknameSynchronizationEnabled")) { - OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); - DiscordSRV.getPlugin().getNicknameUpdater().setNickname(event.getMember(), player); - } - } - } - - -} diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java b/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java index 43109422..5e1e0cfc 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/DiscordSRVUtils.java @@ -121,8 +121,6 @@ public class DiscordSRVUtils { private LevelingConfig levelingConfig; //was the DiscordSRV AccountLink Listener Removed? @Getter - private boolean removedDiscordSRVAccountLinkListener = false; - @Getter private SuggestionsConfig suggestionsConfig; private ConfManager sqlconfigmanager; @Getter @@ -303,15 +301,6 @@ public void whenReady() { registerListeners(); setSettings(true); pluginHookManager.hookAll(); - //remove the discordsrv LinkAccount listener via reflections - if (getMainConfig().remove_discordsrv_link_listener()) { - for (Object listener : getJDA().getEventManager().getRegisteredListeners()) { - if (listener.getClass().getName().equals("github.scarsz.discordsrv.listeners.DiscordAccountLinkListener")) { - getJDA().removeEventListener(listener); - removedDiscordSRVAccountLinkListener = true; - } - } - } if (!inviteTrackingManager.cacheInvites()) errorHandler.severe("Bot does not have the MANAGE_SERVER permission, we cannot make detect inviter when someone joins, please grant the permission."); //fix issues with any ticket or panel diff --git a/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java b/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java index 4d8cdfbc..e8a92d17 100644 --- a/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java +++ b/core/src/main/java/tk/bluetree242/discordsrvutils/config/Config.java @@ -46,24 +46,6 @@ public interface Config { @ConfDefault.DefaultString("ONLINE") String onlinestatus(); - @AnnotationBasedSorter.Order(31) - @ConfKey("remove-discordsrv-link-listener") - @ConfComments("#Should we remove DiscordSRV's account link listener?? bot won't respond to dm link codes\n#NOTE: Plugin uses reflection to do this. Which is like hacking into DiscordSRV") - @ConfDefault.DefaultBoolean(false) - boolean remove_discordsrv_link_listener(); - - @AnnotationBasedSorter.Order(32) - @ConfKey("linkaccount-channel") - @ConfComments("#Custom LinkAccount Channel. ") - @ConfDefault.DefaultLong(0) - long linkaccount_channel(); - - @AnnotationBasedSorter.Order(33) - @ConfKey("linkaccount-channel-delete-messages-delay") - @ConfComments("#Amount of time in seconds to delete messages sent in the link account channel, set 0 to not delete at all") - @ConfDefault.DefaultLong(10) - long linkaccount_channel_delete_messages_delay(); - @AnnotationBasedSorter.Order(34) @ConfKey("disabled-commands") @ConfComments("# Commands that must be disabled, will also hide from help command, Don't use aliases here")