Search in sources :

Example 31 with AdvancementCriterion

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

the class LanternPlayerAdvancements method createCriteria.

static Tuple<List<AdvancementCriterion>, String[][]> createCriteria(AdvancementCriterion criterion) {
    final List<AdvancementCriterion> criteria = new ArrayList<>();
    final List<String[]> names = new ArrayList<>();
    if (criterion instanceof AndCriterion) {
        for (AdvancementCriterion child : ((AndCriterion) criterion).getCriteria()) {
            if (child instanceof LanternScoreCriterion) {
                for (String id : ((LanternScoreCriterion) child).getIds()) {
                    names.add(new String[] { id });
                }
            } else {
                names.add(new String[] { child.getName() });
            }
            criteria.add(child);
        }
    } else {
        if (criterion instanceof LanternScoreCriterion) {
            for (String id : ((LanternScoreCriterion) criterion).getIds()) {
                names.add(new String[] { id });
            }
        } else {
            names.add(new String[] { criterion.getName() });
        }
        criteria.add(criterion);
    }
    return new Tuple<>(criteria, names.toArray(new String[names.size()][]));
}
Also used : AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) ArrayList(java.util.ArrayList) LanternScoreCriterion(org.lanternpowered.server.advancement.criteria.LanternScoreCriterion) AndCriterion(org.spongepowered.api.advancement.criteria.AndCriterion) Tuple(org.spongepowered.api.util.Tuple)

Aggregations

AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)31 ArrayList (java.util.ArrayList)10 CriterionEvent (org.spongepowered.api.event.advancement.CriterionEvent)9 ScoreAdvancementCriterion (org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion)8 Advancement (org.spongepowered.api.advancement.Advancement)7 CriterionBridge (org.spongepowered.common.bridge.advancements.CriterionBridge)7 IMixinCriterion (org.spongepowered.common.interfaces.advancement.IMixinCriterion)7 Instant (java.time.Instant)6 Advancement (net.minecraft.advancements.Advancement)6 Criterion (net.minecraft.advancements.Criterion)5 AndCriterion (org.spongepowered.api.advancement.criteria.AndCriterion)5 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)5 Cause (org.spongepowered.api.event.Cause)5 Cause (org.spongepowered.api.event.cause.Cause)5 SpongeScoreCriterion (org.spongepowered.common.advancement.criterion.SpongeScoreCriterion)5 AdvancementProgress (net.minecraft.advancements.AdvancementProgress)4 OrCriterion (org.spongepowered.api.advancement.criteria.OrCriterion)4 Player (org.spongepowered.api.entity.living.player.Player)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 PlayerAdvancementsBridge (org.spongepowered.common.bridge.server.PlayerAdvancementsBridge)4