Search in sources :

Example 1 with Unit

use of net.minecraft.util.Unit in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method impl$onReturnSleep.

@Inject(method = "startSleepInBed", at = @At(value = "RETURN"), cancellable = true)
private void impl$onReturnSleep(final BlockPos param0, final CallbackInfoReturnable<Either<Player.BedSleepingProblem, Unit>> cir) {
    final Either<Player.BedSleepingProblem, Unit> returnValue = cir.getReturnValue();
    if (returnValue.left().isPresent()) {
        switch(returnValue.left().get()) {
            case NOT_POSSIBLE_HERE:
            case TOO_FAR_AWAY:
            case NOT_POSSIBLE_NOW:
            case OBSTRUCTED:
            case NOT_SAFE:
                final Cause currentCause = Sponge.server().causeStackManager().currentCause();
                final BlockSnapshot snapshot = ((ServerWorld) this.level).createSnapshot(param0.getX(), param0.getY(), param0.getZ());
                if (Sponge.eventManager().post(SpongeEventFactory.createSleepingEventFailed(currentCause, snapshot, (Living) this))) {
                    final Either<Player.BedSleepingProblem, Unit> var5 = super.shadow$startSleepInBed(param0).ifRight((param0x) -> {
                        this.shadow$awardStat(Stats.SLEEP_IN_BED);
                        CriteriaTriggers.SLEPT_IN_BED.trigger((net.minecraft.server.level.ServerPlayer) (Object) this);
                    });
                    ((ServerLevel) this.level).updateSleepingPlayerList();
                    cir.setReturnValue(var5);
                }
                break;
            case // ignore
            OTHER_PROBLEM:
                break;
        }
    }
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) ServerLevel(net.minecraft.server.level.ServerLevel) Living(org.spongepowered.api.entity.living.Living) Cause(org.spongepowered.api.event.Cause) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Unit(net.minecraft.util.Unit) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)1 Unit (net.minecraft.util.Unit)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 Living (org.spongepowered.api.entity.living.Living)1 Cause (org.spongepowered.api.event.Cause)1 ServerWorld (org.spongepowered.api.world.server.ServerWorld)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1