|
| 1 | +--- a/net/minecraft/server/level/ServerPlayer.java |
| 2 | ++++ b/net/minecraft/server/level/ServerPlayer.java |
| 3 | +@@ -24,6 +_,12 @@ |
| 4 | + import java.util.stream.Collectors; |
| 5 | + import javax.annotation.Nonnull; |
| 6 | + import javax.annotation.Nullable; |
| 7 | ++ |
| 8 | ++import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents; |
| 9 | ++import net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents; |
| 10 | ++import net.fabricmc.fabric.api.entity.event.v1.ServerEntityLevelChangeEvents; |
| 11 | ++import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; |
| 12 | ++import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents; |
| 13 | + import net.minecraft.ChatFormatting; |
| 14 | + import net.minecraft.CrashReport; |
| 15 | + import net.minecraft.CrashReportCategory; |
| 16 | +@@ -115,6 +_,7 @@ |
| 17 | + import net.minecraft.world.Container; |
| 18 | + import net.minecraft.world.Difficulty; |
| 19 | + import net.minecraft.world.InteractionHand; |
| 20 | ++import net.minecraft.world.InteractionResult; |
| 21 | + import net.minecraft.world.MenuProvider; |
| 22 | + import net.minecraft.world.damagesource.DamageSource; |
| 23 | + import net.minecraft.world.damagesource.DamageTypes; |
| 24 | +@@ -1231,6 +_,13 @@ |
| 25 | + // CraftBukkit end |
| 26 | + |
| 27 | + this.level().getCraftServer().getScoreboardManager().forAllObjectives(ObjectiveCriteria.DEATH_COUNT, this, ScoreAccess::increment); // CraftBukkit - Get our scores instead |
| 28 | ++ final Entity attacker = damageSource.getEntity(); |
| 29 | ++ |
| 30 | ++ // If the damage source that killed the player was an entity, then fire the event. |
| 31 | ++ if (attacker != null) { |
| 32 | ++ attacker.killedEntity(this.level(), (ServerPlayer) (Object) this, damageSource); |
| 33 | ++ ServerEntityCombatEvents.AFTER_KILLED_OTHER_ENTITY.invoker().afterKilledOtherEntity(this.level(), attacker, (ServerPlayer) (Object) this, damageSource); |
| 34 | ++ } |
| 35 | + LivingEntity killCredit = this.getKillCredit(); |
| 36 | + if (killCredit != null) { |
| 37 | + this.awardStat(Stats.ENTITY_KILLED_BY.get(killCredit.getType())); |
| 38 | +@@ -1248,6 +_,7 @@ |
| 39 | + this.getCombatTracker().recheckStatus(); |
| 40 | + this.setLastDeathLocation(Optional.of(GlobalPos.of(this.level().dimension(), this.blockPosition()))); |
| 41 | + this.setClientLoaded(false); |
| 42 | ++ ServerLivingEntityEvents.AFTER_DEATH.invoker().afterDeath((ServerPlayer) (Object) this, damageSource); |
| 43 | + } |
| 44 | + |
| 45 | + private void tellNeutralMobsThatIDied() { |
| 46 | +@@ -1607,6 +_,7 @@ |
| 47 | + if (maindimensionkey1 != Level.NETHER) { // CraftBukkit |
| 48 | + this.enteredNetherPosition = null; |
| 49 | + } |
| 50 | ++ ServerEntityLevelChangeEvents.AFTER_PLAYER_CHANGE_LEVEL.invoker().afterChangeLevel((ServerPlayer) (Object) this, level, this.level()); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | +@@ -1634,7 +_,12 @@ |
| 55 | + this.setRespawnPosition( |
| 56 | + new ServerPlayer.RespawnConfig(LevelData.RespawnData.of(this.level().dimension(), bedPos, this.getYRot(), this.getXRot()), false), true, com.destroystokyo.paper.event.player.PlayerSetSpawnEvent.Cause.BED // Paper - Add PlayerSetSpawnEvent |
| 57 | + ); |
| 58 | +- if (this.level().isBrightOutside()) { |
| 59 | ++ boolean isDay = this.level().isBrightOutside(); |
| 60 | ++ InteractionResult result = EntitySleepEvents.ALLOW_SLEEP_TIME.invoker().allowSleepTime(this, bedPos, !isDay); |
| 61 | ++ if (result != InteractionResult.PASS) { |
| 62 | ++ isDay = !result.consumesAction(); // true from the event = night-like conditions, so we have to invert |
| 63 | ++ } |
| 64 | ++ if (isDay) { |
| 65 | + return Either.left(Player.BedSleepingProblem.NOT_POSSIBLE_NOW); |
| 66 | + } else { |
| 67 | + if (!this.isCreative()) { |
| 68 | +@@ -1647,7 +_,10 @@ |
| 69 | + new AABB(vec3.x() - 8.0, vec3.y() - 5.0, vec3.z() - 8.0, vec3.x() + 8.0, vec3.y() + 5.0, vec3.z() + 8.0), |
| 70 | + monster -> monster.isPreventingPlayerRest(this.level(), this) |
| 71 | + ); |
| 72 | +- if (!entitiesOfClass.isEmpty()) { |
| 73 | ++ boolean vanillaResult = entitiesOfClass.isEmpty(); |
| 74 | ++ InteractionResult monstersResult = EntitySleepEvents.ALLOW_NEARBY_MONSTERS.invoker().allowNearbyMonsters(this, bedPos, vanillaResult); |
| 75 | ++ vanillaResult = result != InteractionResult.PASS ? monstersResult.consumesAction() : vanillaResult; |
| 76 | ++ if (!vanillaResult) { |
| 77 | + return Either.left(Player.BedSleepingProblem.NOT_SAFE); |
| 78 | + } |
| 79 | + } |
| 80 | +@@ -1660,7 +_,12 @@ |
| 81 | + |
| 82 | + @Override |
| 83 | + public Either<net.minecraft.world.entity.player.Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos bedPos, boolean force) { |
| 84 | +- Direction direction = this.level().getBlockState(bedPos).getValue(HorizontalDirectionalBlock.FACING); |
| 85 | ++ BlockState blockState = this.level().getBlockState(bedPos); |
| 86 | ++ Direction direction = (Direction) (blockState.hasProperty(HorizontalDirectionalBlock.FACING) ? blockState.getValue(HorizontalDirectionalBlock.FACING) : null); |
| 87 | ++ Direction dir = EntitySleepEvents.MODIFY_SLEEPING_DIRECTION.invoker().modifySleepDirection((LivingEntity) (Object) this, bedPos, direction); |
| 88 | ++ if (dir == null) { |
| 89 | ++ return Either.left(Player.BedSleepingProblem.OTHER_PROBLEM); |
| 90 | ++ } |
| 91 | + Either<net.minecraft.world.entity.player.Player.BedSleepingProblem, Unit> bedResult = this.getBedResult(bedPos, direction); |
| 92 | + |
| 93 | + if (bedResult.left().orElse(null) == net.minecraft.world.entity.player.Player.BedSleepingProblem.OTHER_PROBLEM) { |
| 94 | +@@ -2157,6 +_,7 @@ |
| 95 | + this.setShoulderEntityLeft(that.getShoulderEntityLeft()); |
| 96 | + this.setShoulderEntityRight(that.getShoulderEntityRight()); |
| 97 | + this.setLastDeathLocation(that.getLastDeathLocation()); |
| 98 | ++ ServerPlayerEvents.COPY_FROM.invoker().copyFromPlayer(that, (ServerPlayer) (Object) this, keepEverything); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
0 commit comments