Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

ModuleManager lookup by class, not name #295

Closed
EmotionalLove opened this issue Dec 17, 2019 · 1 comment · Fixed by #317
Closed

ModuleManager lookup by class, not name #295

EmotionalLove opened this issue Dec 17, 2019 · 1 comment · Fixed by #317
Assignees
Labels
-other bug enhancement good-first-issue This is a good suggestion / bug report
Milestone

Comments

@EmotionalLove
Copy link
Contributor

No description provided.

@EmotionalLove EmotionalLove added this to the v1.1.2 milestone Dec 17, 2019
@EmotionalLove EmotionalLove self-assigned this Dec 17, 2019
@5HT2 5HT2 added the good-first-issue This is a good suggestion / bug report label Dec 17, 2019
@5HT2 5HT2 mentioned this issue Dec 18, 2019
@x4e
Copy link
Contributor

x4e commented Dec 18, 2019

/**
 * @author cookiedragon234 15/Dec/2019
 */
public class ModuleManager
{
	private static final Map<Module, Set<Value>> modules = new HashMap<>();

	public static Module getModule(Class<? extends Module> moduleClazz)
	{
		for (Module module : modules.keySet())
		{
			if(moduleClazz.isAssignableFrom(module.getClass()))
				return module;
		}
		throw new RuntimeException("Module " + moduleClazz + " was not initialised!");
	}
}

This a snippet of my module manager to show you how it is possible

Usage:

getModule(CrystalAuraModule.class).toggle();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
-other bug enhancement good-first-issue This is a good suggestion / bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants