2020-08-05 10:56:16 +02:00
|
|
|
package net.minestom.server.advancements;
|
|
|
|
|
2020-08-05 11:13:57 +02:00
|
|
|
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
|
|
|
/**
|
2020-10-11 14:58:19 +02:00
|
|
|
* Used to manage advancement tabs
|
|
|
|
* <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 {
|
|
|
|
|
2020-08-19 01:24:51 +02:00
|
|
|
private final Map<String, AdvancementTab> advancementTabMap = new HashMap<>();
|
2020-08-05 10:56:16 +02:00
|
|
|
|
2020-08-06 07:42:00 +02:00
|
|
|
/**
|
2020-10-11 14:58:19 +02:00
|
|
|
* Create a new tab with a single {@link Advancement}
|
2020-08-06 07:42:00 +02:00
|
|
|
*
|
|
|
|
* @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) {
|
2020-08-05 11:13:57 +02:00
|
|
|
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
|
|
|
}
|