package net.minestom.server.advancements;
import net.minestom.server.utils.validate.Check;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Used to manage all the registered {@link AdvancementTab}.
*
* Use {@link #createTab(String, AdvancementRoot)} to create a tab with the appropriate {@link AdvancementRoot}.
*/
public class AdvancementManager {
private final Map advancementTabMap = new ConcurrentHashMap<>();
/**
* Creates a new {@link AdvancementTab} with a single {@link AdvancementRoot}.
*
* @param rootIdentifier the root identifier
* @param root the root advancement
* @return the newly created {@link AdvancementTab}
* @throws IllegalStateException if a tab with the identifier {@code rootIdentifier} already exists
*/
public AdvancementTab createTab(String rootIdentifier, AdvancementRoot root) {
Check.stateCondition(advancementTabMap.containsKey(rootIdentifier),
"A tab with the identifier '" + rootIdentifier + "' already exists");
final AdvancementTab advancementTab = new AdvancementTab(rootIdentifier, root);
this.advancementTabMap.put(rootIdentifier, advancementTab);
return advancementTab;
}
/**
* Gets an advancement tab by its root identifier.
*
* @param rootIdentifier the root identifier of the tab
* @return the {@link AdvancementTab} associated with the identifier, null if not any
*/
public AdvancementTab getTab(String rootIdentifier) {
return advancementTabMap.get(rootIdentifier);
}
/**
* Gets all the created {@link AdvancementTab}.
*
* @return the collection containing all created {@link AdvancementTab}
*/
public Collection getTabs() {
return advancementTabMap.values();
}
}