2020
2121import dev .hypera .ultrastaffchat .UltraStaffChat ;
2222import dev .hypera .ultrastaffchat .utils .DiscordWebhook .EmbedObject ;
23- import net .md_5 .bungee .api .ChatColor ;
2423import net .md_5 .bungee .api .CommandSender ;
2524import net .md_5 .bungee .api .ProxyServer ;
2625import net .md_5 .bungee .api .connection .ProxiedPlayer ;
@@ -37,35 +36,25 @@ public class Discord {
3736 private static String hookURL = "" ;
3837
3938 public static void setup () {
40- if (!UltraStaffChat .getConfig ().getBoolean ("discord-enabled" ).equals (true ))
39+ Configuration config = UltraStaffChat .getConfig ().getConfiguration ();
40+ if (!config .getBoolean ("discord-enabled" ))
4141 return ;
42- if (UltraStaffChat . getConfig (). getString ("discord-webhook" ) == null || UltraStaffChat . getConfig () .getString ("discord-webhook" ).contains ("XXXXXXXXXXXXXXXXXX" )) {
42+ if (config . getString ("discord-webhook" ) == null || config .getString ("discord-webhook" ).contains ("XXXXXXXXXXXXXXXXXX" )) {
4343 Common .logPrefix ("&cError: Discord messages are enabled but the webhook URL has not been configured!" );
4444 return ;
4545 }
4646
47- Configuration config = UltraStaffChat .getConfig ().getConfiguration ();
48- if (config .getSection ("discord-format.embed.fields" ).getKeys ().size () > 25 ) {
49- Common .logPrefix ("&cError: You can have a max of 25 fields in an embed." );
50- return ;
51- } else if (config .getSection ("discord-join-format.embed.fields" ).getKeys ().size () > 25 ) {
52- Common .logPrefix ("&cError: You can have a max of 25 fields in an embed." );
53- return ;
54- } else if (config .getSection ("discord-leave-format.embed.fields" ).getKeys ().size () > 25 ) {
55- Common .logPrefix ("&cError: You can have a max of 25 fields in an embed." );
56- return ;
57- } else if (config .getSection ("discord-switch-format.embed.fields" ).getKeys ().size () > 25 ) {
58- Common .logPrefix ("&cError: You can have a max of 25 fields in an embed." );
59- return ;
60- } else if (config .getSection ("discord-afk-enable-format.embed.fields" ).getKeys ().size () > 25 ) {
61- Common .logPrefix ("&cError: You can have a max of 25 fields in an embed." );
62- return ;
63- } else if (config .getSection ("discord-afk-disable-format.embed.fields" ).getKeys ().size () > 25 ) {
47+ if (config .getSection ("discord-format.embed.fields" ).getKeys ().size () > 25
48+ || config .getSection ("discord-join-format.embed.fields" ).getKeys ().size () > 25
49+ || config .getSection ("discord-leave-format.embed.fields" ).getKeys ().size () > 25
50+ || config .getSection ("discord-switch-format.embed.fields" ).getKeys ().size () > 25
51+ || config .getSection ("discord-afk-enable-format.embed.fields" ).getKeys ().size () > 25
52+ || config .getSection ("discord-afk-disable-format.embed.fields" ).getKeys ().size () > 25 ) {
6453 Common .logPrefix ("&cError: You can have a max of 25 fields in an embed." );
6554 return ;
6655 }
6756
68- hookURL = UltraStaffChat . getConfig () .getString ("discord-webhook" );
57+ hookURL = config .getString ("discord-webhook" );
6958 enabled = true ;
7059 }
7160
@@ -79,7 +68,7 @@ public static boolean isEnabled() {
7968 }
8069
8170 public static void broadcastDiscordJoin (ProxiedPlayer p ) {
82- if (!isEnabled ())
71+ if (!isEnabled () && UltraStaffChat . getConfig (). getConfiguration (). getBoolean ( "discord-join-messages" ) )
8372 return ;
8473 ProxyServer .getInstance ().getScheduler ().runAsync (UltraStaffChat .getInstance (), () -> {
8574 try {
@@ -113,7 +102,7 @@ public static void broadcastDiscordJoin(ProxiedPlayer p) {
113102 }
114103
115104 public static void broadcastDiscordLeave (ProxiedPlayer p ) {
116- if (!isEnabled ())
105+ if (!isEnabled () && UltraStaffChat . getConfig (). getConfiguration (). getBoolean ( "discord-leave-messages" ) )
117106 return ;
118107 ProxyServer .getInstance ().getScheduler ().runAsync (UltraStaffChat .getInstance (), () -> {
119108 try {
@@ -148,7 +137,7 @@ public static void broadcastDiscordLeave(ProxiedPlayer p) {
148137 }
149138
150139 public static void broadcastDiscordSwitch (ProxiedPlayer p , String from , String to ) {
151- if (!isEnabled ())
140+ if (!isEnabled () && UltraStaffChat . getConfig (). getConfiguration (). getBoolean ( "discord-switch-messages" ) )
152141 return ;
153142 ProxyServer .getInstance ().getScheduler ().runAsync (UltraStaffChat .getInstance (), () -> {
154143 try {
@@ -226,7 +215,7 @@ public static void broadcastDiscordStaffChatMessage(CommandSender s, String mess
226215 }
227216
228217 public static void broadcastDiscordAFKEnable (ProxiedPlayer p ) {
229- if (!isEnabled ())
218+ if (!isEnabled () && UltraStaffChat . getConfig (). getConfiguration (). getBoolean ( "discord-afk-enable-messages" ) )
230219 return ;
231220 ProxyServer .getInstance ().getScheduler ().runAsync (UltraStaffChat .getInstance (), () -> {
232221 try {
@@ -261,7 +250,7 @@ public static void broadcastDiscordAFKEnable(ProxiedPlayer p) {
261250 }
262251
263252 public static void broadcastDiscordAFKDisable (ProxiedPlayer p ) {
264- if (!isEnabled ())
253+ if (!isEnabled () && UltraStaffChat . getConfig (). getConfiguration (). getBoolean ( "discord-afk-disable-messages" ) )
265254 return ;
266255 ProxyServer .getInstance ().getScheduler ().runAsync (UltraStaffChat .getInstance (), () -> {
267256 try {
0 commit comments