Minestom/src/main/java/net/minestom/server/advancements/AdvancementManager.java

52 lines
1.6 KiB
Java
Raw Normal View History

2020-08-05 10:56:16 +02:00
package net.minestom.server.advancements;
import net.minestom.server.utils.validate.Check;
2020-08-06 07:42:00 +02:00
import java.util.Collection;
2020-08-05 10:56:16 +02:00
import java.util.HashMap;
import java.util.Map;
2020-08-06 07:42:00 +02:00
/**
* Used to manages advancement tabs
*/
2020-08-05 10:56:16 +02:00
public class AdvancementManager {
private Map<String, AdvancementTab> advancementTabMap = new HashMap<>();
2020-08-06 07:42:00 +02:00
/**
* Create a new tab with a single advancement
*
* @param rootIdentifier the root identifier
* @param root the root advancement
* @return the {@link AdvancementTab} created
* @throws IllegalStateException if a tab with the identifier {@code rootIdentifier} already exists
*/
2020-08-05 10:56:16 +02:00
public AdvancementTab createTab(String rootIdentifier, AdvancementRoot root) {
Check.stateCondition(advancementTabMap.containsKey(rootIdentifier),
"A tab with the identifier '" + rootIdentifier + "' already exists");
2020-08-05 10:56:16 +02:00
final AdvancementTab advancementTab = new AdvancementTab(rootIdentifier, root);
this.advancementTabMap.put(rootIdentifier, advancementTab);
return advancementTab;
}
2020-08-06 07:42:00 +02:00
/**
* Get an advancement tab by its root identifier
*
* @param rootIdentifier the root identifier of the tab
* @return the {@link AdvancementTab} associated with the identifer, null if not any
*/
2020-08-05 10:56:16 +02:00
public AdvancementTab getTab(String rootIdentifier) {
return advancementTabMap.get(rootIdentifier);
}
2020-08-06 07:42:00 +02:00
/**
* Get all the created tab
*
* @return the collection containing all created {@link AdvancementTab}
*/
public Collection<AdvancementTab> getTabs() {
return advancementTabMap.values();
}
2020-08-05 10:56:16 +02:00
}