Skip to content

Commit b9f196b

Browse files
committed
feat: improve Discord webhook handling and error logging
1 parent bf77855 commit b9f196b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/net/onelitefeather/antiredstoneclockremastered/service/impl/DiscordNotificationService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1313
import net.onelitefeather.antiredstoneclockremastered.AntiRedstoneClockRemastered;
1414
import net.onelitefeather.antiredstoneclockremastered.service.api.NotificationService;
15+
import org.bukkit.Bukkit;
1516
import org.bukkit.Location;
1617
import org.bukkit.configuration.Configuration;
1718
import org.bukkit.configuration.MemoryConfiguration;
@@ -20,6 +21,7 @@
2021
import org.jetbrains.annotations.NotNull;
2122
import org.jetbrains.annotations.Nullable;
2223

24+
import java.net.URL;
2325
import java.util.HashMap;
2426
import java.util.List;
2527
import java.util.Map;
@@ -39,10 +41,22 @@ public DiscordNotificationService(@NotNull AntiRedstoneClockRemastered plugin,
3941
}
4042

4143
private WebhookClient createWebHook() {
44+
if (this.plugin.getConfig().getString("notification.discord.webhook", "").isEmpty()) return null;
45+
if (!this.plugin.getConfig().getStringList("notification.discord.enabled").contains("discord")) return null;
46+
try {
47+
var url = new URL(this.plugin.getConfig().getString("notification.discord.webhook", ""));
48+
} catch (Exception e) {
49+
LOGGER.error("Failed to create webhook client. Please check your webhook URL in the config.yml");
50+
LOGGER.error("Disabling plugin...");
51+
Bukkit.getPluginManager().disablePlugin(this.plugin);
52+
return null;
53+
}
4254
try {
4355
return WebhookClient.withUrl(this.plugin.getConfig().getString("notification.discord.webhook", ""));
4456
} catch (IllegalArgumentException e) {
45-
LOGGER.error("Failed to create webhook client");
57+
LOGGER.error("Failed to create webhook client. Please check your webhook URL in the config.yml");
58+
LOGGER.error("Disabling plugin...");
59+
Bukkit.getPluginManager().disablePlugin(this.plugin);
4660
return null;
4761
}
4862
}

src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ notification:
4545

4646
sign:
4747
material: OAK_SIGN
48+
# Should be a list of strings for each line of the sign
49+
# The max length of each line is 16 characters
4850
front:
4951
- "<red>RedstoneClocks!"
5052
- "<red>Are"

0 commit comments

Comments
 (0)