44import id .luckynetwork .dev .lyrams .lej .LuckyEssentials ;
55import id .luckynetwork .dev .lyrams .lej .enums .TrueFalseType ;
66import id .luckynetwork .dev .lyrams .lej .utils .Utils ;
7+ import lombok .Data ;
78import lombok .experimental .UtilityClass ;
89import org .bukkit .Bukkit ;
910import org .bukkit .command .Command ;
@@ -106,17 +107,14 @@ public Plugin getPluginByName(String name) {
106107 * @param plugin the plugin to format
107108 * @return the formatted name
108109 */
109- public String getFormattedName (@ NotNull Plugin plugin , boolean includeVersion ) {
110+ public PluginInfo getPluginInfo (@ NotNull Plugin plugin ) {
110111 TrueFalseType trueFalseType = TrueFalseType .DEFAULT ;
111112 trueFalseType .setIfTrue (plugin .getName ());
112113 trueFalseType .setIfFalse (plugin .getName ());
113114
114115 String pluginName = Utils .colorizeTrueFalse (plugin .isEnabled (), trueFalseType );
115- if (includeVersion ) {
116- pluginName += " (" + plugin .getDescription ().getVersion () + ")" ;
117- }
118116
119- return pluginName ;
117+ return new PluginInfo ( plugin . getName (), pluginName , plugin . getDescription (). getVersion ()) ;
120118 }
121119
122120 /**
@@ -182,6 +180,7 @@ public Map<String, Command> getKnownCommands() {
182180 e .printStackTrace ();
183181 return null ;
184182 }
183+
185184 SimpleCommandMap commandMap ;
186185 try {
187186 commandMap = (SimpleCommandMap ) commandMapField .get (Bukkit .getServer ());
@@ -199,7 +198,6 @@ public Map<String, Command> getKnownCommands() {
199198 }
200199
201200 Map <String , Command > knownCommands ;
202-
203201 try {
204202 knownCommands = (Map <String , Command >) knownCommandsField .get (commandMap );
205203 } catch (IllegalAccessException e ) {
@@ -245,7 +243,6 @@ public boolean load(String pluginName) {
245243 }
246244 } catch (InvalidDescriptionException e ) {
247245 e .printStackTrace ();
248- return false ;
249246 }
250247 }
251248 }
@@ -271,10 +268,9 @@ public boolean load(String pluginName) {
271268 luckyEssentials .getVersionSupport ().getCommandWrap ().wrap (command , alias );
272269 }
273270
274- if (Bukkit .getOnlinePlayers ().size () >= 1 )
275- for (Player player : Bukkit .getOnlinePlayers ()) {
276- luckyEssentials .getVersionSupport ().reloadCommands (player );
277- }
271+ if (Bukkit .getOnlinePlayers ().size () >= 1 ) {
272+ Bukkit .getOnlinePlayers ().forEach (player -> luckyEssentials .getVersionSupport ().reloadCommands (player ));
273+ }
278274 }, 10L );
279275 }
280276
@@ -308,10 +304,8 @@ public boolean unload(Plugin plugin) {
308304 }
309305 }
310306
311- String name = plugin .getName ();
312307
313308 PluginManager pluginManager = Bukkit .getPluginManager ();
314-
315309 SimpleCommandMap commandMap = null ;
316310
317311 List <Plugin > plugins = null ;
@@ -351,33 +345,36 @@ public boolean unload(Plugin plugin) {
351345 e .printStackTrace ();
352346 return false ;
353347 }
354-
355348 }
356349
350+ assert pluginManager != null ;
357351 pluginManager .disablePlugin (plugin );
358352
359353 if (plugins != null ) {
360354 plugins .remove (plugin );
361355 }
362356
357+ String name = plugin .getName ();
363358 if (names != null ) {
364359 names .remove (name );
365360 }
366361
367- if (listeners != null && reloadlisteners ) for (SortedSet <RegisteredListener > set : listeners .values ())
368- set .removeIf (value -> value .getPlugin () == plugin );
362+ if (listeners != null ) {
363+ listeners .values ().forEach (set -> set .removeIf (value -> value .getPlugin () == plugin ));
364+ }
369365
370- if (commandMap != null )
366+ if (commandMap != null ) {
371367 for (Iterator <Map .Entry <String , Command >> it = commands .entrySet ().iterator (); it .hasNext (); ) {
372368 Map .Entry <String , Command > entry = it .next ();
373369 if (entry .getValue () instanceof PluginCommand ) {
374- PluginCommand c = (PluginCommand ) entry .getValue ();
375- if (c .getPlugin () == plugin ) {
376- c .unregister (commandMap );
370+ PluginCommand command = (PluginCommand ) entry .getValue ();
371+ if (command .getPlugin () == plugin ) {
372+ command .unregister (commandMap );
377373 it .remove ();
378374 }
379375 }
380376 }
377+ }
381378
382379 // Attempt to close the classloader to unlock any handles on the plugin's jar file.
383380 ClassLoader classLoader = plugin .getClass ().getClassLoader ();
@@ -390,18 +387,15 @@ public boolean unload(Plugin plugin) {
390387 Field pluginInitField = classLoader .getClass ().getDeclaredField ("pluginInit" );
391388 pluginInitField .setAccessible (true );
392389 pluginInitField .set (classLoader , null );
393-
394390 } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex ) {
395391 Logger .getLogger (PluginManagerUtils .class .getName ()).log (Level .SEVERE , null , ex );
396392 }
397393
398394 try {
399-
400395 ((URLClassLoader ) classLoader ).close ();
401396 } catch (IOException ex ) {
402397 Logger .getLogger (PluginManagerUtils .class .getName ()).log (Level .SEVERE , null , ex );
403398 }
404-
405399 }
406400
407401 // Will not work on processes started with the -XX:+DisableExplicitGC flag, but let's try it anyway.
@@ -426,4 +420,9 @@ public boolean reload(Plugin plugin) {
426420
427421 return false ;
428422 }
423+
424+ @ Data
425+ public static class PluginInfo {
426+ private final String rawName , name , version ;
427+ }
429428}
0 commit comments