use of org.spongepowered.common.advancement.SpongeTrigger 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();
}
}
Aggregations