use of org.spongepowered.api.entity.living.player.server.ServerPlayer 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);
}
}
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class ResourcePackState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final net.minecraft.server.level.ServerPlayer player = phaseContext.getPacketPlayer();
final ServerGamePacketListenerImpl connection = player.connection;
final ServerGamePacketListenerImplBridge mixinHandler = (ServerGamePacketListenerImplBridge) connection;
final ServerboundResourcePackPacketAccessor resource = phaseContext.getPacket();
final ResourcePackStatusEvent.ResourcePackStatus status;
ResourcePack pack;
switch(resource.accessor$action()) {
case ACCEPTED:
pack = mixinHandler.bridge$popReceivedResourcePack(true);
status = ResourcePackStatusEvent.ResourcePackStatus.ACCEPTED;
break;
case DECLINED:
pack = mixinHandler.bridge$popReceivedResourcePack(false);
status = ResourcePackStatusEvent.ResourcePackStatus.DECLINED;
break;
case SUCCESSFULLY_LOADED:
pack = mixinHandler.bridge$popAcceptedResourcePack();
status = ResourcePackStatusEvent.ResourcePackStatus.SUCCESSFULLY_LOADED;
break;
case FAILED_DOWNLOAD:
pack = mixinHandler.bridge$popAcceptedResourcePack();
status = ResourcePackStatusEvent.ResourcePackStatus.FAILED;
break;
default:
throw new AssertionError();
}
if (pack == null) {
return;
}
SpongeCommon.post(SpongeEventFactory.createResourcePackStatusEvent(PhaseTracker.getCauseStackManager().currentCause(), pack, (ServerPlayer) player, status));
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class UseItemPacketState method postBlockTransactionApplication.
@Override
public void postBlockTransactionApplication(final BasicPacketContext context, final BlockChange blockChange, final BlockTransactionReceipt transaction) {
final ServerPlayer player = context.getSpongePlayer();
final BlockPos pos = VecHelper.toBlockPos(transaction.finalBlock().position());
final LevelChunkBridge spongeChunk = (LevelChunkBridge) ((ServerLevel) player.world()).getChunkAt(pos);
if (blockChange == BlockChange.PLACE) {
spongeChunk.bridge$addTrackedBlockPosition((Block) transaction.finalBlock().state().type(), pos, player.uniqueId(), PlayerTracker.Type.CREATOR);
}
spongeChunk.bridge$addTrackedBlockPosition((Block) transaction.finalBlock().state().type(), pos, player.uniqueId(), PlayerTracker.Type.NOTIFIER);
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class PlayerAdvancementsMixin method impl$callRevokeEventIfSuccessful.
@Inject(method = "revoke", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerAdvancements;ensureVisibility(Lnet/minecraft/advancements/Advancement;)V"))
private void impl$callRevokeEventIfSuccessful(final Advancement advancement, final String string, final CallbackInfoReturnable<Boolean> ci, boolean var0) {
if (var0) {
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
SpongeCommon.post(SpongeEventFactory.createAdvancementEventRevoke(currentCause, (org.spongepowered.api.advancement.Advancement) advancement, (ServerPlayer) this.player));
}
}
use of org.spongepowered.api.entity.living.player.server.ServerPlayer in project SpongeCommon by SpongePowered.
the class AdvancementProgressMixin method impl$grantCriterion.
private boolean impl$grantCriterion(String rawCriterion) {
final net.minecraft.advancements.CriterionProgress criterionProgress = this.criteria.get(rawCriterion);
if (criterionProgress == null || criterionProgress.isDone()) {
return false;
}
if (SpongeScoreCriterion.BYPASS_EVENT) {
criterionProgress.grant();
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;
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, this.bridge$getAdvancement(), scoreCriterion, player, lastScore, score);
} else if (score == scoreCriterion.goal()) {
event = SpongeEventFactory.createCriterionEventScoreGrant(cause, this.bridge$getAdvancement(), scoreCriterion, player, Instant.now(), lastScore, score);
} else {
event = SpongeEventFactory.createCriterionEventScoreChange(cause, this.bridge$getAdvancement(), scoreCriterion, player, lastScore, score);
}
} else {
event = SpongeEventFactory.createCriterionEventGrant(cause, this.bridge$getAdvancement(), criterion, player, Instant.now());
}
if (SpongeCommon.post(event)) {
return false;
}
criterionProgress.grant();
return true;
}
Aggregations