Search in sources :

Example 1 with SpongeFilteredTrigger

use of org.spongepowered.common.advancement.SpongeFilteredTrigger 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();
    }
}
Also used : ScoreAdvancementCriterion(org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion) SpongeFilteredTrigger(org.spongepowered.common.advancement.SpongeFilteredTrigger) Player(org.spongepowered.api.entity.living.player.Player) CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) ScoreAdvancementCriterion(org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeTrigger(org.spongepowered.common.advancement.SpongeTrigger) IMixinPlayerAdvancements(org.spongepowered.common.interfaces.advancement.IMixinPlayerAdvancements) SpongeFilteredTrigger(org.spongepowered.common.advancement.SpongeFilteredTrigger) FilteredTrigger(org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger) IMixinCriterion(org.spongepowered.common.interfaces.advancement.IMixinCriterion) TypeToken(com.google.common.reflect.TypeToken) Cause(org.spongepowered.api.event.cause.Cause) Advancement(net.minecraft.advancements.Advancement) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)1 Advancement (net.minecraft.advancements.Advancement)1 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)1 ScoreAdvancementCriterion (org.spongepowered.api.advancement.criteria.ScoreAdvancementCriterion)1 FilteredTrigger (org.spongepowered.api.advancement.criteria.trigger.FilteredTrigger)1 Player (org.spongepowered.api.entity.living.player.Player)1 CriterionEvent (org.spongepowered.api.event.advancement.CriterionEvent)1 Cause (org.spongepowered.api.event.cause.Cause)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 SpongeFilteredTrigger (org.spongepowered.common.advancement.SpongeFilteredTrigger)1 SpongeTrigger (org.spongepowered.common.advancement.SpongeTrigger)1 IMixinCriterion (org.spongepowered.common.interfaces.advancement.IMixinCriterion)1 IMixinPlayerAdvancements (org.spongepowered.common.interfaces.advancement.IMixinPlayerAdvancements)1