13
0
geforkt von Mirrors/Paper

Add PlayerDeepSleepEvent

Dieser Commit ist enthalten in:
Jake Potrebic 2021-04-21 15:58:19 -07:00
Ursprung a3c944c37b
Commit bb4539d223

Datei anzeigen

@ -35,7 +35,7 @@
public final InventoryMenu inventoryMenu; public final InventoryMenu inventoryMenu;
public AbstractContainerMenu containerMenu; public AbstractContainerMenu containerMenu;
protected FoodData foodData = new FoodData(); protected FoodData foodData = new FoodData();
@@ -181,13 +191,24 @@ @@ -181,14 +191,25 @@
private Optional<GlobalPos> lastDeathLocation; private Optional<GlobalPos> lastDeathLocation;
@Nullable @Nullable
public FishingHook fishing; public FishingHook fishing;
@ -48,7 +48,7 @@
private boolean ignoreFallDamageFromCurrentImpulse; private boolean ignoreFallDamageFromCurrentImpulse;
private int currentImpulseContextResetGraceTime; private int currentImpulseContextResetGraceTime;
+ public boolean affectsSpawning = true; // Paper - Affects Spawning API + public boolean affectsSpawning = true; // Paper - Affects Spawning API
+
+ // CraftBukkit start + // CraftBukkit start
+ public boolean fauxSleeping; + public boolean fauxSleeping;
+ public int oldLevel = -1; + public int oldLevel = -1;
@ -58,10 +58,25 @@
+ return (CraftHumanEntity) super.getBukkitEntity(); + return (CraftHumanEntity) super.getBukkitEntity();
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+
public Player(Level world, BlockPos pos, float yaw, GameProfile gameProfile) { public Player(Level world, BlockPos pos, float yaw, GameProfile gameProfile) {
super(EntityType.PLAYER, world); super(EntityType.PLAYER, world);
@@ -261,7 +282,7 @@ this.lastItemInMainHand = ItemStack.EMPTY;
@@ -244,6 +265,13 @@
if (this.isSleeping()) {
++this.sleepCounter;
+ // Paper start - Add PlayerDeepSleepEvent
+ if (this.sleepCounter == SLEEP_DURATION) {
+ if (!new io.papermc.paper.event.player.PlayerDeepSleepEvent((org.bukkit.entity.Player) getBukkitEntity()).callEvent()) {
+ this.sleepCounter = Integer.MIN_VALUE;
+ }
+ }
+ // Paper end - Add PlayerDeepSleepEvent
if (this.sleepCounter > 100) {
this.sleepCounter = 100;
}
@@ -261,7 +289,7 @@
this.updateIsUnderwater(); this.updateIsUnderwater();
super.tick(); super.tick();
if (!this.level().isClientSide && this.containerMenu != null && !this.containerMenu.stillValid(this)) { if (!this.level().isClientSide && this.containerMenu != null && !this.containerMenu.stillValid(this)) {
@ -70,7 +85,7 @@
this.containerMenu = this.inventoryMenu; this.containerMenu = this.inventoryMenu;
} }
@@ -353,7 +374,7 @@ @@ -353,7 +381,7 @@
} }
private void turtleHelmetTick() { private void turtleHelmetTick() {
@ -79,7 +94,7 @@
} }
private boolean isEquipped(Item item) { private boolean isEquipped(Item item) {
@@ -513,6 +534,13 @@ @@ -513,6 +541,13 @@
} }
@ -93,7 +108,7 @@
public void closeContainer() { public void closeContainer() {
this.containerMenu = this.inventoryMenu; this.containerMenu = this.inventoryMenu;
} }
@@ -523,8 +551,14 @@ @@ -523,8 +558,14 @@
public void rideTick() { public void rideTick() {
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) { if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
this.stopRiding(); this.stopRiding();
@ -110,7 +125,7 @@
super.rideTick(); super.rideTick();
this.oBob = this.bob; this.oBob = this.bob;
this.bob = 0.0F; this.bob = 0.0F;
@@ -593,6 +627,7 @@ @@ -593,6 +634,7 @@
this.playShoulderEntityAmbientSound(this.getShoulderEntityLeft()); this.playShoulderEntityAmbientSound(this.getShoulderEntityLeft());
this.playShoulderEntityAmbientSound(this.getShoulderEntityRight()); this.playShoulderEntityAmbientSound(this.getShoulderEntityRight());
if (!this.level().isClientSide && (this.fallDistance > 0.5F || this.isInWater()) || this.abilities.flying || this.isSleeping() || this.isInPowderSnow) { if (!this.level().isClientSide && (this.fallDistance > 0.5F || this.isInWater()) || this.abilities.flying || this.isSleeping() || this.isInPowderSnow) {
@ -118,7 +133,7 @@
this.removeEntitiesOnShoulder(); this.removeEntitiesOnShoulder();
} }
@@ -719,7 +754,14 @@ @@ -719,7 +761,14 @@
@Nullable @Nullable
public ItemEntity drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership) { public ItemEntity drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership) {
@ -134,7 +149,7 @@
this.swing(InteractionHand.MAIN_HAND); this.swing(InteractionHand.MAIN_HAND);
} }
@@ -809,7 +851,7 @@ @@ -809,7 +858,7 @@
} }
if (nbt.contains("LastDeathLocation", 10)) { if (nbt.contains("LastDeathLocation", 10)) {
@ -143,7 +158,7 @@
Logger logger = Player.LOGGER; Logger logger = Player.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -817,7 +859,7 @@ @@ -817,7 +866,7 @@
} }
if (nbt.contains("current_explosion_impact_pos", 9)) { if (nbt.contains("current_explosion_impact_pos", 9)) {
@ -152,7 +167,7 @@
Logger logger1 = Player.LOGGER; Logger logger1 = Player.LOGGER;
Objects.requireNonNull(logger1); Objects.requireNonNull(logger1);
@@ -854,7 +896,7 @@ @@ -854,7 +903,7 @@
} }
this.getLastDeathLocation().flatMap((globalpos) -> { this.getLastDeathLocation().flatMap((globalpos) -> {
@ -161,7 +176,7 @@
Logger logger = Player.LOGGER; Logger logger = Player.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -886,10 +928,10 @@ @@ -886,10 +935,10 @@
if (this.isDeadOrDying()) { if (this.isDeadOrDying()) {
return false; return false;
} else { } else {
@ -174,7 +189,7 @@
} }
if (world.getDifficulty() == Difficulty.EASY) { if (world.getDifficulty() == Difficulty.EASY) {
@@ -901,7 +943,13 @@ @@ -901,7 +950,13 @@
} }
} }
@ -189,7 +204,7 @@
} }
} }
} }
@@ -923,10 +971,29 @@ @@ -923,10 +978,29 @@
} }
public boolean canHarmPlayer(Player player) { public boolean canHarmPlayer(Player player) {
@ -222,7 +237,7 @@
} }
@Override @Override
@@ -966,32 +1033,38 @@ @@ -966,32 +1040,38 @@
} }
} }
@ -275,7 +290,7 @@
} }
public boolean isTextFilteringEnabled() { public boolean isTextFilteringEnabled() {
@@ -1061,13 +1134,19 @@ @@ -1061,13 +1141,19 @@
@Override @Override
public void removeVehicle() { public void removeVehicle() {
@ -297,7 +312,7 @@
} }
@Override @Override
@@ -1144,10 +1223,15 @@ @@ -1144,10 +1230,15 @@
f *= 0.2F + f2 * f2 * 0.8F; f *= 0.2F + f2 * f2 * 0.8F;
f1 *= f2; f1 *= f2;
@ -314,7 +329,7 @@
if (iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) { if (iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) {
this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource()); this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource());
return; return;
@@ -1159,7 +1243,7 @@ @@ -1159,7 +1250,7 @@
boolean flag1; boolean flag1;
if (this.isSprinting() && flag) { if (this.isSprinting() && flag) {
@ -323,7 +338,7 @@
flag1 = true; flag1 = true;
} else { } else {
flag1 = false; flag1 = false;
@@ -1168,6 +1252,7 @@ @@ -1168,6 +1259,7 @@
f += itemstack.getItem().getAttackDamageBonus(target, f, damagesource); f += itemstack.getItem().getAttackDamageBonus(target, f, damagesource);
boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity && !this.isSprinting(); boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround() && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && target instanceof LivingEntity && !this.isSprinting();
@ -331,7 +346,7 @@
if (flag2) { if (flag2) {
f *= 1.5F; f *= 1.5F;
} }
@@ -1202,13 +1287,17 @@ @@ -1202,13 +1294,17 @@
if (target instanceof LivingEntity) { if (target instanceof LivingEntity) {
LivingEntity entityliving1 = (LivingEntity) target; LivingEntity entityliving1 = (LivingEntity) target;
@ -351,7 +366,7 @@
} }
LivingEntity entityliving2; LivingEntity entityliving2;
@@ -1223,8 +1312,13 @@ @@ -1223,8 +1319,13 @@
if (entityliving2 != this && entityliving2 != target && !this.isAlliedTo((Entity) entityliving2) && (!(entityliving2 instanceof ArmorStand) || !((ArmorStand) entityliving2).isMarker()) && this.distanceToSqr((Entity) entityliving2) < 9.0D) { if (entityliving2 != this && entityliving2 != target && !this.isAlliedTo((Entity) entityliving2) && (!(entityliving2 instanceof ArmorStand) || !((ArmorStand) entityliving2).isMarker()) && this.distanceToSqr((Entity) entityliving2) < 9.0D) {
float f7 = this.getEnchantedDamage(entityliving2, f6, damagesource) * f2; float f7 = this.getEnchantedDamage(entityliving2, f6, damagesource) * f2;
@ -367,7 +382,7 @@
Level world = this.level(); Level world = this.level();
if (world instanceof ServerLevel) { if (world instanceof ServerLevel) {
@@ -1235,26 +1329,43 @@ @@ -1235,26 +1336,43 @@
} }
} }
@ -415,7 +430,7 @@
} }
} }
@@ -1308,9 +1419,14 @@ @@ -1308,9 +1426,14 @@
} }
} }
@ -432,7 +447,7 @@
} }
} }
@@ -1351,7 +1467,14 @@ @@ -1351,7 +1474,14 @@
@Override @Override
public void remove(Entity.RemovalReason reason) { public void remove(Entity.RemovalReason reason) {
@ -448,7 +463,7 @@
this.inventoryMenu.removed(this); this.inventoryMenu.removed(this);
if (this.containerMenu != null && this.hasContainerOpen()) { if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer(); this.doCloseContainer();
@@ -1391,7 +1514,13 @@ @@ -1391,7 +1521,13 @@
} }
public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos pos) { public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos pos) {
@ -463,7 +478,7 @@
this.sleepCounter = 0; this.sleepCounter = 0;
return Either.right(Unit.INSTANCE); return Either.right(Unit.INSTANCE);
} }
@@ -1545,12 +1674,24 @@ @@ -1545,12 +1681,24 @@
} }
public void startFallFlying() { public void startFallFlying() {
@ -489,7 +504,7 @@
} }
@Override @Override
@@ -1664,11 +1805,30 @@ @@ -1664,11 +1812,30 @@
public int getXpNeededForNextLevel() { public int getXpNeededForNextLevel() {
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2); return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
} }
@ -521,7 +536,7 @@
} }
} }
@@ -1748,13 +1908,20 @@ @@ -1748,13 +1915,20 @@
@Override @Override
public void setItemSlot(EquipmentSlot slot, ItemStack stack) { public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
@ -549,7 +564,7 @@
} }
} }
@@ -1798,26 +1965,55 @@ @@ -1798,26 +1972,55 @@
public void removeEntitiesOnShoulder() { public void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
@ -612,7 +627,7 @@
} }
@Override @Override
@@ -2003,20 +2199,31 @@ @@ -2003,20 +2206,31 @@
@Override @Override
public ImmutableList<Pose> getDismountPoses() { public ImmutableList<Pose> getDismountPoses() {
return ImmutableList.of(Pose.STANDING, Pose.CROUCHING, Pose.SWIMMING); return ImmutableList.of(Pose.STANDING, Pose.CROUCHING, Pose.SWIMMING);