use of org.spongepowered.common.bridge.advancements.CriterionBridge in project SpongeCommon by SpongePowered.
the class AdvancementProgressMixin method impl$revokeCriterion.
private boolean impl$revokeCriterion(String rawCriterion) {
final net.minecraft.advancements.CriterionProgress criterionProgress = this.criteria.get(rawCriterion);
if (criterionProgress == null || !criterionProgress.isDone()) {
return false;
}
if (SpongeScoreCriterion.BYPASS_EVENT) {
criterionProgress.revoke();
return true;
}
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ServerPlayer player = ((PlayerAdvancementsBridge) this.impl$playerAdvancements).bridge$getPlayer();
final CriterionProgress progress = (CriterionProgress) criterionProgress;
final AdvancementCriterion criterion = progress.criterion();
final CriterionBridge criterionBridge = (CriterionBridge) criterion;
// The score criterion needs special care
final SpongeScoreCriterion scoreCriterion = criterionBridge.bridge$getScoreCriterion();
final CriterionEvent event;
final Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) this).advancement();
if (scoreCriterion != null) {
final SpongeScoreCriterionProgress scoreProgress = (SpongeScoreCriterionProgress) this.impl$progressMap.get(scoreCriterion.name());
final int lastScore = scoreProgress.score();
final int score = lastScore + 1;
if (lastScore == scoreCriterion.goal()) {
event = SpongeEventFactory.createCriterionEventScoreRevoke(cause, advancement, scoreCriterion, player, lastScore, score);
} else if (score == scoreCriterion.goal()) {
event = SpongeEventFactory.createCriterionEventScoreGrant(cause, advancement, scoreCriterion, player, Instant.now(), lastScore, score);
} else {
event = SpongeEventFactory.createCriterionEventScoreChange(cause, advancement, scoreCriterion, player, lastScore, score);
}
} else {
event = SpongeEventFactory.createCriterionEventRevoke(cause, advancement, criterion, player);
}
if (SpongeCommon.post(event)) {
return false;
}
criterionProgress.revoke();
return true;
}
use of org.spongepowered.common.bridge.advancements.CriterionBridge 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();
}
}
use of org.spongepowered.common.bridge.advancements.CriterionBridge in project SpongeCommon by SpongePowered.
the class PlayerAdvancementsMixin method impl$updateProgressOnUnregister.
@Nullable
@Redirect(method = "unregisterListeners", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/AdvancementProgress;getCriterion(Ljava/lang/String;)Lnet/minecraft/advancements/CriterionProgress;"))
private CriterionProgress impl$updateProgressOnUnregister(final AdvancementProgress advancementProgress, final String criterion) {
if (((PlatformEntityBridge) this.player).bridge$isFakePlayer()) {
return advancementProgress.getCriterion(criterion);
}
final org.spongepowered.api.advancement.Advancement advancement = ((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).advancement();
final AdvancementCriterion advancementCriterion = (AdvancementCriterion) ((Advancement) advancement).getCriteria().get(criterion);
final CriterionBridge criterionBridge = (CriterionBridge) advancementCriterion;
// Only remove the trigger once the goal is reached
if (criterionBridge.bridge$getScoreCriterion() != null && !((org.spongepowered.api.advancement.AdvancementProgress) advancementProgress).get(criterionBridge.bridge$getScoreCriterion()).get().achieved()) {
return null;
}
return advancementProgress.getCriterion(criterion);
}
use of org.spongepowered.common.bridge.advancements.CriterionBridge in project SpongeCommon by SpongePowered.
the class PlayerAdvancementsMixin method impl$onUnregisterListenersGetProgress.
@Redirect(method = "registerListeners(Lnet/minecraft/advancements/Advancement;)V", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/advancements/CriterionProgress;isDone()Z"))
private boolean impl$onUnregisterListenersGetProgress(final CriterionProgress progress) {
final CriterionProgressBridge mixinCriterionProgress = (CriterionProgressBridge) progress;
if (((PlatformEntityBridge) this.player).bridge$isFakePlayer() || !mixinCriterionProgress.bridge$isCriterionAvailable()) {
return progress.isDone();
}
final AdvancementCriterion criterion = ((org.spongepowered.api.advancement.criteria.CriterionProgress) progress).criterion();
final CriterionBridge mixinCriterion = (CriterionBridge) criterion;
// Only remove the trigger once the goal is reached
if (mixinCriterion.bridge$getScoreCriterion() != null) {
return ((CriterionProgressBridge) progress).bridge$getAdvancementProgress().get(mixinCriterion.bridge$getScoreCriterion()).get().achieved();
}
return progress.isDone();
}
use of org.spongepowered.common.bridge.advancements.CriterionBridge in project SpongeCommon by SpongePowered.
the class SpongeCriterionBuilder method build0.
@SuppressWarnings("ConstantConditions")
@Override
AdvancementCriterion build0() {
CriterionTriggerInstance trigger = (CriterionTriggerInstance) this.trigger;
if (this.trigger == null) {
trigger = SpongeDummyTrigger.Instance.dummy();
}
final Criterion criterion = new Criterion(trigger);
((CriterionBridge) criterion).bridge$setName(this.name);
return (AdvancementCriterion) criterion;
}
Aggregations