Search in sources :

Example 1 with CriterionTrigger_ListenerAccessor

use of org.spongepowered.common.accessor.advancements.CriterionTrigger_ListenerAccessor in project SpongeCommon by SpongePowered.

the class SpongeCriterionTrigger method bridge$trigger.

@Override
public void bridge$trigger(final ServerPlayer player) {
    final PlayerAdvancements playerAdvancements = ((net.minecraft.server.level.ServerPlayer) player).getAdvancements();
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    // correct type verified in builder
    @SuppressWarnings("unchecked") final TypeToken<FilteredTriggerConfiguration> typeToken = (TypeToken<FilteredTriggerConfiguration>) TypeToken.get(this.triggerConfigurationType);
    for (final Listener listener : new ArrayList<>(this.listeners.get(playerAdvancements))) {
        final CriterionTrigger_ListenerAccessor mixinListener = (CriterionTrigger_ListenerAccessor) listener;
        final Advancement advancement = (Advancement) mixinListener.accessor$advancement();
        final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((net.minecraft.advancements.Advancement) advancement).getCriteria().get(mixinListener.accessor$criterion());
        final CriterionEvent.Trigger event = SpongeEventFactory.createCriterionEventTrigger(cause, advancement, advancementCriterion, typeToken, player, (FilteredTrigger) listener.getTriggerInstance(), this.eventHandler == null);
        if (this.eventHandler != null) {
            this.eventHandler.accept(event);
            if (!event.result()) {
                continue;
            }
        }
        SpongeCommon.post(event);
        if (event.result()) {
            listener.run(playerAdvancements);
        }
    }
}
Also used : CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) ArrayList(java.util.ArrayList) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) PlayerAdvancements(net.minecraft.server.PlayerAdvancements) TypeToken(io.leangen.geantyref.TypeToken) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Cause(org.spongepowered.api.event.Cause) FilteredTriggerConfiguration(org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration) CriterionTrigger_ListenerAccessor(org.spongepowered.common.accessor.advancements.CriterionTrigger_ListenerAccessor) Advancement(org.spongepowered.api.advancement.Advancement)

Aggregations

TypeToken (io.leangen.geantyref.TypeToken)1 ArrayList (java.util.ArrayList)1 PlayerAdvancements (net.minecraft.server.PlayerAdvancements)1 Advancement (org.spongepowered.api.advancement.Advancement)1 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)1 FilteredTriggerConfiguration (org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration)1 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)1 Cause (org.spongepowered.api.event.Cause)1 CriterionEvent (org.spongepowered.api.event.advancement.CriterionEvent)1 CriterionTrigger_ListenerAccessor (org.spongepowered.common.accessor.advancements.CriterionTrigger_ListenerAccessor)1