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

54 lines
1.9 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.Map;
import java.util.concurrent.ConcurrentHashMap;
2020-08-05 10:56:16 +02:00
2020-08-06 07:42:00 +02:00
/**
* Used to manage all the registered {@link AdvancementTab}
2020-10-11 14:58:19 +02:00
* <p>
* Use {@link #createTab(String, AdvancementRoot)} to create a tab with the appropriate {@link AdvancementRoot}
2020-08-06 07:42:00 +02:00
*/
2020-08-05 10:56:16 +02:00
public class AdvancementManager {
private final Map<String, AdvancementTab> advancementTabMap = new ConcurrentHashMap<>();
2020-08-05 10:56:16 +02:00
2020-08-06 07:42:00 +02:00
/**
* Create a new {@link AdvancementTab} with a single {@link AdvancementRoot}
2020-08-06 07:42:00 +02:00
*
* @param rootIdentifier the root identifier
* @param root the root advancement
* @return the newly created {@link AdvancementTab}
2020-08-06 07:42:00 +02:00
* @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
/**
2020-10-11 14:58:19 +02:00
* Get all the created {@link AdvancementTab}
2020-08-06 07:42:00 +02:00
*
* @return the collection containing all created {@link AdvancementTab}
*/
public Collection<AdvancementTab> getTabs() {
return advancementTabMap.values();
}
2020-08-05 10:56:16 +02:00
}