use of org.lanternpowered.server.advancement.LanternPlayerAdvancements 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();
}
}
}
}
}
Aggregations