56
56
import tk .bluetree242 .discordsrvutils .commandmanagement .CommandManager ;
57
57
import tk .bluetree242 .discordsrvutils .commands .bukkit .DiscordSRVUtilsCommand ;
58
58
import tk .bluetree242 .discordsrvutils .commands .bukkit .tabcompleters .DiscordSRVUtilsTabCompleter ;
59
- import tk .bluetree242 .discordsrvutils .commands .discord .* ;
59
+ import tk .bluetree242 .discordsrvutils .commands .discord .HelpCommand ;
60
60
import tk .bluetree242 .discordsrvutils .commands .discord .admin .TestMessageCommand ;
61
61
import tk .bluetree242 .discordsrvutils .commands .discord .leveling .LeaderboardCommand ;
62
62
import tk .bluetree242 .discordsrvutils .commands .discord .leveling .LevelCommand ;
72
72
import tk .bluetree242 .discordsrvutils .leveling .LevelingManager ;
73
73
import tk .bluetree242 .discordsrvutils .leveling .listeners .bukkit .BukkitLevelingListener ;
74
74
import tk .bluetree242 .discordsrvutils .leveling .listeners .jda .DiscordLevelingListener ;
75
+ import tk .bluetree242 .discordsrvutils .listeners .afk .CMIAfkListener ;
75
76
import tk .bluetree242 .discordsrvutils .listeners .afk .EssentialsAFKListener ;
76
77
import tk .bluetree242 .discordsrvutils .listeners .bukkit .JoinUpdateChecker ;
77
78
import tk .bluetree242 .discordsrvutils .listeners .discordsrv .DiscordSRVListener ;
@@ -151,6 +152,7 @@ public class DiscordSRVUtils extends JavaPlugin {
151
152
private ConfManager <SuggestionsConfig > suggestionsConfigManager = ConfManager .create (getDataFolder ().toPath (), "suggestions.yml" , SuggestionsConfig .class );
152
153
private SuggestionsConfig suggestionsConfig ;
153
154
155
+
154
156
//Thread Pool
155
157
private ThreadPoolExecutor pool ;
156
158
//Our DiscordSRV Listener
@@ -159,6 +161,7 @@ public class DiscordSRVUtils extends JavaPlugin {
159
161
private HikariDataSource sql ;
160
162
//listeners that should be registered
161
163
private List <ListenerAdapter > listeners = new ArrayList <>();
164
+ private long lastErrorTime = 0 ;
162
165
163
166
public static DiscordSRVUtils get () {
164
167
return instance ;
@@ -210,6 +213,11 @@ public void onLoad() {
210
213
init ();
211
214
//require intents and cacheflags
212
215
if (getServer ().getPluginManager ().getPlugin ("DiscordSRV" ) != null ) {
216
+ if (DiscordSRV .isReady ) {
217
+ //Oh no, they are using a plugin manager to reload the plugin, give them a warn
218
+ logger .warning ("It seems like you are using a Plugin Manager to reload the plugin. This is not a good practice. If you see problems. Please restart" );
219
+ return ;
220
+ }
213
221
DiscordSRV .api .requireIntent (GatewayIntent .GUILD_MESSAGE_REACTIONS );
214
222
DiscordSRV .api .requireCacheFlag (CacheFlag .EMOTE );
215
223
}
@@ -301,7 +309,7 @@ public void onEnable() {
301
309
return ;
302
310
}
303
311
//initialize pool
304
- pool = (ThreadPoolExecutor ) Executors .newFixedThreadPool (config .pool_size (), new ThreadFactory () {
312
+ pool = (ThreadPoolExecutor ) Executors .newFixedThreadPool (config .pool_size (), new ThreadFactory () {
305
313
@ Override
306
314
public Thread newThread (@ NotNull Runnable r ) {
307
315
@@ -355,7 +363,7 @@ public void registerBukkitCommands() {
355
363
getCommand ("discordsrvutils" ).setTabCompleter (new DiscordSRVUtilsTabCompleter ());
356
364
}
357
365
358
- private void startupError (Throwable ex ,@ NotNull String msg ) {
366
+ private void startupError (Throwable ex , @ NotNull String msg ) {
359
367
setEnabled (false );
360
368
logger .warning (msg );
361
369
try {
@@ -365,7 +373,7 @@ private void startupError(Throwable ex,@NotNull String msg) {
365
373
e .printStackTrace ();
366
374
}
367
375
//tell them where to report
368
- logger .severe ( "Send this to support at https://discordsrvutils.xyz/support" );
376
+ logger .severe ("Send this to support at https://discordsrvutils.xyz/support" );
369
377
ex .printStackTrace ();
370
378
}
371
379
@@ -442,13 +450,13 @@ private void initDefaultMessages() {
442
450
}
443
451
}
444
452
445
-
446
453
public void onDisable () {
447
454
if (dsrvlistener != null ) DiscordSRV .api .unsubscribe (dsrvlistener );
448
455
if (isReady ()) {
449
456
getJDA ().removeEventListener (listeners .toArray (new Object [0 ]));
450
457
}
451
- pool .shutdown ();
458
+ if (pool != null )
459
+ pool .shutdown ();
452
460
if (WaiterManager .get () != null ) WaiterManager .get ().timer .cancel ();
453
461
if (sql != null ) sql .close ();
454
462
}
@@ -474,7 +482,7 @@ private void whenStarted() {
474
482
if (!levelingRoles .exists ()) {
475
483
levelingRoles .createNewFile ();
476
484
FileWriter writer = new FileWriter (levelingRoles );
477
- writer .write ("{}" );
485
+ writer .write ("{\n \n }" );
478
486
writer .close ();
479
487
levelingRolesRaw = new JSONObject ();
480
488
} else {
@@ -486,14 +494,14 @@ private void whenStarted() {
486
494
logger .severe ("Error creating leveling-roles.json" );
487
495
}
488
496
497
+ //Register Expansion
489
498
if (getServer ().getPluginManager ().isPluginEnabled ("PlaceholderAPI" )) {
490
499
new PAPIExpansion ().register ();
491
500
}
492
501
493
502
494
503
}
495
504
496
-
497
505
public void registerListeners () {
498
506
getJDA ().addEventListener (listeners .toArray (new Object [0 ]));
499
507
Bukkit .getServer ().getPluginManager ().registerEvents (new BukkitLevelingListener (), this );
@@ -517,9 +525,7 @@ public void registerCommands() {
517
525
CommandManager .get ().registerCommand (new DenySuggestionCommand ());
518
526
}
519
527
520
-
521
528
/**
522
- *
523
529
* @return `DiscordSRV.isReady`. This may change any time soon
524
530
*/
525
531
public boolean isReady () {
@@ -544,7 +550,7 @@ public void reloadConfigs() throws IOException, InvalidConfigException {
544
550
if (!levelingRoles .exists ()) {
545
551
levelingRoles .createNewFile ();
546
552
FileWriter writer = new FileWriter (levelingRoles );
547
- writer .write ("{/n/ n}" );
553
+ writer .write ("{\n \ n }" );
548
554
writer .close ();
549
555
levelingRolesRaw = new JSONObject ();
550
556
} else {
@@ -591,6 +597,10 @@ public void whenReady() {
591
597
getServer ().getPluginManager ().registerEvents (new EssentialsAFKListener (), this );
592
598
hookedPlugins .add (getServer ().getPluginManager ().getPlugin ("Essentials" ));
593
599
}
600
+ if (getServer ().getPluginManager ().isPluginEnabled ("CMI" )) {
601
+ getServer ().getPluginManager ().registerEvents (new CMIAfkListener (), this );
602
+ hookedPlugins .add (getServer ().getPluginManager ().getPlugin ("CMI" ));
603
+ }
594
604
if (getServer ().getPluginManager ().isPluginEnabled ("AdvancedBan" )) {
595
605
getServer ().getPluginManager ().registerEvents (new AdvancedBanPunishmentListener (), this );
596
606
hookedPlugins .add (getServer ().getPluginManager ().getPlugin ("AdvancedBan" ));
@@ -708,7 +718,6 @@ private void doSuggestions() {
708
718
}
709
719
}
710
720
711
-
712
721
public void setSettings () {
713
722
if (!isReady ()) return ;
714
723
OnlineStatus onlineStatus = getMainConfig ().onlinestatus ().equalsIgnoreCase ("DND" ) ? OnlineStatus .DO_NOT_DISTURB : OnlineStatus .valueOf (getMainConfig ().onlinestatus ().toUpperCase ());
@@ -805,7 +814,6 @@ public <U> void handleCF(CompletableFuture<U> cf, Consumer<U> success, Consumer<
805
814
});
806
815
}
807
816
808
-
809
817
/**
810
818
* For doing a cf inside another one
811
819
*/
@@ -826,7 +834,6 @@ public void defaultHandle(Throwable ex, MessageChannel channel) {
826
834
ex .printStackTrace ();
827
835
}
828
836
829
- private long lastErrorTime = 0 ;
830
837
public void defaultHandle (Throwable ex ) {
831
838
//handle error on thread pool
832
839
if (!config .minimize_errors ()) {
@@ -836,15 +843,15 @@ public void defaultHandle(Throwable ex) {
836
843
logger .warning ("Read the note above the error Please." );
837
844
//don't spam errors
838
845
if ((System .currentTimeMillis () - lastErrorTime ) >= 180000 )
839
- for (Player p : Bukkit .getOnlinePlayers ()) {
840
- if (p .hasPermission ("discordsrvutils.errornotifications" )) {
841
- //tell admins that something was wrong
842
- TextComponent msg = new TextComponent (Utils .colors ("&7[&eDSU&7] Plugin had an error. Check console for details." ));
843
- msg .setClickEvent (new ClickEvent (ClickEvent .Action .OPEN_URL , "https://discordsrvutils.xyz/support" ));
844
- msg .setHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , new ComponentBuilder (net .md_5 .bungee .api .ChatColor .GREEN + "" + net .md_5 .bungee .api .ChatColor .BOLD + "Join Support Discord" ).create ()));
845
- p .spigot ().sendMessage (msg );
846
+ for (Player p : Bukkit .getOnlinePlayers ()) {
847
+ if (p .hasPermission ("discordsrvutils.errornotifications" )) {
848
+ //tell admins that something was wrong
849
+ TextComponent msg = new TextComponent (Utils .colors ("&7[&eDSU&7] Plugin had an error. Check console for details." ));
850
+ msg .setClickEvent (new ClickEvent (ClickEvent .Action .OPEN_URL , "https://discordsrvutils.xyz/support" ));
851
+ msg .setHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , new ComponentBuilder (net .md_5 .bungee .api .ChatColor .GREEN + "" + net .md_5 .bungee .api .ChatColor .BOLD + "Join Support Discord" ).create ()));
852
+ p .spigot ().sendMessage (msg );
853
+ }
846
854
}
847
- }
848
855
lastErrorTime = System .currentTimeMillis ();
849
856
850
857
} else {
0 commit comments