1212import net .kyori .adventure .text .minimessage .tag .resolver .Placeholder ;
1313import net .onelitefeather .antiredstoneclockremastered .AntiRedstoneClockRemastered ;
1414import net .onelitefeather .antiredstoneclockremastered .service .api .NotificationService ;
15+ import org .bukkit .Bukkit ;
1516import org .bukkit .Location ;
1617import org .bukkit .configuration .Configuration ;
1718import org .bukkit .configuration .MemoryConfiguration ;
2021import org .jetbrains .annotations .NotNull ;
2122import org .jetbrains .annotations .Nullable ;
2223
24+ import java .net .URL ;
2325import java .util .HashMap ;
2426import java .util .List ;
2527import 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 }
0 commit comments