2020public abstract class HierarchicalAddonModule implements AddonModule {
2121
2222 private final @ Nullable AddonModule parentModule ;
23- private List <AddonModule > loadableChildren ;
23+ private final List <AddonModule > loadableChildren = new ArrayList <>() ;
2424
2525 /**
2626 * Constructs a module with no parent.
@@ -59,8 +59,7 @@ public Iterable<AddonModule> children() {
5959 */
6060 public List <AddonModule > moduleChain () {
6161 List <AddonModule > chain = new ArrayList <>();
62- chain .add (this );
63- AddonModule current = parentModule ;
62+ AddonModule current = this ;
6463 while (current != null ) {
6564 chain .add (current );
6665 if (current instanceof HierarchicalAddonModule hierarchical ) {
@@ -88,7 +87,7 @@ public final boolean canLoad(SkriptAddon addon) {
8887 }
8988
9089 // Filter children that can load
91- loadableChildren = new ArrayList <> ();
90+ loadableChildren . clear ();
9291 for (AddonModule child : children ()) {
9392 if (child .canLoad (addon )) {
9493 loadableChildren .add (child );
@@ -107,27 +106,22 @@ protected void initSelf(SkriptAddon addon) {
107106 @ Override
108107 public final void init (SkriptAddon addon ) {
109108 initSelf (addon );
110- if (loadableChildren != null ) {
111- for (AddonModule child : loadableChildren ) {
112- child .init (addon );
113- }
109+ for (AddonModule child : loadableChildren ) {
110+ child .init (addon );
114111 }
115112 }
116113
117114 /**
118115 * Override for module-specific loading.
119116 * @param addon The addon this module belongs to.
120117 */
121- protected void loadSelf (SkriptAddon addon ) {
122- }
118+ protected abstract void loadSelf (SkriptAddon addon );
123119
124120 @ Override
125121 public final void load (SkriptAddon addon ) {
126122 loadSelf (addon );
127- if (loadableChildren != null ) {
128- for (AddonModule child : loadableChildren ) {
129- child .load (addon );
130- }
123+ for (AddonModule child : loadableChildren ) {
124+ child .load (addon );
131125 }
132126 }
133127
0 commit comments