top.hendrixshen.magiclib.impl.malilib.config.GlobalConfigManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magiclib-malilib-extra-1.18.2-fabric Show documentation
Show all versions of magiclib-malilib-extra-1.18.2-fabric Show documentation
Unleash Magic Enhancement Malilib.
The newest version!
package top.hendrixshen.magiclib.impl.malilib.config;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import fi.dy.masa.malilib.event.InputEventHandler;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import top.hendrixshen.magiclib.api.malilib.config.MagicConfigManager;
import top.hendrixshen.magiclib.api.malilib.config.option.MagicIConfigBase;
import top.hendrixshen.magiclib.util.collect.ValueContainer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public final class GlobalConfigManager {
@Getter(lazy = true)
private static final GlobalConfigManager instance = new GlobalConfigManager();
private final Map managers = Maps.newHashMap();
private final List CONTAINERS = Lists.newArrayList();
private final Map CONFIG_TO_CONTAINER = Maps.newLinkedHashMap();
private GlobalConfigManager() {
}
void registerConfigContainer(ConfigContainer configContainer) {
this.CONTAINERS.add(configContainer);
this.CONFIG_TO_CONTAINER.put(configContainer.getConfig(), configContainer);
}
public @NotNull Collection getAllContainers() {
return Lists.newArrayList(this.CONTAINERS);
}
public @NotNull ValueContainer getContainerByConfig(MagicIConfigBase config) {
return ValueContainer.ofNullable(this.CONFIG_TO_CONTAINER.getOrDefault(config, null));
}
public boolean hasConfig(MagicIConfigBase config) {
return this.getContainerByConfig(config).isPresent();
}
public static @NotNull MagicConfigManager getConfigManager(String identifier) {
MagicConfigManager configManager = GlobalConfigManager.getInstance().managers.get(identifier);
if (configManager == null) {
configManager = new MagicConfigManagerImpl(identifier);
GlobalConfigManager.getInstance().managers.put(identifier, configManager);
InputEventHandler.getKeybindManager().registerKeybindProvider((MagicConfigManagerImpl) configManager);
}
return configManager;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy