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));
}
}
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);
}
}
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;
}
Aggregations