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);
}
}
}
Aggregations