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
/**
2020-10-15 21:16:31 +02:00
* Used to manage all the registered {@link AdvancementTab}.
2020-10-11 14:58:19 +02:00
* <p>
2020-10-15 21:16:31 +02:00
* 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
/**
2020-10-15 21:16:31 +02:00
* Creates 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
/**
2020-10-15 21:16:31 +02:00
* Gets an advancement tab by its root identifier.
2020-08-06 07:42:00 +02:00
*
* @param rootIdentifier the root identifier of the tab
2020-10-15 21:16:31 +02:00
* @return the {@link AdvancementTab} associated with the identifier, null if not any
2020-08-06 07:42:00 +02:00
*/
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-15 21:16:31 +02:00
* Gets 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
}