Created
November 1, 2017 19:09
-
-
Save TheMasteredPanda/e0e888746602b3b78164609e1dea427a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.zoramagic.bungee.core.api.module; | |
import com.google.common.collect.Maps; | |
import io.pucman.bungee.manager.Manager; | |
import net.zoramagic.bungee.core.ZCore; | |
import java.util.Arrays; | |
import java.util.LinkedHashMap; | |
public class ModuleManager extends Manager<ZCore> | |
{ | |
private LinkedHashMap<String, Module> modules; | |
public ModuleManager(ZCore instance) | |
{ | |
super(instance, Priority.HIGH); | |
this.modules = Maps.newLinkedHashMap(); | |
} | |
public void load(Module... modules) | |
{ | |
Arrays.stream(modules).forEachOrdered(module -> { | |
if (!this.modules.containsKey(module.getName())) { | |
if (module instanceof CommandModule) { | |
this.instance.getCommandManager().register(instance, (CommandModule) module); | |
} | |
this.modules.put(module.getName(), module); | |
} else { | |
this.instance.getLogger().warning("A module named " + module.getName() + " is already loaded."); | |
} | |
}); | |
} | |
@Override | |
public void onEnable() | |
{ | |
this.modules.values().forEach(Module::init); | |
} | |
@Override | |
public void onDisable() | |
{ | |
this.modules.values().forEach(Module::shutdown); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment