Commit 303ac2af790baa4f0da6882716017b569ac34193

Authored by Mumfrey
1 parent d19241ae

convert observer list in LiteLoaderMods to HandlerList

java/common/com/mumfrey/liteloader/core/LiteLoaderMods.java
@@ -15,6 +15,8 @@ import net.minecraft.client.resources.IResourcePack; @@ -15,6 +15,8 @@ import net.minecraft.client.resources.IResourcePack;
15 import com.mumfrey.liteloader.LiteMod; 15 import com.mumfrey.liteloader.LiteMod;
16 import com.mumfrey.liteloader.api.ModLoadObserver; 16 import com.mumfrey.liteloader.api.ModLoadObserver;
17 import com.mumfrey.liteloader.common.LoadingProgress; 17 import com.mumfrey.liteloader.common.LoadingProgress;
  18 +import com.mumfrey.liteloader.core.event.HandlerList;
  19 +import com.mumfrey.liteloader.interfaces.FastIterableDeque;
18 import com.mumfrey.liteloader.interfaces.Loadable; 20 import com.mumfrey.liteloader.interfaces.Loadable;
19 import com.mumfrey.liteloader.interfaces.LoadableMod; 21 import com.mumfrey.liteloader.interfaces.LoadableMod;
20 import com.mumfrey.liteloader.interfaces.LoaderEnumerator; 22 import com.mumfrey.liteloader.interfaces.LoaderEnumerator;
@@ -64,7 +66,7 @@ public class LiteLoaderMods @@ -64,7 +66,7 @@ public class LiteLoaderMods
64 /** 66 /**
65 * Mod load observers 67 * Mod load observers
66 */ 68 */
67 - private List<ModLoadObserver> observers; 69 + private FastIterableDeque<ModLoadObserver> observers = new HandlerList<ModLoadObserver>(ModLoadObserver.class);
68 70
69 /** 71 /**
70 * List of loaded mods, for crash reporting 72 * List of loaded mods, for crash reporting
@@ -104,7 +106,7 @@ public class LiteLoaderMods @@ -104,7 +106,7 @@ public class LiteLoaderMods
104 106
105 void init(List<ModLoadObserver> observers) 107 void init(List<ModLoadObserver> observers)
106 { 108 {
107 - this.observers = observers; 109 + this.observers.addAll(observers);
108 this.disabledMods.addAll(this.enumerator.getDisabledContainers()); 110 this.disabledMods.addAll(this.enumerator.getDisabledContainers());
109 } 111 }
110 112
@@ -500,10 +502,7 @@ public class LiteLoaderMods @@ -500,10 +502,7 @@ public class LiteLoaderMods
500 */ 502 */
501 void onModLoaded(Mod mod) 503 void onModLoaded(Mod mod)
502 { 504 {
503 - for (ModLoadObserver observer : this.observers)  
504 - {  
505 - observer.onModLoaded(mod.getMod());  
506 - } 505 + this.observers.all().onModLoaded(mod.getMod());
507 506
508 this.allMods.add(mod); 507 this.allMods.add(mod);
509 this.initMods.add(mod); 508 this.initMods.add(mod);
@@ -532,10 +531,7 @@ public class LiteLoaderMods @@ -532,10 +531,7 @@ public class LiteLoaderMods
532 this.disabledMods.add(new NonMod(container, false)); 531 this.disabledMods.add(new NonMod(container, false));
533 } 532 }
534 533
535 - for (ModLoadObserver observer : this.observers)  
536 - {  
537 - observer.onModLoadFailed(container, identifier, reason, th);  
538 - } 534 + this.observers.all().onModLoadFailed(container, identifier, reason, th);
539 } 535 }
540 536
541 /** 537 /**
@@ -591,10 +587,7 @@ public class LiteLoaderMods @@ -591,10 +587,7 @@ public class LiteLoaderMods
591 */ 587 */
592 private void onPreInitMod(LiteMod instance) 588 private void onPreInitMod(LiteMod instance)
593 { 589 {
594 - for (ModLoadObserver observer : this.observers)  
595 - {  
596 - observer.onPreInitMod(instance);  
597 - } 590 + this.observers.all().onPreInitMod(instance);
598 591
599 // register mod config panel if configurable 592 // register mod config panel if configurable
600 this.configManager.registerMod(instance); 593 this.configManager.registerMod(instance);
@@ -617,10 +610,7 @@ public class LiteLoaderMods @@ -617,10 +610,7 @@ public class LiteLoaderMods
617 */ 610 */
618 private void onPostInitMod(LiteMod instance) 611 private void onPostInitMod(LiteMod instance)
619 { 612 {
620 - for (ModLoadObserver observer : this.observers)  
621 - {  
622 - observer.onPostInitMod(instance);  
623 - } 613 + this.observers.all().onPostInitMod(instance);
624 614
625 // add the mod to all relevant listener queues 615 // add the mod to all relevant listener queues
626 LiteLoader.getInterfaceManager().offer(instance); 616 LiteLoader.getInterfaceManager().offer(instance);
@@ -646,10 +636,7 @@ public class LiteLoaderMods @@ -646,10 +636,7 @@ public class LiteLoaderMods
646 636
647 LiteLoaderLogger.info("Performing config upgrade for mod %s. Upgrading %s to %s...", instance.getName(), lastModVersion, LiteLoaderVersion.CURRENT); 637 LiteLoaderLogger.info("Performing config upgrade for mod %s. Upgrading %s to %s...", instance.getName(), lastModVersion, LiteLoaderVersion.CURRENT);
648 638
649 - for (ModLoadObserver observer : this.observers)  
650 - {  
651 - observer.onMigrateModConfig(instance, newConfigPath, oldConfigPath);  
652 - } 639 + this.observers.all().onMigrateModConfig(instance, newConfigPath, oldConfigPath);
653 640
654 // Migrate versioned config if any is present 641 // Migrate versioned config if any is present
655 this.configManager.migrateModConfig(instance, newConfigPath, oldConfigPath); 642 this.configManager.migrateModConfig(instance, newConfigPath, oldConfigPath);