2727
2828import ch .andre601 .advancedserverlist .core .commands .CommandHandler ;
2929import ch .andre601 .advancedserverlist .core .file .FileHandler ;
30- import ch .andre601 .advancedserverlist .core .interfaces .PluginCore ;
31- import ch .andre601 .advancedserverlist .core .interfaces .PluginLogger ;
30+ import ch .andre601 .advancedserverlist .core .interfaces .core .PluginCore ;
3231import ch .andre601 .advancedserverlist .core .profiles .players .PlayerHandler ;
3332
3433import java .io .IOException ;
3534import java .io .InputStream ;
36- import java .lang .reflect .Constructor ;
37- import java .lang .reflect .InvocationTargetException ;
3835import java .nio .file .Path ;
3936import java .util .*;
4037
4138public class AdvancedServerList {
4239
43- private final PluginCore plugin ;
40+ private final PluginCore <?> plugin ;
4441 private final FileHandler fileHandler ;
4542 private final CommandHandler commandHandler ;
4643 private final PlayerHandler playerHandler ;
4744
4845 private String version ;
4946
50- public AdvancedServerList (PluginCore plugin ){
47+ public AdvancedServerList (PluginCore <?> plugin ){
5148 this .plugin = plugin ;
5249 this .fileHandler = new FileHandler (this );
5350 this .commandHandler = new CommandHandler (this );
@@ -56,41 +53,8 @@ public AdvancedServerList(PluginCore plugin){
5653 load ();
5754 }
5855
59- public static <T > List <T > getPlayers (Class <T > clazz , String text ){
60- try {
61- String [] lines = text .split ("\n " );
62-
63- final List <T > players = new ArrayList <>(lines .length );
64- final Constructor <T > constructor = clazz .getDeclaredConstructor (String .class , UUID .class );
65-
66- constructor .setAccessible (true );
67-
68- for (String line : lines ){
69- players .add (constructor .newInstance (line , UUID .randomUUID ()));
70- }
71-
72- return players ;
73- }catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex ){
74- return Collections .emptyList ();
75- }
76- }
77-
78- public void disable (){
79- getPluginLogger ().info ("Saving cache.data file..." );
80- getPlayerHandler ().save ();
81- getPluginLogger ().info ("AdvancedServerList disabled!" );
82- }
83-
84- public void clearFaviconCache (){
85- plugin .clearFaviconCache ();
86- }
87-
88- public PluginLogger getPluginLogger (){
89- return plugin .getPluginLogger ();
90- }
91-
92- public Path getPath (){
93- return plugin .getPath ();
56+ public PluginCore <?> getPlugin (){
57+ return plugin ;
9458 }
9559
9660 public FileHandler getFileHandler (){
@@ -109,58 +73,69 @@ public String getVersion(){
10973 return version ;
11074 }
11175
76+ public void disable (){
77+ getPlugin ().getPluginLogger ().info ("Saving cache.data file..." );
78+ getPlayerHandler ().save ();
79+ getPlugin ().getPluginLogger ().info ("AdvancedServerList disabled!" );
80+ }
81+
82+ public void clearFaviconCache (){
83+ plugin .clearFaviconCache ();
84+ }
85+
11286 private void load (){
11387 printBanner ();
11488 resolveVersion ();
115-
116- getPluginLogger ().info ("Starting AdvancedServerList v%s..." , version );
117-
118- getPluginLogger ().info ("Platform: " + plugin .getPlatformName () + " " + plugin .getPlatformVersion ());
89+
90+ getPlugin (). getPluginLogger ().info ("Starting AdvancedServerList v%s..." , version );
91+
92+ getPlugin (). getPluginLogger ().info ("Platform: " + plugin .getPlatformName () + " " + plugin .getPlatformVersion ());
11993
12094 if (getFileHandler ().loadConfig ()){
121- getPluginLogger ().info ("Successfully loaded config.yml!" );
95+ getPlugin (). getPluginLogger ().info ("Successfully loaded config.yml!" );
12296 }else {
123- getPluginLogger ().warn ("Unable to load config.yml! Check previous lines for errors." );
97+ getPlugin (). getPluginLogger ().warn ("Unable to load config.yml! Check previous lines for errors." );
12498 return ;
12599 }
126100
127101 if (getFileHandler ().loadProfiles ()){
128- getPluginLogger ().info ("Successfully loaded " + getFileHandler ().getProfiles ().size () + " profiles!" );
102+ getPlugin (). getPluginLogger ().info ("Successfully loaded " + getFileHandler ().getProfiles ().size () + " profiles!" );
129103 }else {
130- getPluginLogger ().warn ("Unable to load profiles! Check previous lines for errors." );
104+ getPlugin (). getPluginLogger ().warn ("Unable to load profiles! Check previous lines for errors." );
131105 return ;
132106 }
133107
134- if (!getPath ().resolve ("favicons" ).toFile ().exists () && getPath ().resolve ("favicons" ).toFile ().mkdirs ())
135- getPluginLogger ().info ("Successfully created favicons folder." );
136-
137- getPluginLogger ().info ("Loading Commands..." );
108+ Path folder = getPlugin ().getFolderPath ().resolve ("favicons" );
109+ if (!folder .toFile ().exists () && folder .toFile ().mkdirs ())
110+ getPlugin ().getPluginLogger ().info ("Successfully created favicons folder." );
111+
112+ getPlugin ().getPluginLogger ().info ("Loading Commands..." );
138113 plugin .loadCommands ();
139- getPluginLogger ().info ("Commands loaded!" );
140-
141- getPluginLogger ().info ("Loading events..." );
114+ getPlugin (). getPluginLogger ().info ("Commands loaded!" );
115+
116+ getPlugin (). getPluginLogger ().info ("Loading events..." );
142117 plugin .loadEvents ();
143- getPluginLogger ().info ("Events loaded!" );
144-
145- getPluginLogger ().info ("Loading cache.data..." );
118+ getPlugin (). getPluginLogger ().info ("Events loaded!" );
119+
120+ getPlugin (). getPluginLogger ().info ("Loading cache.data..." );
146121 getPlayerHandler ().load ();
147-
148- getPluginLogger ().info ("Loading bStats metrics. Disable it in the global config under /plugins/bstats/" );
122+
123+ getPlugin (). getPluginLogger ().info ("Loading bStats metrics. Disable it in the global config under /plugins/bstats/" );
149124 plugin .loadMetrics ();
150- getPluginLogger ().info ("Metrics loaded!" );
151-
152- getPluginLogger ().info ("AdvancedServerList is ready!" );
125+ getPlugin (). getPluginLogger ().info ("Metrics loaded!" );
126+
127+ getPlugin (). getPluginLogger ().info ("AdvancedServerList is ready!" );
153128 }
154129
155130 private void printBanner (){
156- getPluginLogger ().info ("" );
157- getPluginLogger ().info (" _____ _" );
158- getPluginLogger ().info (" /\\ / ____| |" );
159- getPluginLogger ().info (" / \\ | (___ | |" );
160- getPluginLogger ().info (" / /\\ \\ \\ ___ \\ | |" );
161- getPluginLogger ().info (" / ____ \\ ____) | |____" );
162- getPluginLogger ().info ("/_/ \\ _\\ _____/|______|" );
163- getPluginLogger ().info ("" );
131+ getPlugin (). getPluginLogger ().info ("" );
132+ getPlugin (). getPluginLogger ().info (" _____ _" );
133+ getPlugin (). getPluginLogger ().info (" /\\ / ____| |" );
134+ getPlugin (). getPluginLogger ().info (" / \\ | (___ | |" );
135+ getPlugin (). getPluginLogger ().info (" / /\\ \\ \\ ___ \\ | |" );
136+ getPlugin (). getPluginLogger ().info (" / ____ \\ ____) | |____" );
137+ getPlugin (). getPluginLogger ().info ("/_/ \\ _\\ _____/|______|" );
138+ getPlugin (). getPluginLogger ().info ("" );
164139 }
165140
166141 private void resolveVersion (){
0 commit comments