use of org.spongepowered.common.advancement.SpongeCriterionTrigger in project SpongeCommon by SpongePowered.
the class CriterionTrigger_ListenerMixin method impl$callEvents.
// @formatter:on
@SuppressWarnings({ "unchecked", "rawtypes" })
@Inject(method = "run", at = @At("HEAD"), cancellable = true)
private void impl$callEvents(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.criterion);
final CriterionBridge criterionBridge = (CriterionBridge) advancementCriterion;
if (criterionBridge.bridge$getScoreCriterion() != null) {
advancementCriterion = criterionBridge.bridge$getScoreCriterion();
}
if (!PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
// Some mods do advancement granting on async threads, and we can't allow for the spam to be thrown.
return;
}
// Sponge filters are always handled in the trigger method
if (!(this.trigger instanceof SpongeFilteredTrigger)) {
final FilteredTrigger<FilteredTriggerConfiguration> filteredTrigger = (FilteredTrigger) this.trigger;
if (filteredTrigger.type() instanceof SpongeCriterionTrigger) {
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ServerPlayer player = ((PlayerAdvancementsBridge) playerAdvancements).bridge$getPlayer();
final TypeToken<FilteredTriggerConfiguration> typeToken = (TypeToken) TypeToken.get(filteredTrigger.type().configurationType());
final CriterionEvent.Trigger event = SpongeEventFactory.createCriterionEventTrigger(cause, advancement, advancementCriterion, typeToken, player, filteredTrigger, true);
SpongeCommon.post(event);
if (!event.result()) {
ci.cancel();
return;
}
}
}
PhaseTracker.getCauseStackManager().pushCause(this.trigger);
// the score be increased by one.
if (advancementCriterion instanceof ScoreAdvancementCriterion) {
((PlayerAdvancementsBridge) playerAdvancements).bridge$getPlayer().progress(advancement).get((ScoreAdvancementCriterion) advancementCriterion).get().add(1);
ci.cancel();
PhaseTracker.getCauseStackManager().popCause();
}
}
Aggregations