|
37 | 37 | import net.minecraft.server.players.PlayerList; |
38 | 38 | import net.minecraft.stats.RecipeBook; |
39 | 39 | import net.minecraft.stats.ServerRecipeBook; |
| 40 | +import net.minecraft.stats.Stats; |
40 | 41 | import net.minecraft.util.Mth; |
41 | 42 | import net.minecraft.util.RandomSource; |
42 | 43 | import net.minecraft.util.Unit; |
|
60 | 61 | import net.minecraft.world.item.enchantment.EnchantmentHelper; |
61 | 62 | import net.minecraft.world.level.GameType; |
62 | 63 | import net.minecraft.world.level.Level; |
| 64 | +import net.minecraft.world.level.block.CampfireBlock; |
| 65 | +import net.minecraft.world.level.block.state.properties.BlockStateProperties; |
63 | 66 | import net.minecraft.world.level.border.WorldBorder; |
64 | 67 | import net.minecraft.world.level.dimension.LevelStem; |
65 | 68 | import net.minecraft.world.level.portal.DimensionTransition; |
@@ -452,7 +455,6 @@ public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean p_348590_ |
452 | 455 | } |
453 | 456 |
|
454 | 457 |
|
455 | | - |
456 | 458 | @Redirect(method = "adjustSpawnLocation", at = @At(value = "INVOKE", |
457 | 459 | target = "Lnet/minecraft/world/level/storage/ServerLevelData;getGameType()Lnet/minecraft/world/level/GameType;")) |
458 | 460 | private GameType neotenet$useWorldGameType(ServerLevelData instance, @Local(argsOnly = true) ServerLevel p_352206_) { |
@@ -656,6 +658,40 @@ public Either<BedSleepingProblem, Unit> getBedResult(BlockPos blockposition, Dir |
656 | 658 | return Either.left(BedSleepingProblem.OTHER_PROBLEM); |
657 | 659 | } |
658 | 660 |
|
| 661 | + @Override |
| 662 | + public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos blockposition, boolean force) { |
| 663 | + Direction enumdirection = (Direction) this.level().getBlockState(blockposition).getValue(BlockStateProperties.HORIZONTAL_FACING); |
| 664 | + Either<Player.BedSleepingProblem, Unit> bedResult = this.getBedResult(blockposition, enumdirection); |
| 665 | + |
| 666 | + if (bedResult.left().orElse(null) == Player.BedSleepingProblem.OTHER_PROBLEM) { |
| 667 | + return bedResult; // return immediately if the result is not bypassable by plugins |
| 668 | + } |
| 669 | + |
| 670 | + if (force) { |
| 671 | + bedResult = Either.right(Unit.INSTANCE); |
| 672 | + } |
| 673 | + |
| 674 | + bedResult = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerBedEnterEvent(this, blockposition, bedResult); |
| 675 | + if (bedResult.left().isPresent()) { |
| 676 | + return bedResult; |
| 677 | + } |
| 678 | + { |
| 679 | + { |
| 680 | + // Start vanilla code |
| 681 | + Either<Player.BedSleepingProblem, Unit> either = super.startSleepInBed(blockposition).ifRight(p_9029_ -> { |
| 682 | + this.awardStat(Stats.SLEEP_IN_BED); |
| 683 | + CriteriaTriggers.SLEPT_IN_BED.trigger((ServerPlayer) (Object) this); |
| 684 | + }); |
| 685 | + if (!this.serverLevel().canSleepThroughNights()) { |
| 686 | + this.displayClientMessage(Component.translatable("sleep.not_possible"), true); |
| 687 | + } |
| 688 | + |
| 689 | + ((ServerLevel) this.level()).updateSleepingPlayerList(); |
| 690 | + return either; |
| 691 | + } |
| 692 | + } |
| 693 | + } |
| 694 | + |
659 | 695 | @Override |
660 | 696 | public Scoreboard getScoreboard() { |
661 | 697 | return this.getBukkitEntity().getScoreboard().getHandle(); |
|
0 commit comments