use of org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger in project SpongeCommon by SpongePowered.
the class MixinICriterionTriggerListener method onGrantCriterion.
@SuppressWarnings("unchecked")
@Inject(method = "grantCriterion", at = @At("HEAD"), cancellable = true)
private void onGrantCriterion(PlayerAdvancements playerAdvancements, CallbackInfo ci) {
final org.spongepowered.api.advancement.Advancement advancement = (org.spongepowered.api.advancement.Advancement) this.advancement;
AdvancementCriterion advancementCriterion = (AdvancementCriterion) this.advancement.getCriteria().get(this.criterionName);
final IMixinCriterion mixinCriterion = (IMixinCriterion) advancementCriterion;
if (mixinCriterion.getScoreCriterion() != null) {
advancementCriterion = mixinCriterion.getScoreCriterion();
}
// Sponge filters are always handled in the trigger method
if (!(this.criterionInstance instanceof SpongeFilteredTrigger)) {
final FilteredTrigger filteredTrigger = (FilteredTrigger) this.criterionInstance;
if (filteredTrigger.getType() instanceof SpongeTrigger) {
final Cause cause = Sponge.getCauseStackManager().getCurrentCause();
final Player player = ((IMixinPlayerAdvancements) playerAdvancements).getPlayer();
final TypeToken typeToken = TypeToken.of(filteredTrigger.getType().getConfigurationType());
final CriterionEvent.Trigger event = SpongeEventFactory.createCriterionEventTrigger(cause, advancement, advancementCriterion, typeToken, player, filteredTrigger, true);
SpongeImpl.postEvent(event);
if (!event.getResult()) {
ci.cancel();
return;
}
}
}
SpongeImpl.getCauseStackManager().pushCause(this.criterionInstance);
// the score be increased by one.
if (advancementCriterion instanceof ScoreAdvancementCriterion) {
((IMixinPlayerAdvancements) playerAdvancements).getPlayer().getProgress(advancement).get((ScoreAdvancementCriterion) advancementCriterion).get().add(1);
ci.cancel();
SpongeImpl.getCauseStackManager().popCause();
}
}
use of org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger 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