Search in sources :

Example 26 with ServerPlayer

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);
        }
    }
}
Also used : CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) ArrayList(java.util.ArrayList) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) PlayerAdvancements(net.minecraft.server.PlayerAdvancements) TypeToken(io.leangen.geantyref.TypeToken) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Cause(org.spongepowered.api.event.Cause) FilteredTriggerConfiguration(org.spongepowered.api.advancement.criteria.trigger.FilteredTriggerConfiguration) CriterionTrigger_ListenerAccessor(org.spongepowered.common.accessor.advancements.CriterionTrigger_ListenerAccessor) Advancement(org.spongepowered.api.advancement.Advancement)

Example 27 with ServerPlayer

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));
}
Also used : ResourcePack(org.spongepowered.api.resourcepack.ResourcePack) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) ServerGamePacketListenerImplBridge(org.spongepowered.common.bridge.server.network.ServerGamePacketListenerImplBridge) ServerboundResourcePackPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundResourcePackPacketAccessor) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) ResourcePackStatusEvent(org.spongepowered.api.event.entity.living.player.ResourcePackStatusEvent)

Example 28 with ServerPlayer

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);
}
Also used : ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) BlockPos(net.minecraft.core.BlockPos) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge)

Example 29 with ServerPlayer

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));
    }
}
Also used : Cause(org.spongepowered.api.event.Cause) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) Advancement(net.minecraft.advancements.Advancement) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 30 with ServerPlayer

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;
}
Also used : CriterionEvent(org.spongepowered.api.event.advancement.CriterionEvent) PlayerAdvancementsBridge(org.spongepowered.common.bridge.server.PlayerAdvancementsBridge) AdvancementCriterion(org.spongepowered.api.advancement.criteria.AdvancementCriterion) SpongeScoreCriterion(org.spongepowered.common.advancement.criterion.SpongeScoreCriterion) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) Cause(org.spongepowered.api.event.Cause) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) SpongeAndCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeAndCriterionProgress) SpongeOrCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeOrCriterionProgress) SpongeScoreCriterionProgress(org.spongepowered.common.advancement.criterion.SpongeScoreCriterionProgress) ImplementationBackedCriterionProgress(org.spongepowered.common.advancement.criterion.ImplementationBackedCriterionProgress) CriterionProgress(org.spongepowered.api.advancement.criteria.CriterionProgress) CriterionBridge(org.spongepowered.common.bridge.advancements.CriterionBridge)

Aggregations

ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)32 Component (net.kyori.adventure.text.Component)13 Cause (org.spongepowered.api.event.Cause)9 Listener (org.spongepowered.api.event.Listener)8 Sponge (org.spongepowered.api.Sponge)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 TypeToken (io.leangen.geantyref.TypeToken)6 RegistryTypes (org.spongepowered.api.registry.RegistryTypes)6 Inject (com.google.inject.Inject)5 UUID (java.util.UUID)5 Identity (net.kyori.adventure.identity.Identity)5 NamedTextColor (net.kyori.adventure.text.format.NamedTextColor)5 BlockPos (net.minecraft.core.BlockPos)5 AdvancementCriterion (org.spongepowered.api.advancement.criteria.AdvancementCriterion)5 CommandResult (org.spongepowered.api.command.CommandResult)5 CommandException (org.spongepowered.api.command.exception.CommandException)5 CommandContext (org.spongepowered.api.command.parameter.CommandContext)5 Map (java.util.Map)4 Command (org.spongepowered.api.command.Command)4 Parameter (org.spongepowered.api.command.parameter.Parameter)4