Search in sources :

Example 1 with ScoreCriterionProgress

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

the class LanternTrigger method trigger.

@SuppressWarnings("unchecked")
@Override
public void trigger(Player player) {
    final LanternPlayerAdvancements playerAdvancements = ((LanternPlayer) player).getAdvancementsProgress();
    final Collection<AbstractCriterionProgress> collection = this.progress.get(playerAdvancements);
    if (!collection.isEmpty()) {
        final Cause cause = CauseStack.current().getCurrentCause();
        for (AbstractCriterionProgress progress : new ArrayList<>(this.progress.get(playerAdvancements))) {
            final Advancement advancement = progress.getAdvancementProgress().getAdvancement();
            final AdvancementCriterion criterion = progress.getCriterion();
            final FilteredTrigger filteredTrigger = criterion.getTrigger().get();
            final CriterionEvent.Trigger event = SpongeEventFactory.createCriterionEventTrigger(cause, advancement, criterion, this.configTypeToken, player, filteredTrigger, this.eventHandler != null);
            if (this.eventHandler != null) {
                this.eventHandler.accept(event);
            }
            Sponge.getEventManager().post(event);
            if (event.getResult()) {
                if (progress instanceof ScoreCriterionProgress) {
                    ((ScoreCriterionProgress) progress).add(1);
                } else {
                    progress.grant();
                }
            }
        }
    }
}
Also used : ScoreCriterionProgress(org.spongepowered.api.advancement.criteria.ScoreCriterionProgress) CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) AbstractCriterionProgress(org.lanternpowered.server.advancement.criteria.progress.AbstractCriterionProgress) Cause(org.spongepowered.api.event.cause.Cause) ArrayList(java.util.ArrayList) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) LanternPlayerAdvancements(org.lanternpowered.server.advancement.LanternPlayerAdvancements) FilteredTrigger(org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger) Advancement(org.spongepowered.api.advancement.Advancement) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Aggregations

ArrayList (java.util.ArrayList)1 LanternPlayerAdvancements (org.lanternpowered.server.advancement.LanternPlayerAdvancements)1 AbstractCriterionProgress (org.lanternpowered.server.advancement.criteria.progress.AbstractCriterionProgress)1 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)1 Advancement (org.spongepowered.api.advancement.Advancement)1 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)1 ScoreCriterionProgress (org.spongepowered.api.advancement.criteria.ScoreCriterionProgress)1 FilteredTrigger (org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger)1 CriterionEvent (org.spongepowered.api.event.advancement.CriterionEvent)1 Cause (org.spongepowered.api.event.cause.Cause)1