From 64ceeb155fc9c7d13d37ff6ebc6afc89ad49cb20 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 24 Sep 2024 15:50:46 +0200 Subject: [PATCH 1/9] Add "Shared Bot" menu back --- src/main/java/net/clementraynaud/skoice/lang/DiscordLang.java | 1 + src/main/java/net/clementraynaud/skoice/menus/MenuEmoji.java | 1 + src/main/resources/discord/lang/EN.yml | 3 +++ src/main/resources/discord/menus/fields.yml | 3 +++ src/main/resources/discord/menus/menus.yml | 4 ++++ 5 files changed, 12 insertions(+) diff --git a/src/main/java/net/clementraynaud/skoice/lang/DiscordLang.java b/src/main/java/net/clementraynaud/skoice/lang/DiscordLang.java index f48127de..e68f5441 100644 --- a/src/main/java/net/clementraynaud/skoice/lang/DiscordLang.java +++ b/src/main/java/net/clementraynaud/skoice/lang/DiscordLang.java @@ -34,6 +34,7 @@ protected void loadFormatter() { super.formatter.set("open-collective-url", "https://opencollective.com/skoice"); super.formatter.set("github-url", "https://github.com/Skoice/skoice"); super.formatter.set("crowdin-url", "https://crowdin.com/project/skoice"); + super.formatter.set("creation-guide-url", "https://github.com/Skoice/skoice/wiki/Creating-a-Discord-Bot-for-Skoice"); super.formatter.set("link-minecraft-command", "/skoice link"); } diff --git a/src/main/java/net/clementraynaud/skoice/menus/MenuEmoji.java b/src/main/java/net/clementraynaud/skoice/menus/MenuEmoji.java index d0f58524..6085a44c 100644 --- a/src/main/java/net/clementraynaud/skoice/menus/MenuEmoji.java +++ b/src/main/java/net/clementraynaud/skoice/menus/MenuEmoji.java @@ -59,6 +59,7 @@ public enum MenuEmoji { QUESTION("U+2753"), REPEAT("U+1F501"), REPEAT_ONE("U+1F502"), + ROBOT("U+1F916"), SCREWDRIVER("U+1FA9B"), SKULL("U+1F480"), SOUND("U+1F509"), diff --git a/src/main/resources/discord/lang/EN.yml b/src/main/resources/discord/lang/EN.yml index 274f2c3e..07ffcb7f 100644 --- a/src/main/resources/discord/lang/EN.yml +++ b/src/main/resources/discord/lang/EN.yml @@ -212,6 +212,9 @@ field: proximity-channel-deleted: title: "Proximity Channel Deleted" description: "You have deleted a channel used by the proximity voice chat. These channels are automatically deleted when they are no longer needed. You should not be doing it manually." + shared-bot: + title: "Shared Bot" + description: "It seems like your bot is running multiple programs. However, it must be dedicated to Skoice in order to work properly. You can create a new one by [following these instructions]({creation-guide-url}). Once you have retrieved its token, type `{token-minecraft-command}` followed by the token on your Minecraft server. If your bot is not running multiple programs, please ask for help on our Discord server by pressing the button below." button-label: back: "Back" configure-now: "Configure Now" diff --git a/src/main/resources/discord/menus/fields.yml b/src/main/resources/discord/menus/fields.yml index 6ba592a1..3e5ea969 100644 --- a/src/main/resources/discord/menus/fields.yml +++ b/src/main/resources/discord/menus/fields.yml @@ -83,4 +83,7 @@ illegal-value: inline: false proximity-channel-deleted: emoji: x + inline: false +shared-bot: + emoji: robot inline: false \ No newline at end of file diff --git a/src/main/resources/discord/menus/menus.yml b/src/main/resources/discord/menus/menus.yml index 7dc88878..7b4bf22a 100644 --- a/src/main/resources/discord/menus/menus.yml +++ b/src/main/resources/discord/menus/menus.yml @@ -84,6 +84,10 @@ error: type: error fields: - proximity-channel-deleted + shared-bot: + type: error + fields: + - shared-bot voice-chat: emoji: speaking_head From 4ff29dba3c832b5c74090af724db604f6ec77fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Raynaud?= <30211659+carlodrift@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:40:38 +0200 Subject: [PATCH 2/9] Fix auto updater on Windows systems --- src/main/java/net/clementraynaud/skoice/Updater.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/clementraynaud/skoice/Updater.java b/src/main/java/net/clementraynaud/skoice/Updater.java index c2ed70f1..232f4036 100644 --- a/src/main/java/net/clementraynaud/skoice/Updater.java +++ b/src/main/java/net/clementraynaud/skoice/Updater.java @@ -139,9 +139,13 @@ private synchronized void update(String version, String expectedHash) { .transferFrom(Channels.newChannel(connection.getInputStream()), 0, Long.MAX_VALUE); if (this.verifyFileIntegrity(tempUpdateFile, expectedHash)) { - Files.move(tempUpdateFile.toPath(), finalUpdateFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + Files.copy(tempUpdateFile.toPath(), finalUpdateFile.toPath(), StandardCopyOption.REPLACE_EXISTING); this.downloadedVersion = version; this.plugin.getLogger().info(this.plugin.getLang().getMessage("logger.info.plugin-updated")); + try { + Files.delete(tempUpdateFile.toPath()); + } catch (IOException ignored) { + } } else { throw new IOException("File integrity check failed"); } From 4317b22e7ee1e3ffa5525eb27c41f1f39407e0f6 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 16 Sep 2024 23:03:32 +0200 Subject: [PATCH 3/9] Add old bot warning --- .../skoice/listeners/session/ReadyListener.java | 10 +++++++++- src/main/resources/minecraft/lang/EN.yml | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java b/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java index b5931128..3cbbf17e 100644 --- a/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java +++ b/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java @@ -34,6 +34,8 @@ import net.kyori.adventure.text.event.HoverEvent; import org.bukkit.entity.Player; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; import java.util.function.Consumer; public class ReadyListener extends ListenerAdapter { @@ -49,7 +51,7 @@ public void onReady(ReadyEvent event) { Player tokenManager = this.plugin.getBot().getTokenManager(); - this.plugin.getBot().getJDA().retrieveApplicationInfo().queue(applicationInfo -> { + event.getJDA().retrieveApplicationInfo().queue(applicationInfo -> { if (applicationInfo.isBotPublic()) { this.handlePublicBot(tokenManager); return; @@ -57,6 +59,12 @@ public void onReady(ReadyEvent event) { this.plugin.getLogger().info(this.plugin.getLang().getMessage("logger.info.bot-connected")); + if (tokenManager != null + && event.getJDA().getSelfUser().getTimeCreated().isBefore(OffsetDateTime.now().minusDays(1))) { + this.plugin.getLogger().warning(this.plugin.getLang().getMessage("logger.warning.old-bot")); + tokenManager.sendMessage(this.plugin.getLang().getMessage("chat.configuration.old-bot")); + } + applicationInfo.setRequiredScopes("applications.commands"); this.plugin.getBot().setInviteUrl(applicationInfo.getInviteUrl(Permission.ADMINISTRATOR)); diff --git a/src/main/resources/minecraft/lang/EN.yml b/src/main/resources/minecraft/lang/EN.yml index e351586b..7df4fd36 100644 --- a/src/main/resources/minecraft/lang/EN.yml +++ b/src/main/resources/minecraft/lang/EN.yml @@ -27,6 +27,7 @@ logger: two-factor-authentication: "Two-factor authentication required. Enable two-factor authentication on the bot owner's account or disable \"Require 2FA for moderator actions\" in server settings." no-voice-channel: "Voice channel not set. Type \"/configure\" on your Discord server to set up Skoice." no-radius: "Radius not set. Type \"/configure\" on your Discord server to set up Skoice." + old-bot: "You are using an old bot. Make sure it is configured as indicated and you only use it for Skoice." error: missing-permission: "You did not grant your bot the \"Administrator\" permission on your Discord server. Open this link to add it: %s." bot-could-not-connect: "Your bot could not connect. To update the token, type \"/skoice token\" followed by the new token." @@ -49,6 +50,7 @@ chat: bot-connecting: "%s Your bot is &aattempting to connect&7." bot-connected: "%s Your bot is &anow connected&7." bot-connected-incomplete-configuration-discord: "%s Your bot is &anow connected&7. Type \"&e/configure&7\" on your Discord server to set it up." + old-bot: "%s You are &cusing an old bot&7. Make sure it is configured as indicated and you only use it for Skoice." bot-already-connected: "%s You have &aupdated the token&7. Restart your Minecraft server to connect your bot." bot-could-not-connect: "%s Your bot &ccould not connect&7. Try again with a valid token." invalid-bot: "%s Your bot is &cnot configured correctly&7. Please follow the instructions again to create a new one." From a80fdcf3d94a08bb6b1fc5c0b41953b23a661092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Raynaud?= <30211659+carlodrift@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:54:16 +0200 Subject: [PATCH 4/9] Fix ConcurrentModificationException in Network --- .../clementraynaud/skoice/system/Network.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/clementraynaud/skoice/system/Network.java b/src/main/java/net/clementraynaud/skoice/system/Network.java index 2efdf195..498e5884 100644 --- a/src/main/java/net/clementraynaud/skoice/system/Network.java +++ b/src/main/java/net/clementraynaud/skoice/system/Network.java @@ -20,23 +20,26 @@ package net.clementraynaud.skoice.system; import net.clementraynaud.skoice.Skoice; +import net.clementraynaud.skoice.util.ThreadUtil; import org.bukkit.entity.Player; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; public class Network { private final Skoice plugin; - private final Set players; + private final Set players = ConcurrentHashMap.newKeySet(); private ProximityChannel proximityChannel; public Network(Skoice plugin, Set players) { + ThreadUtil.ensureNotMainThread(); this.plugin = plugin; - this.players = players; + this.players.addAll(players); Networks.add(this); } @@ -48,6 +51,7 @@ public void build() { } public boolean canPlayerConnect(LinkedPlayer player) { + ThreadUtil.ensureNotMainThread(); if (!player.isStateEligible()) { return false; } @@ -58,6 +62,7 @@ public boolean canPlayerConnect(LinkedPlayer player) { } public boolean canPlayerStayConnected(LinkedPlayer player) { + ThreadUtil.ensureNotMainThread(); if (!player.isStateEligible()) { return false; } @@ -68,6 +73,7 @@ public boolean canPlayerStayConnected(LinkedPlayer player) { } public void splitIfSpread() { + ThreadUtil.ensureNotMainThread(); if (this.size() < 4) { return; } @@ -110,35 +116,43 @@ private Set getChainingPlayers(Set chainingPlayers, } public void engulf(Network network) { + ThreadUtil.ensureNotMainThread(); this.players.addAll(network.players); network.players.clear(); } public void clear() { + ThreadUtil.ensureNotMainThread(); this.players.clear(); } public void add(LinkedPlayer player) { + ThreadUtil.ensureNotMainThread(); this.players.add(player); } public void remove(LinkedPlayer player) { + ThreadUtil.ensureNotMainThread(); this.players.remove(player); } public void remove(Player player) { + ThreadUtil.ensureNotMainThread(); this.players.removeIf(p -> p.getBukkitPlayer().equals(player)); } public boolean contains(LinkedPlayer player) { + ThreadUtil.ensureNotMainThread(); return this.players.contains(player); } public boolean contains(Player player) { + ThreadUtil.ensureNotMainThread(); return this.players.stream().anyMatch(p -> p.getBukkitPlayer().equals(player)); } public int size() { + ThreadUtil.ensureNotMainThread(); return this.players.size(); } From 4ffd892584107ccb754d0b09040bc6bc7bf97a21 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 21 Sep 2024 23:43:04 +0200 Subject: [PATCH 5/9] Update dependencies --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 93cad621..42d6bce3 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.junit junit-bom - 5.11.0 + 5.11.1 pom import @@ -222,12 +222,12 @@ org.bstats bstats-bukkit - 3.0.3 + 3.1.0 net.dv8tion JDA - 5.1.0 + 5.1.1 club.minnced From 5503c9a91ebcc66825480f2b865ceac9cbd561be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Raynaud?= <30211659+carlodrift@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:48:30 +0200 Subject: [PATCH 6/9] Make main thread checks disabled in production --- .../java/net/clementraynaud/skoice/util/ThreadUtil.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/clementraynaud/skoice/util/ThreadUtil.java b/src/main/java/net/clementraynaud/skoice/util/ThreadUtil.java index 63df529c..f317d1dd 100644 --- a/src/main/java/net/clementraynaud/skoice/util/ThreadUtil.java +++ b/src/main/java/net/clementraynaud/skoice/util/ThreadUtil.java @@ -19,20 +19,19 @@ package net.clementraynaud.skoice.util; -import com.bugsnag.Severity; -import net.clementraynaud.skoice.Skoice; import org.bukkit.Bukkit; public final class ThreadUtil { + private static final boolean DEBUG = false; + private ThreadUtil() { } public static void ensureNotMainThread(boolean disablingBypass) { - if (Bukkit.isPrimaryThread() && (!disablingBypass || Bukkit.getPluginManager().isPluginEnabled("Skoice"))) { + if (ThreadUtil.DEBUG && Bukkit.isPrimaryThread() && (!disablingBypass || Bukkit.getPluginManager().isPluginEnabled("Skoice"))) { Exception exception = new IllegalStateException("This method should not be called from the main thread."); exception.printStackTrace(); - Skoice.analyticManager().getBugsnag().notify(exception, Severity.WARNING); } } From 53c24c0f070e881f8a2dc8f23c8a268f4d1c8e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Raynaud?= <30211659+carlodrift@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:51:31 +0200 Subject: [PATCH 7/9] Update dependabot.yml --- .github/dependabot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f373bc65..fb4f6a2a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,5 +3,5 @@ updates: - package-ecosystem: "maven" directory: "/" schedule: - interval: "weekly" - target-branch: "dev" + interval: "daily" + target-branch: "release" From 4962769ab326255ecb52486dd0805de46b13ba39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Raynaud?= <30211659+carlodrift@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:23:56 +0200 Subject: [PATCH 8/9] Add warning when bot is running multiple programs --- .../skoice/listeners/session/ReadyListener.java | 5 ++++- src/main/resources/minecraft/lang/EN.yml | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java b/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java index 3cbbf17e..1507078a 100644 --- a/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java +++ b/src/main/java/net/clementraynaud/skoice/listeners/session/ReadyListener.java @@ -35,7 +35,6 @@ import org.bukkit.entity.Player; import java.time.OffsetDateTime; -import java.time.temporal.ChronoUnit; import java.util.function.Consumer; public class ReadyListener extends ListenerAdapter { @@ -87,6 +86,10 @@ private void setDefaultFailure() { this.plugin.getListenerManager().update(); return; } + if (error.getErrorCode() == ErrorResponse.INTERACTION_ALREADY_ACKNOWLEDGED.getCode() || (error.getErrorCode() == ErrorResponse.UNKNOWN_INTERACTION.getCode() && error.getMessage().startsWith("10062: Failed to acknowledge this interaction, this can be due to 2 reasons"))) { + this.plugin.getLogger().warning(this.plugin.getLang().getMessage("logger.warning.shared-bot", "https://github.com/Skoice/skoice/wiki/Creating-a-Discord-Bot-for-Skoice")); + return; + } } else if (throwable instanceof PermissionException) { this.plugin.getListenerManager().update(); return; diff --git a/src/main/resources/minecraft/lang/EN.yml b/src/main/resources/minecraft/lang/EN.yml index 7df4fd36..41f6df54 100644 --- a/src/main/resources/minecraft/lang/EN.yml +++ b/src/main/resources/minecraft/lang/EN.yml @@ -28,6 +28,7 @@ logger: no-voice-channel: "Voice channel not set. Type \"/configure\" on your Discord server to set up Skoice." no-radius: "Radius not set. Type \"/configure\" on your Discord server to set up Skoice." old-bot: "You are using an old bot. Make sure it is configured as indicated and you only use it for Skoice." + shared-bot: "It seems like your bot is running multiple programs. However, it must be dedicated to Skoice in order to work properly. You can create a new one by following the instructions on this page: %s. Once you have retrieved its token, type \"/skoice token\" followed by the token." error: missing-permission: "You did not grant your bot the \"Administrator\" permission on your Discord server. Open this link to add it: %s." bot-could-not-connect: "Your bot could not connect. To update the token, type \"/skoice token\" followed by the new token." From 517c905e1fe8376125b7a864ff68e1165b01f28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Raynaud?= <30211659+carlodrift@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:41:26 +0200 Subject: [PATCH 9/9] Version bump --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 42d6bce3..ffc3bb2a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.clementraynaud skoice - 3.2.1 + 3.2.2 jar skoice