Search in sources :

Example 1 with IMixinICriterionTriggerListener

use of org.spongepowered.common.interfaces.advancement.IMixinICriterionTriggerListener in project SpongeCommon by SpongePowered.

the class SpongeTrigger method trigger.

@Override
public void trigger(Player player) {
    final PlayerAdvancements playerAdvancements = ((EntityPlayerMP) player).getAdvancements();
    final Cause cause = Sponge.getCauseStackManager().getCurrentCause();
    final TypeToken typeToken = TypeToken.of(this.triggerConfigurationClass);
    for (Listener listener : new ArrayList<>(this.listeners.get(playerAdvancements))) {
        final IMixinICriterionTriggerListener mixinListener = (IMixinICriterionTriggerListener) listener;
        final Advancement advancement = (Advancement) mixinListener.getAdvancement();
        final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((net.minecraft.advancements.Advancement) advancement).getCriteria().get(mixinListener.getCriterionName());
        final CriterionEvent.Trigger event = SpongeEventFactory.createCriterionEventTrigger(cause, advancement, advancementCriterion, typeToken, player, (FilteredTrigger) listener.getCriterionInstance(), this.eventHandler == null);
        if (this.eventHandler != null) {
            this.eventHandler.accept(event);
            if (!event.getResult()) {
                continue;
            }
        }
        SpongeImpl.postEvent(event);
        if (event.getResult()) {
            listener.grantCriterion(playerAdvancements);
        }
    }
}
Also used : IMixinICriterionTriggerListener(org.spongepowered.common.interfaces.advancement.IMixinICriterionTriggerListener) PlayerAdvancements(net.minecraft.advancements.PlayerAdvancements) CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) TypeToken(com.google.common.reflect.TypeToken) Cause(org.spongepowered.api.event.cause.Cause) IMixinICriterionTriggerListener(org.spongepowered.common.interfaces.advancement.IMixinICriterionTriggerListener) ArrayList(java.util.ArrayList) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Advancement(org.spongepowered.api.advancement.Advancement)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)1 ArrayList (java.util.ArrayList)1 PlayerAdvancements (net.minecraft.advancements.PlayerAdvancements)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Advancement (org.spongepowered.api.advancement.Advancement)1 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)1 CriterionEvent (org.spongepowered.api.event.advancement.CriterionEvent)1 Cause (org.spongepowered.api.event.cause.Cause)1 IMixinICriterionTriggerListener (org.spongepowered.common.interfaces.advancement.IMixinICriterionTriggerListener)1