Search in sources :

Example 11 with Advancement

use of org.spongepowered.api.advancement.Advancement in project LanternServer by LanternPowered.

the class LanternPlayerAdvancements method update.

private void update(LanternAdvancementProgress progress, @Nullable List<MessagePlayOutAdvancements.AdvStruct> added, @Nullable List<String> removed, @Nullable Map<String, Object2LongMap<String>> progressMap, boolean force) {
    final Advancement advancement = progress.getAdvancement();
    boolean updateParentAndChildren = false;
    if (progress.dirtyVisibility || force) {
        final boolean visible = shouldBeVisible(advancement);
        progress.dirtyVisibility = false;
        if (progress.visible != visible) {
            progress.visible = visible;
            if (visible && added != null) {
                added.add(createAdvancement(advancement));
                // The progress is now visible, send the complete data
                if (progressMap != null) {
                    final Object2LongMap<String> progressMap1 = progress.collectProgress();
                    if (!progressMap1.isEmpty()) {
                        progressMap.put(advancement.getId(), progressMap1);
                    }
                    // The progress is already updated, prevent from doing it again
                    progress.dirtyProgress = false;
                }
            } else if (removed != null) {
                removed.add(advancement.getId());
            }
            updateParentAndChildren = true;
        }
    }
    if (progress.visible && progress.dirtyProgress && progressMap != null) {
        progressMap.put(advancement.getId(), progress.collectProgress());
    }
    // Reset dirty state, even if nothing changed
    progress.dirtyProgress = false;
    if (updateParentAndChildren) {
        for (Advancement child : advancement.getChildren()) {
            update(get(child), added, removed, progressMap, true);
        }
        advancement.getParent().ifPresent(parent -> update(get(parent), added, removed, progressMap, true));
    }
}
Also used : Advancement(org.spongepowered.api.advancement.Advancement)

Example 12 with Advancement

use of org.spongepowered.api.advancement.Advancement in project LanternServer by LanternPowered.

the class LanternPlayerAdvancements method init0.

private void init0() {
    cleanup();
    // Load all the advancements into this progress tracker
    final AdvancementRegistryModule registryModule = AdvancementRegistryModule.get();
    for (Advancement advancement : registryModule.getAll()) {
        final LanternAdvancementProgress progress = get(advancement);
        // Update the visibility
        progress.dirtyVisibility = true;
        this.dirtyProgress.add(progress);
    }
}
Also used : Advancement(org.spongepowered.api.advancement.Advancement) AdvancementRegistryModule(org.lanternpowered.server.game.registry.type.advancement.AdvancementRegistryModule)

Example 13 with Advancement

use of org.spongepowered.api.advancement.Advancement in project LanternServer by LanternPowered.

the class LanternTreeLayout method generateNode.

private static TreeNode generateNode(Advancement advancement, TreeLayoutElement element, int column) {
    final TreeNode treeNode = new TreeNode(element, (double) column * HORIZONTAL_OFFSET);
    TreeNode previous = null;
    for (Advancement child : advancement.getChildren()) {
        final TreeLayoutElement childElement = ((LanternAdvancement) child).getLayoutElement();
        if (childElement != null) {
            final TreeNode childNode = generateNode(child, childElement, column + 1);
            childNode.previous = previous;
            childNode.parent = treeNode;
            if (previous != null) {
                previous.next = childNode;
            }
            treeNode.children.add(childNode);
            previous = childNode;
        }
    }
    return treeNode;
}
Also used : TreeLayoutElement(org.spongepowered.api.advancement.TreeLayoutElement) LanternAdvancement(org.lanternpowered.server.advancement.LanternAdvancement) LanternAdvancement(org.lanternpowered.server.advancement.LanternAdvancement) Advancement(org.spongepowered.api.advancement.Advancement)

Aggregations

Advancement (org.spongepowered.api.advancement.Advancement)13 Cause (org.spongepowered.api.event.cause.Cause)7 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)4 CriterionEvent (org.spongepowered.api.event.advancement.CriterionEvent)4 Instant (java.time.Instant)3 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AbstractCriterionProgress (org.lanternpowered.server.advancement.criteria.progress.AbstractCriterionProgress)2 ScoreAdvancementCriterion (org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion)2 ScoreCriterionProgress (org.spongepowered.api.advancement.criteria.ScoreCriterionProgress)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TypeToken (com.google.common.reflect.TypeToken)1 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)1 Object2LongOpenHashMap (it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 AdvancementList (net.minecraft.advancements.AdvancementList)1