11package me .hsgamer .bettergui ;
22
3- import me .hsgamer .bettergui .api .addon .PostEnable ;
3+ import io .github .projectunified .minelib .plugin .base .BasePlugin ;
4+ import io .github .projectunified .minelib .plugin .command .CommandComponent ;
5+ import io .github .projectunified .minelib .plugin .postenable .PostEnable ;
6+ import io .github .projectunified .minelib .plugin .postenable .PostEnableComponent ;
47import me .hsgamer .bettergui .api .menu .Menu ;
58import me .hsgamer .bettergui .builder .*;
69import me .hsgamer .bettergui .command .*;
1316import me .hsgamer .bettergui .manager .MenuManager ;
1417import me .hsgamer .bettergui .papi .ExtraPlaceholderExpansion ;
1518import me .hsgamer .bettergui .util .StringReplacerApplier ;
16- import me .hsgamer .hscore .bukkit .baseplugin .BasePlugin ;
1719import me .hsgamer .hscore .bukkit .config .BukkitConfig ;
1820import me .hsgamer .hscore .bukkit .gui .BukkitGUIListener ;
1921import me .hsgamer .hscore .bukkit .utils .MessageUtils ;
3032import org .bukkit .Bukkit ;
3133import org .bukkit .plugin .java .JavaPlugin ;
3234
33- import java .util .Collections ;
34- import java .util .HashMap ;
35- import java .util .List ;
36- import java .util .Map ;
35+ import java .util .*;
3736
3837/**
3938 * The main class of the plugin
4039 */
41- public final class BetterGUI extends BasePlugin {
40+ public final class BetterGUI extends BasePlugin implements PostEnable {
4241 private static final CachedValue <BetterGUI > INSTANCE_CACHE = CachedValue .of (() -> JavaPlugin .getPlugin (BetterGUI .class ));
43- private final MainConfig mainConfig = ConfigGenerator .newInstance (MainConfig .class , new BukkitConfig (this , "config.yml" ));
44- private final MessageConfig messageConfig = ConfigGenerator .newInstance (MessageConfig .class , new BukkitConfig (this , "messages.yml" ));
45- private final TemplateConfig templateButtonConfig = new TemplateConfig (this );
46- private final MenuManager menuManager = new MenuManager (this );
47- private final MenuCommandManager menuCommandManager = new MenuCommandManager (this );
48- private final AddonManager addonManager = new AddonManager (this );
49- private final AddonDownloader addonDownloader = new AddonDownloader (this );
50- private final VariableBundle variableBundle = new VariableBundle ();
5142
5243 /**
5344 * Get the instance of the plugin
@@ -59,59 +50,78 @@ public static BetterGUI getInstance() {
5950 }
6051
6152 @ Override
62- public void load () {
63- MessageUtils .setPrefix (messageConfig ::getPrefix );
64-
53+ protected List <Object > getComponents () {
54+ VariableBundle variableBundle = new VariableBundle ();
6555 CommonVariableBundle .registerVariables (variableBundle );
6656 BukkitVariableBundle .registerVariables (variableBundle );
6757 variableBundle .register ("menu_" , StringReplacer .of ((original , uuid ) -> {
6858 String [] split = original .split ("_" , 2 );
6959 String menuName = split [0 ].trim ();
7060 String variable = split .length > 1 ? split [1 ].trim () : "" ;
71- Menu menu = menuManager .getMenu (menuName );
61+ Menu menu = get ( MenuManager . class ) .getMenu (menuName );
7262 if (menu == null ) {
7363 return null ;
7464 }
7565 return menu .getVariableManager ().setVariables (StringReplacerApplier .normalizeQuery (variable ), uuid );
7666 }));
77- }
7867
79- @ Override
80- public void enable () {
81- BukkitGUIListener .init (this );
68+ AddonManager addonManager = new AddonManager (this );
69+ AddonDownloader addonDownloader = new AddonDownloader (this , addonManager );
70+
71+ List <Object > components = new ArrayList <>(Arrays .asList (
72+ variableBundle ,
73+
74+ new PostEnableComponent (this ),
75+
76+ new Permissions (this ),
77+ new CommandComponent (this ,
78+ new OpenCommand (this ),
79+ new MainCommand (this ),
80+ new GetAddonsCommand (this ),
81+ new ReloadCommand (this ),
82+ new GetVariablesCommand (this ),
83+ new GetTemplateButtonsCommand (this )
84+ ),
8285
83- addonManager .loadExpansions ();
86+ ConfigGenerator .newInstance (MainConfig .class , new BukkitConfig (this , "config.yml" )),
87+ ConfigGenerator .newInstance (MessageConfig .class , new BukkitConfig (this , "messages.yml" )),
88+ new TemplateConfig (this ),
8489
85- registerCommand (new OpenCommand (this ));
86- registerCommand (new MainCommand (this ));
87- registerCommand (new GetAddonsCommand (this ));
88- registerCommand (new ReloadCommand (this ));
89- registerCommand (new GetVariablesCommand (this ));
90- registerCommand (new GetTemplateButtonsCommand (this ));
90+ addonManager ,
91+ new MenuManager (this ),
92+ new MenuCommandManager (this ),
93+ addonDownloader
94+ ));
9195
9296 if (Bukkit .getPluginManager ().getPlugin ("PlaceholderAPI" ) != null ) {
93- ExtraPlaceholderExpansion expansion = new ExtraPlaceholderExpansion (this );
94- expansion .register ();
95- addDisableFunction (expansion ::unregister );
97+ components .add (new ExtraPlaceholderExpansion (this ));
9698 }
99+
100+ return components ;
101+ }
102+
103+ @ Override
104+ public void load () {
105+ MessageUtils .setPrefix (() -> get (MessageConfig .class ).getPrefix ());
106+ }
107+
108+ @ Override
109+ public void enable () {
110+ BukkitGUIListener .init (this );
97111 }
98112
99113 @ Override
100114 public void postEnable () {
101- addonManager .enableExpansions ();
102- addonDownloader .setup ();
103- templateButtonConfig .setup ();
104- menuManager .loadMenuConfig ();
105- addonManager .call (PostEnable .class , PostEnable ::onPostEnable );
115+ get (AddonManager .class ).call (me .hsgamer .bettergui .api .addon .PostEnable .class , me .hsgamer .bettergui .api .addon .PostEnable ::onPostEnable );
106116
107117 Metrics metrics = new Metrics (this , 6609 );
108118 metrics .addCustomChart (new DrilldownPie ("addon" , () -> {
109119 Map <String , Map <String , Integer >> map = new HashMap <>();
110- Map <String , Integer > addons = addonManager .getExpansionCount ();
120+ Map <String , Integer > addons = get ( AddonManager . class ) .getExpansionCount ();
111121 map .put (String .valueOf (addons .size ()), addons );
112122 return map ;
113123 }));
114- metrics .addCustomChart (new AdvancedPie ("addon_count" , addonManager ::getExpansionCount ));
124+ metrics .addCustomChart (new AdvancedPie ("addon_count" , get ( AddonManager . class ) ::getExpansionCount ));
115125
116126 if (getDescription ().getVersion ().contains ("SNAPSHOT" )) {
117127 getLogger ().warning ("You are using the development version" );
@@ -133,98 +143,12 @@ public void postEnable() {
133143
134144 @ Override
135145 public void disable () {
136- menuCommandManager .clearMenuCommand ();
137- menuManager .clear ();
138- templateButtonConfig .clear ();
139- addonManager .disableExpansions ();
140- addonManager .clearExpansions ();
141- }
142-
143- @ Override
144- public void postDisable () {
145146 ActionBuilder .INSTANCE .clear ();
146147 ButtonBuilder .INSTANCE .clear ();
147148 ItemModifierBuilder .INSTANCE .clear ();
148149 MenuBuilder .INSTANCE .clear ();
149150 RequirementBuilder .INSTANCE .clear ();
150- variableBundle .unregisterAll ();
151+ get ( VariableBundle . class ) .unregisterAll ();
151152 INSTANCE_CACHE .clearCache ();
152153 }
153-
154- @ Override
155- protected List <Class <?>> getPermissionClasses () {
156- return Collections .singletonList (Permissions .class );
157- }
158-
159- /**
160- * Get the main config
161- *
162- * @return the main config
163- */
164- public MainConfig getMainConfig () {
165- return mainConfig ;
166- }
167-
168- /**
169- * Get the message config
170- *
171- * @return the message config
172- */
173- public MessageConfig getMessageConfig () {
174- return messageConfig ;
175- }
176-
177- /**
178- * Get the template button config
179- *
180- * @return the template button config
181- */
182- public TemplateConfig getTemplateButtonConfig () {
183- return templateButtonConfig ;
184- }
185-
186- /**
187- * Get the menu manager
188- *
189- * @return the menu manager
190- */
191- public MenuManager getMenuManager () {
192- return menuManager ;
193- }
194-
195- /**
196- * Get the menu command manager
197- *
198- * @return the menu command manager
199- */
200- public MenuCommandManager getMenuCommandManager () {
201- return menuCommandManager ;
202- }
203-
204- /**
205- * Get the addon manager
206- *
207- * @return the addon manager
208- */
209- public AddonManager getAddonManager () {
210- return addonManager ;
211- }
212-
213- /**
214- * Get the addon downloader
215- *
216- * @return the addon downloader
217- */
218- public AddonDownloader getAddonDownloader () {
219- return addonDownloader ;
220- }
221-
222- /**
223- * Get the variable bundle
224- *
225- * @return the variable bundle
226- */
227- public VariableBundle getVariableBundle () {
228- return variableBundle ;
229- }
230154}
0 commit comments