net.minecraft.world.entity.player

This commit is contained in:
Jake Potrebic 2024-12-14 16:39:48 -08:00
parent d3ec6a433b
commit 6bb7e658de
No known key found for this signature in database
GPG key ID: ECE0B3C133C016C5
4 changed files with 714 additions and 791 deletions

View file

@ -1,30 +1,16 @@
--- a/net/minecraft/world/entity/player/Inventory.java --- a/net/minecraft/world/entity/player/Inventory.java
+++ b/net/minecraft/world/entity/player/Inventory.java +++ b/net/minecraft/world/entity/player/Inventory.java
@@ -23,6 +23,12 @@ @@ -36,6 +_,54 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
+// CraftBukkit start
+import java.util.ArrayList;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
public class Inventory implements Container, Nameable {
@@ -38,7 +44,55 @@
public int selected;
public final Player player; public final Player player;
private int timesChanged; private int timesChanged;
+
+ // CraftBukkit start - add fields and methods + // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>(); + public List<org.bukkit.entity.HumanEntity> transaction = new java.util.ArrayList<org.bukkit.entity.HumanEntity>();
+ private int maxStack = MAX_STACK; + private int maxStack = MAX_STACK;
+ +
+ public List<ItemStack> getContents() { + public List<ItemStack> getContents() {
+ List<ItemStack> combined = new ArrayList<ItemStack>(this.items.size() + this.armor.size() + this.offhand.size()); + List<ItemStack> combined = new java.util.ArrayList<>(this.items.size() + this.armor.size() + this.offhand.size());
+ for (List<net.minecraft.world.item.ItemStack> sub : this.compartments) { + for (List<ItemStack> sub : this.compartments) {
+ combined.addAll(sub); + combined.addAll(sub);
+ } + }
+ +
@ -35,15 +21,15 @@
+ return this.armor; + return this.armor;
+ } + }
+ +
+ public void onOpen(CraftHumanEntity who) { + public void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity who) {
+ this.transaction.add(who); + this.transaction.add(who);
+ } + }
+ +
+ public void onClose(CraftHumanEntity who) { + public void onClose(org.bukkit.craftbukkit.entity.CraftHumanEntity who) {
+ this.transaction.remove(who); + this.transaction.remove(who);
+ } + }
+ +
+ public List<HumanEntity> getViewers() { + public List<org.bukkit.entity.HumanEntity> getViewers() {
+ return this.transaction; + return this.transaction;
+ } + }
+ +
@ -59,24 +45,28 @@
+ public void setMaxStackSize(int size) { + public void setMaxStackSize(int size) {
+ this.maxStack = size; + this.maxStack = size;
+ } + }
+
+ @Override + @Override
+ public Location getLocation() { + public org.bukkit.Location getLocation() {
+ return this.player.getBukkitEntity().getLocation(); + return this.player.getBukkitEntity().getLocation();
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+ +
public Inventory(Player player) { public Inventory(Player player) {
this.items = NonNullList.withSize(36, ItemStack.EMPTY); this.player = player;
this.armor = NonNullList.withSize(4, ItemStack.EMPTY);
@@ -56,9 +110,31 @@
}
private boolean hasRemainingSpaceForItem(ItemStack existingStack, ItemStack stack) {
- return !existingStack.isEmpty() && ItemStack.isSameItemSameComponents(existingStack, stack) && existingStack.isStackable() && existingStack.getCount() < this.getMaxStackSize(existingStack);
+ return !existingStack.isEmpty() && existingStack.isStackable() && existingStack.getCount() < this.getMaxStackSize(existingStack) && ItemStack.isSameItemSameComponents(existingStack, stack); // Paper - check if itemstack is stackable first
} }
@@ -50,10 +_,32 @@
private boolean hasRemainingSpaceForItem(ItemStack destination, ItemStack origin) {
return !destination.isEmpty()
- && ItemStack.isSameItemSameComponents(destination, origin)
&& destination.isStackable()
- && destination.getCount() < this.getMaxStackSize(destination);
- }
+ && destination.getCount() < this.getMaxStackSize(destination)
+ && ItemStack.isSameItemSameComponents(destination, origin); // Paper - check if itemstack is stackable first
+ }
+
+ // CraftBukkit start - Watch method above! :D + // CraftBukkit start - Watch method above! :D
+ public int canHold(ItemStack itemstack) { + public int canHold(ItemStack itemstack) {
+ int remains = itemstack.getCount(); + int remains = itemstack.getCount();
@ -98,33 +88,30 @@
+ return itemstack.getCount() - remains; + return itemstack.getCount() - remains;
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+
public int getFreeSlot() { public int getFreeSlot() {
for (int i = 0; i < this.items.size(); ++i) { for (int i = 0; i < this.items.size(); i++) {
if (((ItemStack) this.items.get(i)).isEmpty()) { @@ -65,7 +_,10 @@
@@ -69,8 +145,10 @@
return -1; return -1;
} }
- public void addAndPickItem(ItemStack stack) { - public void addAndPickItem(ItemStack stack) {
- this.selected = this.getSuitableHotbarSlot();
+ // Paper start - Add PlayerPickItemEvent + // Paper start - Add PlayerPickItemEvent
+ public void addAndPickItem(ItemStack stack, final int targetSlot) { + public void addAndPickItem(ItemStack stack, final int targetSlot) {
+ this.selected = targetSlot; + this.selected = targetSlot;
+ // Paper end - Add PlayerPickItemEvent + // Paper end - Add PlayerPickItemEvent
if (!((ItemStack) this.items.get(this.selected)).isEmpty()) { this.selected = this.getSuitableHotbarSlot();
int i = this.getFreeSlot(); if (!this.items.get(this.selected).isEmpty()) {
int freeSlot = this.getFreeSlot();
@@ -82,8 +160,10 @@ @@ -77,7 +_,10 @@
this.items.set(this.selected, stack); this.items.set(this.selected, stack);
} }
- public void pickSlot(int slot) { - public void pickSlot(int index) {
- this.selected = this.getSuitableHotbarSlot();
+ // Paper start - Add PlayerPickItemEvent + // Paper start - Add PlayerPickItemEvent
+ public void pickSlot(int slot, final int targetSlot) { + public void pickSlot(int index, final int targetSlot) {
+ this.selected = targetSlot; + this.selected = targetSlot;
+ // Paper end - Add PlayerPickItemEvent + // Paper end - Add PlayerPickItemEvent
ItemStack itemstack = (ItemStack) this.items.get(this.selected); this.selected = this.getSuitableHotbarSlot();
ItemStack itemStack = this.items.get(this.selected);
this.items.set(this.selected, (ItemStack) this.items.get(slot)); this.items.set(this.selected, this.items.get(index));

View file

@ -0,0 +1,671 @@
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -159,7 +_,7 @@
public static final int CLIENT_LOADED_TIMEOUT_TIME = 60;
private long timeEntitySatOnShoulder;
final Inventory inventory = new Inventory(this);
- protected PlayerEnderChestContainer enderChestInventory = new PlayerEnderChestContainer();
+ protected PlayerEnderChestContainer enderChestInventory = new PlayerEnderChestContainer(this); // CraftBukkit - add "this" to constructor
public final InventoryMenu inventoryMenu;
public AbstractContainerMenu containerMenu;
protected FoodData foodData = new FoodData();
@@ -191,13 +_,25 @@
private Optional<GlobalPos> lastDeathLocation = Optional.empty();
@Nullable
public FishingHook fishing;
- protected float hurtDir;
+ public float hurtDir; // Paper - protected -> public
@Nullable
public Vec3 currentImpulseImpactPos;
@Nullable
public Entity currentExplosionCause;
private boolean ignoreFallDamageFromCurrentImpulse;
private int currentImpulseContextResetGraceTime;
+ public boolean affectsSpawning = true; // Paper - Affects Spawning API
+ public net.kyori.adventure.util.TriState flyingFallDamage = net.kyori.adventure.util.TriState.NOT_SET; // Paper - flying fall damage
+
+ // CraftBukkit start
+ public boolean fauxSleeping;
+ public int oldLevel = -1;
+
+ @Override
+ public org.bukkit.craftbukkit.entity.CraftHumanEntity getBukkitEntity() {
+ return (org.bukkit.craftbukkit.entity.CraftHumanEntity) super.getBukkitEntity();
+ }
+ // CraftBukkit end
public Player(Level level, BlockPos pos, float yRot, GameProfile gameProfile) {
super(EntityType.PLAYER, level);
@@ -261,6 +_,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;
}
@@ -278,7 +_,7 @@
this.updateIsUnderwater();
super.tick();
if (!this.level().isClientSide && this.containerMenu != null && !this.containerMenu.stillValid(this)) {
- this.closeContainer();
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper - Inventory close reason
this.containerMenu = this.inventoryMenu;
}
@@ -365,7 +_,7 @@
}
private void turtleHelmetTick() {
- this.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
+ this.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit
}
private boolean isEquipped(Item item) {
@@ -512,6 +_,18 @@
}
}
+ // Paper start - Inventory close reason; unused code, but to keep signatures aligned
+ public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ this.closeContainer();
+ this.containerMenu = this.inventoryMenu;
+ }
+ // Paper end - Inventory close reason
+ // Paper start - special close for unloaded inventory
+ public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ this.containerMenu = this.inventoryMenu;
+ }
+ // Paper end - special close for unloaded inventory
+
public void closeContainer() {
this.containerMenu = this.inventoryMenu;
}
@@ -523,8 +_,14 @@
public void rideTick() {
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
this.stopRiding();
- this.setShiftKeyDown(false);
- } else {
+ // CraftBukkit start - SPIGOT-7316: no longer passenger, dismount and return
+ if (!this.isPassenger()) {
+ this.setShiftKeyDown(false);
+ return;
+ }
+ }
+ {
+ // CraftBukkit end
super.rideTick();
this.oBob = this.bob;
this.bob = 0.0F;
@@ -588,6 +_,7 @@
this.playShoulderEntityAmbientSound(this.getShoulderEntityLeft());
this.playShoulderEntityAmbientSound(this.getShoulderEntityRight());
if (!this.level().isClientSide && (this.fallDistance > 0.5F || this.isInWater()) || this.abilities.flying || this.isSleeping() || this.isInPowderSnow) {
+ if (!this.level().paperConfig().entities.behavior.parrotsAreUnaffectedByPlayerMovement) // Paper - Add option to make parrots stay
this.removeEntitiesOnShoulder();
}
}
@@ -717,6 +_,13 @@
@Nullable
public ItemEntity drop(ItemStack droppedItem, boolean dropAround, boolean includeThrowerName) {
+ // CraftBukkit start - SPIGOT-2942: Add boolean to call event
+ return this.drop(droppedItem, dropAround, includeThrowerName, true);
+ }
+
+ @Nullable
+ public ItemEntity drop(ItemStack droppedItem, boolean dropAround, boolean includeThrowerName, boolean callEvent) {
+ // CraftBukkit end
if (!droppedItem.isEmpty() && this.level().isClientSide) {
this.swing(InteractionHand.MAIN_HAND);
}
@@ -867,10 +_,10 @@
if (this.isDeadOrDying()) {
return false;
} else {
- this.removeEntitiesOnShoulder();
+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
if (damageSource.scalesWithDifficulty()) {
if (level.getDifficulty() == Difficulty.PEACEFUL) {
- amount = 0.0F;
+ return false; // CraftBukkit - f = 0.0f -> return false
}
if (level.getDifficulty() == Difficulty.EASY) {
@@ -882,7 +_,14 @@
}
}
- return amount != 0.0F && super.hurtServer(level, damageSource, amount);
+ // return amount != 0.0F && super.hurtServer(level, damageSource, amount);
+ // CraftBukkit start - Don't filter out 0 damage
+ boolean damaged = super.hurtServer(level, damageSource, amount);
+ if (damaged) {
+ this.removeEntitiesOnShoulder();
+ }
+ return damaged;
+ // CraftBukkit end
}
}
}
@@ -892,7 +_,7 @@
super.blockUsingShield(entity);
ItemStack itemBlockingWith = this.getItemBlockingWith();
if (entity.canDisableShield() && itemBlockingWith != null) {
- this.disableShield(itemBlockingWith);
+ this.disableShield(itemBlockingWith, entity); // Paper - Add PlayerShieldDisableEvent
}
}
@@ -902,9 +_,29 @@
}
public boolean canHarmPlayer(Player other) {
- Team team = this.getTeam();
- Team team1 = other.getTeam();
- return team == null || !team.isAlliedTo(team1) || team.isAllowFriendlyFire();
+ // CraftBukkit start - Change to check OTHER player's scoreboard team according to API
+ // To summarize this method's logic, it's "Can parameter hurt this"
+ org.bukkit.scoreboard.Team team;
+ if (other instanceof ServerPlayer) {
+ ServerPlayer thatPlayer = (ServerPlayer) other;
+ team = thatPlayer.getBukkitEntity().getScoreboard().getPlayerTeam(thatPlayer.getBukkitEntity());
+ if (team == null || team.allowFriendlyFire()) {
+ return true;
+ }
+ } else {
+ // This should never be called, but is implemented anyway
+ org.bukkit.OfflinePlayer thisPlayer = other.level().getCraftServer().getOfflinePlayer(other.getScoreboardName());
+ team = other.level().getCraftServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
+ if (team == null || team.allowFriendlyFire()) {
+ return true;
+ }
+ }
+
+ if (this instanceof ServerPlayer) {
+ return !team.hasPlayer(((ServerPlayer) this).getBukkitEntity());
+ }
+ return !team.hasPlayer(this.level().getCraftServer().getOfflinePlayer(this.getScoreboardName()));
+ // CraftBukkit end
}
@Override
@@ -943,7 +_,12 @@
}
@Override
- protected void actuallyHurt(ServerLevel level, DamageSource damageSource, float amount) {
+ // CraftBukkit start
+ protected boolean actuallyHurt(ServerLevel level, DamageSource damageSource, float amount, org.bukkit.event.entity.EntityDamageEvent event) { // void -> boolean
+ if (true) {
+ return super.actuallyHurt(level, damageSource, amount, event);
+ }
+ // CraftBukkit end
if (!this.isInvulnerableTo(level, damageSource)) {
amount = this.getDamageAfterArmorAbsorb(damageSource, amount);
amount = this.getDamageAfterMagicAbsorb(damageSource, amount);
@@ -955,7 +_,7 @@
}
if (var8 != 0.0F) {
- this.causeFoodExhaustion(damageSource.getFoodExhaustion());
+ this.causeFoodExhaustion(damageSource.getFoodExhaustion(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
this.getCombatTracker().recordDamage(damageSource, var8);
this.setHealth(this.getHealth() - var8);
if (var8 < 3.4028235E37F) {
@@ -965,6 +_,7 @@
this.gameEvent(GameEvent.ENTITY_DAMAGE);
}
}
+ return false; // CraftBukkit
}
public boolean isTextFilteringEnabled() {
@@ -1040,13 +_,19 @@
@Override
public void removeVehicle() {
- super.removeVehicle();
+ // Paper start - Force entity dismount during teleportation
+ this.removeVehicle(false);
+ }
+ @Override
+ public void removeVehicle(boolean suppressCancellation) {
+ super.removeVehicle(suppressCancellation);
+ // Paper end - Force entity dismount during teleportation
this.boardingCooldown = 0;
}
@Override
protected boolean isImmobile() {
- return super.isImmobile() || this.isSleeping();
+ return super.isImmobile() || this.isSleeping() || this.isRemoved() || !valid; // Paper - player's who are dead or not in a world shouldn't move...
}
@Override
@@ -1125,8 +_,17 @@
}
public void attack(Entity target) {
- if (target.isAttackable()) {
- if (!target.skipAttackInteraction(this)) {
+ // Paper start - PlayerAttackEntityEvent
+ boolean willAttack = target.isAttackable() && !target.skipAttackInteraction(this); // Vanilla logic
+ io.papermc.paper.event.player.PrePlayerAttackEntityEvent playerAttackEntityEvent = new io.papermc.paper.event.player.PrePlayerAttackEntityEvent(
+ (org.bukkit.entity.Player) this.getBukkitEntity(),
+ target.getBukkitEntity(),
+ willAttack
+ );
+
+ if (playerAttackEntityEvent.callEvent() && willAttack) { // Logic moved to willAttack local variable.
+ {
+ // Paper end - PlayerAttackEntityEvent
float f = this.isAutoSpinAttack() ? this.autoSpinAttackDmg : (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE);
ItemStack weaponItem = this.getWeaponItem();
DamageSource damageSource = Optional.ofNullable(weaponItem.getItem().getDamageSource(this)).orElse(this.damageSources().playerAttack(this));
@@ -1134,18 +_,25 @@
float attackStrengthScale = this.getAttackStrengthScale(0.5F);
f *= 0.2F + attackStrengthScale * attackStrengthScale * 0.8F;
f1 *= attackStrengthScale;
- this.resetAttackStrengthTicker();
+ // this.resetAttackStrengthTicker(); // CraftBukkit - Moved to EntityLiving to reset the cooldown after the damage is dealt
if (target.getType().is(EntityTypeTags.REDIRECTABLE_PROJECTILE)
- && target instanceof Projectile projectile
- && projectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) {
- this.level().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource());
- } else {
+ && target instanceof Projectile projectile) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(target, damageSource, f1, false)) {
+ return;
+ }
+ if (projectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) {
+ this.level().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource());
+ return;
+ }
+ }
+ {
+ // CraftBukkit end
if (f > 0.0F || f1 > 0.0F) {
boolean flag = attackStrengthScale > 0.9F;
boolean flag1;
if (this.isSprinting() && flag) {
- this.level()
- .playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F);
+ this.sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
flag1 = true;
} else {
flag1 = false;
@@ -1161,7 +_,9 @@
&& !this.isPassenger()
&& target instanceof LivingEntity
&& !this.isSprinting();
+ flag2 = flag2 && !this.level().paperConfig().entities.behavior.disablePlayerCrits; // Paper - Toggleable player crits
if (flag2) {
+ damageSource = damageSource.critical(true); // Paper start - critical damage API
f *= 1.5F;
}
@@ -1188,17 +_,23 @@
if (target instanceof LivingEntity livingEntity1) {
livingEntity1.knockback(
f4 * 0.5F, Mth.sin(this.getYRot() * (float) (Math.PI / 180.0)), -Mth.cos(this.getYRot() * (float) (Math.PI / 180.0))
+ , this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK // Paper - knockback events
);
} else {
target.push(
-Mth.sin(this.getYRot() * (float) (Math.PI / 180.0)) * f4 * 0.5F,
0.1,
Mth.cos(this.getYRot() * (float) (Math.PI / 180.0)) * f4 * 0.5F
+ , this // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
);
}
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6, 1.0, 0.6));
+ // Paper start - Configurable sprint interruption on attack
+ if (!this.level().paperConfig().misc.disableSprintInterruptionOnAttack) {
this.setSprinting(false);
+ }
+ // Paper end - Configurable sprint interruption on attack
}
if (flag3) {
@@ -1212,43 +_,62 @@
&& (!(livingEntity2 instanceof ArmorStand) || !((ArmorStand)livingEntity2).isMarker())
&& this.distanceToSqr(livingEntity2) < 9.0) {
float f6 = this.getEnchantedDamage(livingEntity2, f5, damageSource) * attackStrengthScale;
+ // CraftBukkit start - Only apply knockback if the damage hits
+ if (!livingEntity2.hurtServer((ServerLevel) this.level(), this.damageSources().playerAttack(this).sweep().critical(flag2), f6)) { // Paper - add critical damage API
+ continue;
+ }
+ // CraftBukkit end
livingEntity2.knockback(
0.4F, Mth.sin(this.getYRot() * (float) (Math.PI / 180.0)), -Mth.cos(this.getYRot() * (float) (Math.PI / 180.0))
+ , this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SWEEP_ATTACK // CraftBukkit // Paper - knockback events
);
- livingEntity2.hurt(damageSource, f6);
+ // CraftBukkit - moved up
if (this.level() instanceof ServerLevel serverLevel) {
EnchantmentHelper.doPostAttackEffects(serverLevel, livingEntity2, damageSource);
}
}
}
- this.level()
- .playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F);
+ this.sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
this.sweepAttack();
}
if (target instanceof ServerPlayer && target.hurtMarked) {
+ // CraftBukkit start - Add Velocity Event
+ boolean cancelled = false;
+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) target.getBukkitEntity();
+ org.bukkit.util.Vector velocity = org.bukkit.craftbukkit.util.CraftVector.toBukkit(deltaMovement);
+
+ org.bukkit.event.player.PlayerVelocityEvent event = new org.bukkit.event.player.PlayerVelocityEvent(player, velocity.clone());
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+
+ if (!cancelled) {
((ServerPlayer)target).connection.send(new ClientboundSetEntityMotionPacket(target));
target.hurtMarked = false;
target.setDeltaMovement(deltaMovement);
+ }
+ // CraftBukkit end
}
if (flag2) {
- this.level()
- .playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F);
+ this.sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
this.crit(target);
}
if (!flag2 && !flag3) {
if (flag) {
- this.level()
- .playSound(
- null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F
+ this.sendSoundEffect(
+ this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F // Paper - send while respecting visibility
);
} else {
- this.level()
- .playSound(
- null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F
+ this.sendSoundEffect(
+ this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F // Paper - send while respecting visibility
);
}
}
@@ -1296,10 +_,14 @@
}
}
- this.causeFoodExhaustion(0.1F);
+ this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent // Spigot - Change to use configurable value
} else {
- this.level()
- .playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
+ this.sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
+ // CraftBukkit start - resync on cancelled event
+ if (this instanceof ServerPlayer) {
+ ((ServerPlayer) this).getBukkitEntity().updateInventory();
+ }
+ // CraftBukkit end
}
}
}
@@ -1316,8 +_,21 @@
this.attack(target);
}
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper - Add PlayerShieldDisableEvent
public void disableShield(ItemStack stack) {
- this.getCooldowns().addCooldown(stack, 100);
+ // Paper start - Add PlayerShieldDisableEvent
+ this.disableShield(stack, null);
+ }
+ public void disableShield(ItemStack stack, @Nullable LivingEntity attacker) {
+ final org.bukkit.entity.Entity finalAttacker = attacker != null ? attacker.getBukkitEntity() : null;
+ if (finalAttacker != null) {
+ final io.papermc.paper.event.player.PlayerShieldDisableEvent shieldDisableEvent = new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) getBukkitEntity(), finalAttacker, 100);
+ if (!shieldDisableEvent.callEvent()) return;
+ this.getCooldowns().addCooldown(stack, shieldDisableEvent.getCooldown());
+ } else {
+ this.getCooldowns().addCooldown(stack, 100);
+ }
+ // Paper end - Add PlayerShieldDisableEvent
this.stopUsingItem();
this.level().broadcastEntityEvent(this, (byte)30);
}
@@ -1341,7 +_,14 @@
@Override
public void remove(Entity.RemovalReason reason) {
- super.remove(reason);
+ // CraftBukkit start - add Bukkit remove cause
+ this.remove(reason, null);
+ }
+
+ @Override
+ public void remove(Entity.RemovalReason entity_removalreason, org.bukkit.event.entity.EntityRemoveEvent.Cause cause) {
+ super.remove(entity_removalreason, cause);
+ // CraftBukkit end
this.inventoryMenu.removed(this);
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
@@ -1381,6 +_,12 @@
}
public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos bedPos) {
+ // CraftBukkit start
+ return this.startSleepInBed(bedPos, false);
+ }
+
+ public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos bedPos, boolean force) {
+ // CraftBukkit end
this.startSleeping(bedPos);
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
@@ -1492,7 +_,7 @@
@Override
public boolean causeFallDamage(float fallDistance, float multiplier, DamageSource source) {
- if (this.abilities.mayfly) {
+ if (this.abilities.mayfly && !this.flyingFallDamage.toBooleanOrElse(false)) { // Paper - flying fall damage
return false;
} else {
if (fallDistance >= 2.0F) {
@@ -1532,12 +_,24 @@
}
public void startFallFlying() {
- this.setSharedFlag(7, true);
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, true).isCancelled()) {
+ this.setSharedFlag(7, true);
+ } else {
+ // SPIGOT-5542: must toggle like below
+ this.setSharedFlag(7, true);
+ this.setSharedFlag(7, false);
+ }
+ // CraftBukkit end
}
public void stopFallFlying() {
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) {
this.setSharedFlag(7, true);
this.setSharedFlag(7, false);
+ }
+ // CraftBukkit end
}
@Override
@@ -1643,15 +_,35 @@
public int getXpNeededForNextLevel() {
if (this.experienceLevel >= 30) {
return 112 + (this.experienceLevel - 30) * 9;
- } else {
+ } else { // Paper - diff on change; calculateTotalExperiencePoints
return this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2;
}
}
+ // Paper start - send while respecting visibility
+ private static void sendSoundEffect(Player fromEntity, double x, double y, double z, SoundEvent soundEffect, SoundSource soundCategory, float volume, float pitch) {
+ fromEntity.level().playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity itself
+ if (fromEntity instanceof ServerPlayer serverPlayer) {
+ serverPlayer.connection.send(new net.minecraft.network.protocol.game.ClientboundSoundPacket(net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.wrapAsHolder(soundEffect), soundCategory, x, y, z, volume, pitch, fromEntity.random.nextLong()));
+ }
+ }
+ // Paper end - send while respecting visibility
+
public void causeFoodExhaustion(float exhaustion) {
+ // CraftBukkit start
+ this.causeFoodExhaustion(exhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.UNKNOWN);
+ }
+
+ public void causeFoodExhaustion(float exhaustion, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason reason) {
+ // CraftBukkit end
if (!this.abilities.invulnerable) {
if (!this.level().isClientSide) {
- this.foodData.addExhaustion(exhaustion);
+ // CraftBukkit start
+ org.bukkit.event.entity.EntityExhaustionEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerExhaustionEvent(this, reason, exhaustion);
+ if (!event.isCancelled()) {
+ this.foodData.addExhaustion(event.getExhaustion());
+ }
+ // CraftBukkit end
}
}
}
@@ -1736,13 +_,20 @@
@Override
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
+ // CraftBukkit start
+ this.setItemSlot(slot, stack, false);
+ }
+
+ @Override
+ public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) {
+ // CraftBukkit end
this.verifyEquippedItem(stack);
if (slot == EquipmentSlot.MAINHAND) {
- this.onEquipItem(slot, this.inventory.items.set(this.inventory.selected, stack), stack);
+ this.onEquipItem(slot, this.inventory.items.set(this.inventory.selected, stack), stack, silent); // CraftBukkit
} else if (slot == EquipmentSlot.OFFHAND) {
- this.onEquipItem(slot, this.inventory.offhand.set(0, stack), stack);
+ this.onEquipItem(slot, this.inventory.offhand.set(0, stack), stack, silent); // CraftBukkit
} else if (slot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
- this.onEquipItem(slot, this.inventory.armor.set(slot.getIndex(), stack), stack);
+ this.onEquipItem(slot, this.inventory.armor.set(slot.getIndex(), stack), stack, silent); // CraftBukkit
}
}
@@ -1783,24 +_,53 @@
public void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
- this.respawnEntityOnShoulder(this.getShoulderEntityLeft());
+ // CraftBukkit start
+ if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) {
+ this.setShoulderEntityLeft(new CompoundTag());
+ }
+ if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) {
+ this.setShoulderEntityRight(new CompoundTag());
+ }
+ // CraftBukkit end
+ }
+ }
+
+ // Paper start - release entity api
+ public Entity releaseLeftShoulderEntity() {
+ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityLeft());
+ if (entity != null) {
this.setShoulderEntityLeft(new CompoundTag());
- this.respawnEntityOnShoulder(this.getShoulderEntityRight());
+ }
+ return entity;
+ }
+
+ public Entity releaseRightShoulderEntity() {
+ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityRight());
+ if (entity != null) {
this.setShoulderEntityRight(new CompoundTag());
}
+ return entity;
}
+ // Paper end - release entity api
- private void respawnEntityOnShoulder(CompoundTag entityCompound) {
+ private boolean respawnEntityOnShoulder(CompoundTag entityCompound) { // CraftBukkit void->boolean
+ // Paper start - release entity api - return entity - overload
+ return this.respawnEntityOnShoulder0(entityCompound) != null;
+ }
+ @Nullable
+ private Entity respawnEntityOnShoulder0(CompoundTag entityCompound) { // CraftBukkit void->boolean
+ // Paper end - release entity api - return entity - overload
if (!this.level().isClientSide && !entityCompound.isEmpty()) {
- EntityType.create(entityCompound, this.level(), EntitySpawnReason.LOAD).ifPresent(entity -> {
+ return EntityType.create(entityCompound, this.level(), EntitySpawnReason.LOAD).map((entity) -> { // CraftBukkit
if (entity instanceof TamableAnimal) {
((TamableAnimal)entity).setOwnerUUID(this.uuid);
}
entity.setPos(this.getX(), this.getY() + 0.7F, this.getZ());
- ((ServerLevel)this.level()).addWithUUID(entity);
- });
+ return ((ServerLevel)this.level()).addWithUUID(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY) ? entity : null; // CraftBukkit // Paper start - release entity api - return entity
+ }).orElse(null); // CraftBukkit // Paper end - release entity api - return entity
}
+ return null; // Paper - return null
}
@Override
@@ -1988,17 +_,28 @@
return ImmutableList.of(Pose.STANDING, Pose.CROUCHING, Pose.SWIMMING);
}
+ // Paper start - PlayerReadyArrowEvent
+ protected boolean tryReadyArrow(ItemStack bow, ItemStack itemstack) {
+ return !(this instanceof ServerPlayer) ||
+ new com.destroystokyo.paper.event.player.PlayerReadyArrowEvent(
+ ((ServerPlayer) this).getBukkitEntity(),
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(bow),
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)
+ ).callEvent();
+ }
+ // Paper end - PlayerReadyArrowEvent
+
@Override
public ItemStack getProjectile(ItemStack shootable) {
if (!(shootable.getItem() instanceof ProjectileWeaponItem)) {
return ItemStack.EMPTY;
} else {
- Predicate<ItemStack> supportedHeldProjectiles = ((ProjectileWeaponItem)shootable.getItem()).getSupportedHeldProjectiles();
+ Predicate<ItemStack> supportedHeldProjectiles = ((ProjectileWeaponItem)shootable.getItem()).getSupportedHeldProjectiles().and(item -> this.tryReadyArrow(shootable, item)); // Paper - PlayerReadyArrowEvent
ItemStack heldProjectile = ProjectileWeaponItem.getHeldProjectile(this, supportedHeldProjectiles);
if (!heldProjectile.isEmpty()) {
return heldProjectile;
} else {
- supportedHeldProjectiles = ((ProjectileWeaponItem)shootable.getItem()).getAllSupportedProjectiles();
+ supportedHeldProjectiles = ((ProjectileWeaponItem)shootable.getItem()).getAllSupportedProjectiles().and(item -> this.tryReadyArrow(shootable, item)); // Paper - PlayerReadyArrowEvent
for (int i = 0; i < this.inventory.getContainerSize(); i++) {
ItemStack item = this.inventory.getItem(i);

View file

@ -1,27 +1,27 @@
--- a/net/minecraft/world/entity/player/ProfilePublicKey.java --- a/net/minecraft/world/entity/player/ProfilePublicKey.java
+++ b/net/minecraft/world/entity/player/ProfilePublicKey.java +++ b/net/minecraft/world/entity/player/ProfilePublicKey.java
@@ -24,7 +24,7 @@ @@ -24,7 +_,7 @@
public static ProfilePublicKey createValidated(SignatureValidator servicesSignatureVerifier, UUID playerUuid, ProfilePublicKey.Data publicKeyData) throws ProfilePublicKey.ValidationException { public static ProfilePublicKey createValidated(SignatureValidator signatureValidator, UUID profileId, ProfilePublicKey.Data data) throws ProfilePublicKey.ValidationException {
if (!publicKeyData.validateSignature(servicesSignatureVerifier, playerUuid)) { if (!data.validateSignature(signatureValidator, profileId)) {
- throw new ProfilePublicKey.ValidationException(INVALID_SIGNATURE); - throw new ProfilePublicKey.ValidationException(INVALID_SIGNATURE);
+ throw new ProfilePublicKey.ValidationException(INVALID_SIGNATURE, org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PUBLIC_KEY_SIGNATURE); // Paper - kick event causes + throw new ProfilePublicKey.ValidationException(INVALID_SIGNATURE, org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PUBLIC_KEY_SIGNATURE); // Paper - kick event causes
} else { } else {
return new ProfilePublicKey(publicKeyData); return new ProfilePublicKey(data);
} }
@@ -88,8 +88,16 @@ @@ -88,8 +_,16 @@
} }
public static class ValidationException extends ThrowingComponent { public static class ValidationException extends ThrowingComponent {
+ public final org.bukkit.event.player.PlayerKickEvent.Cause kickCause; // Paper + public final org.bukkit.event.player.PlayerKickEvent.Cause kickCause; // Paper
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper + @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper
public ValidationException(Component messageText) { public ValidationException(Component component) {
+ // Paper start + // Paper start
+ this(messageText, org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN); + this(component, org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN);
+ } + }
+ public ValidationException(Component messageText, org.bukkit.event.player.PlayerKickEvent.Cause kickCause) { + public ValidationException(Component component, org.bukkit.event.player.PlayerKickEvent.Cause kickCause) {
+ // Paper end + // Paper end
super(messageText); super(component);
+ this.kickCause = kickCause; // Paper + this.kickCause = kickCause; // Paper
} }
} }

View file

@ -1,735 +0,0 @@
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -118,6 +118,15 @@
import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Scoreboard;
import org.slf4j.Logger;
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.util.CraftVector;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityExhaustionEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.player.PlayerVelocityEvent;
+// CraftBukkit end
public abstract class Player extends LivingEntity {
@@ -139,7 +148,8 @@
private static final int CURRENT_IMPULSE_CONTEXT_RESET_GRACE_TIME_TICKS = 40;
public static final Vec3 DEFAULT_VEHICLE_ATTACHMENT = new Vec3(0.0D, 0.6D, 0.0D);
public static final EntityDimensions STANDING_DIMENSIONS = EntityDimensions.scalable(0.6F, 1.8F).withEyeHeight(1.62F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, Player.DEFAULT_VEHICLE_ATTACHMENT));
- private static final Map<Pose, EntityDimensions> POSES = ImmutableMap.builder().put(Pose.STANDING, Player.STANDING_DIMENSIONS).put(Pose.SLEEPING, Player.SLEEPING_DIMENSIONS).put(Pose.FALL_FLYING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(Pose.SWIMMING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(Pose.SPIN_ATTACK, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(Pose.CROUCHING, EntityDimensions.scalable(0.6F, 1.5F).withEyeHeight(1.27F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, Player.DEFAULT_VEHICLE_ATTACHMENT))).put(Pose.DYING, EntityDimensions.fixed(0.2F, 0.2F).withEyeHeight(1.62F)).build();
+ // CraftBukkit - decompile error
+ private static final Map<Pose, EntityDimensions> POSES = ImmutableMap.<Pose, EntityDimensions>builder().put(Pose.STANDING, Player.STANDING_DIMENSIONS).put(Pose.SLEEPING, Player.SLEEPING_DIMENSIONS).put(Pose.FALL_FLYING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(Pose.SWIMMING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(Pose.SPIN_ATTACK, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(Pose.CROUCHING, EntityDimensions.scalable(0.6F, 1.5F).withEyeHeight(1.27F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, Player.DEFAULT_VEHICLE_ATTACHMENT))).put(Pose.DYING, EntityDimensions.fixed(0.2F, 0.2F).withEyeHeight(1.62F)).build();
private static final EntityDataAccessor<Float> DATA_PLAYER_ABSORPTION_ID = SynchedEntityData.defineId(Player.class, EntityDataSerializers.FLOAT);
private static final EntityDataAccessor<Integer> DATA_SCORE_ID = SynchedEntityData.defineId(Player.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Byte> DATA_PLAYER_MODE_CUSTOMISATION = SynchedEntityData.defineId(Player.class, EntityDataSerializers.BYTE);
@@ -149,7 +159,7 @@
public static final int CLIENT_LOADED_TIMEOUT_TIME = 60;
private long timeEntitySatOnShoulder;
final Inventory inventory = new Inventory(this);
- protected PlayerEnderChestContainer enderChestInventory = new PlayerEnderChestContainer();
+ protected PlayerEnderChestContainer enderChestInventory = new PlayerEnderChestContainer(this); // CraftBukkit - add "this" to constructor
public final InventoryMenu inventoryMenu;
public AbstractContainerMenu containerMenu;
protected FoodData foodData = new FoodData();
@@ -181,13 +191,25 @@
private Optional<GlobalPos> lastDeathLocation;
@Nullable
public FishingHook fishing;
- protected float hurtDir;
+ public float hurtDir; // Paper - protected -> public
@Nullable
public Vec3 currentImpulseImpactPos;
@Nullable
public Entity currentExplosionCause;
private boolean ignoreFallDamageFromCurrentImpulse;
private int currentImpulseContextResetGraceTime;
+ public boolean affectsSpawning = true; // Paper - Affects Spawning API
+ public net.kyori.adventure.util.TriState flyingFallDamage = net.kyori.adventure.util.TriState.NOT_SET; // Paper - flying fall damage
+
+ // CraftBukkit start
+ public boolean fauxSleeping;
+ public int oldLevel = -1;
+
+ @Override
+ public CraftHumanEntity getBukkitEntity() {
+ return (CraftHumanEntity) super.getBukkitEntity();
+ }
+ // CraftBukkit end
public Player(Level world, BlockPos pos, float yaw, GameProfile gameProfile) {
super(EntityType.PLAYER, world);
@@ -244,6 +266,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 +290,7 @@
this.updateIsUnderwater();
super.tick();
if (!this.level().isClientSide && this.containerMenu != null && !this.containerMenu.stillValid(this)) {
- this.closeContainer();
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper - Inventory close reason
this.containerMenu = this.inventoryMenu;
}
@@ -353,7 +382,7 @@
}
private void turtleHelmetTick() {
- this.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
+ this.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit
}
private boolean isEquipped(Item item) {
@@ -511,7 +540,19 @@
super.handleEntityEvent(status);
}
+ }
+
+ // Paper start - Inventory close reason; unused code, but to keep signatures aligned
+ public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ closeContainer();
+ this.containerMenu = this.inventoryMenu;
+ }
+ // Paper end - Inventory close reason
+ // Paper start - special close for unloaded inventory
+ public void closeUnloadedInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ this.containerMenu = this.inventoryMenu;
}
+ // Paper end - special close for unloaded inventory
public void closeContainer() {
this.containerMenu = this.inventoryMenu;
@@ -523,8 +564,14 @@
public void rideTick() {
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
this.stopRiding();
- this.setShiftKeyDown(false);
- } else {
+ // CraftBukkit start - SPIGOT-7316: no longer passenger, dismount and return
+ if (!this.isPassenger()) {
+ this.setShiftKeyDown(false);
+ return;
+ }
+ }
+ {
+ // CraftBukkit end
super.rideTick();
this.oBob = this.bob;
this.bob = 0.0F;
@@ -593,6 +640,7 @@
this.playShoulderEntityAmbientSound(this.getShoulderEntityLeft());
this.playShoulderEntityAmbientSound(this.getShoulderEntityRight());
if (!this.level().isClientSide && (this.fallDistance > 0.5F || this.isInWater()) || this.abilities.flying || this.isSleeping() || this.isInPowderSnow) {
+ if (!this.level().paperConfig().entities.behavior.parrotsAreUnaffectedByPlayerMovement) // Paper - Add option to make parrots stay
this.removeEntitiesOnShoulder();
}
@@ -719,7 +767,14 @@
@Nullable
public ItemEntity drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership) {
- if (!stack.isEmpty() && this.level().isClientSide) {
+ // CraftBukkit start - SPIGOT-2942: Add boolean to call event
+ return this.drop(stack, throwRandomly, retainOwnership, true);
+ }
+
+ @Nullable
+ public ItemEntity drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) {
+ // CraftBukkit end
+ if (!itemstack.isEmpty() && this.level().isClientSide) {
this.swing(InteractionHand.MAIN_HAND);
}
@@ -809,7 +864,7 @@
}
if (nbt.contains("LastDeathLocation", 10)) {
- DataResult dataresult = GlobalPos.CODEC.parse(NbtOps.INSTANCE, nbt.get("LastDeathLocation"));
+ DataResult<GlobalPos> dataresult = GlobalPos.CODEC.parse(NbtOps.INSTANCE, nbt.get("LastDeathLocation")); // CraftBukkit - decompile error
Logger logger = Player.LOGGER;
Objects.requireNonNull(logger);
@@ -817,7 +872,7 @@
}
if (nbt.contains("current_explosion_impact_pos", 9)) {
- DataResult dataresult1 = Vec3.CODEC.parse(NbtOps.INSTANCE, nbt.get("current_explosion_impact_pos"));
+ DataResult<Vec3> dataresult1 = Vec3.CODEC.parse(NbtOps.INSTANCE, nbt.get("current_explosion_impact_pos")); // CraftBukkit - decompile error
Logger logger1 = Player.LOGGER;
Objects.requireNonNull(logger1);
@@ -854,7 +909,7 @@
}
this.getLastDeathLocation().flatMap((globalpos) -> {
- DataResult dataresult = GlobalPos.CODEC.encodeStart(NbtOps.INSTANCE, globalpos);
+ DataResult<Tag> dataresult = GlobalPos.CODEC.encodeStart(NbtOps.INSTANCE, globalpos); // CraftBukkit - decompile error
Logger logger = Player.LOGGER;
Objects.requireNonNull(logger);
@@ -886,10 +941,10 @@
if (this.isDeadOrDying()) {
return false;
} else {
- this.removeEntitiesOnShoulder();
+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
if (source.scalesWithDifficulty()) {
if (world.getDifficulty() == Difficulty.PEACEFUL) {
- amount = 0.0F;
+ return false; // CraftBukkit - f = 0.0f -> return false
}
if (world.getDifficulty() == Difficulty.EASY) {
@@ -901,7 +956,13 @@
}
}
- return amount == 0.0F ? false : super.hurtServer(world, source, amount);
+ // CraftBukkit start - Don't filter out 0 damage
+ boolean damaged = super.hurtServer(world, source, amount);
+ if (damaged) {
+ this.removeEntitiesOnShoulder();
+ }
+ return damaged;
+ // CraftBukkit end
}
}
}
@@ -912,7 +973,7 @@
ItemStack itemstack = this.getItemBlockingWith();
if (attacker.canDisableShield() && itemstack != null) {
- this.disableShield(itemstack);
+ this.disableShield(itemstack, attacker); // Paper - Add PlayerShieldDisableEvent
}
}
@@ -923,10 +984,29 @@
}
public boolean canHarmPlayer(Player player) {
- PlayerTeam scoreboardteam = this.getTeam();
- PlayerTeam scoreboardteam1 = player.getTeam();
+ // CraftBukkit start - Change to check OTHER player's scoreboard team according to API
+ // To summarize this method's logic, it's "Can parameter hurt this"
+ org.bukkit.scoreboard.Team team;
+ if (player instanceof ServerPlayer) {
+ ServerPlayer thatPlayer = (ServerPlayer) player;
+ team = thatPlayer.getBukkitEntity().getScoreboard().getPlayerTeam(thatPlayer.getBukkitEntity());
+ if (team == null || team.allowFriendlyFire()) {
+ return true;
+ }
+ } else {
+ // This should never be called, but is implemented anyway
+ org.bukkit.OfflinePlayer thisPlayer = player.level().getCraftServer().getOfflinePlayer(player.getScoreboardName());
+ team = player.level().getCraftServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
+ if (team == null || team.allowFriendlyFire()) {
+ return true;
+ }
+ }
- return scoreboardteam == null ? true : (!scoreboardteam.isAlliedTo(scoreboardteam1) ? true : scoreboardteam.isAllowFriendlyFire());
+ if (this instanceof ServerPlayer) {
+ return !team.hasPlayer(((ServerPlayer) this).getBukkitEntity());
+ }
+ return !team.hasPlayer(this.level().getCraftServer().getOfflinePlayer(this.getScoreboardName()));
+ // CraftBukkit end
}
@Override
@@ -966,32 +1046,38 @@
}
}
+ // CraftBukkit start
@Override
- protected void actuallyHurt(ServerLevel world, DamageSource source, float amount) {
- if (!this.isInvulnerableTo(world, source)) {
- amount = this.getDamageAfterArmorAbsorb(source, amount);
- amount = this.getDamageAfterMagicAbsorb(source, amount);
- float f1 = amount;
+ protected boolean actuallyHurt(ServerLevel worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { // void -> boolean
+ if (true) {
+ return super.actuallyHurt(worldserver, damagesource, f, event);
+ }
+ // CraftBukkit end
+ if (!this.isInvulnerableTo(worldserver, damagesource)) {
+ f = this.getDamageAfterArmorAbsorb(damagesource, f);
+ f = this.getDamageAfterMagicAbsorb(damagesource, f);
+ float f1 = f;
- amount = Math.max(amount - this.getAbsorptionAmount(), 0.0F);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (f1 - amount));
- float f2 = f1 - amount;
+ f = Math.max(f - this.getAbsorptionAmount(), 0.0F);
+ this.setAbsorptionAmount(this.getAbsorptionAmount() - (f1 - f));
+ float f2 = f1 - f;
if (f2 > 0.0F && f2 < 3.4028235E37F) {
this.awardStat(Stats.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
}
- if (amount != 0.0F) {
- this.causeFoodExhaustion(source.getFoodExhaustion());
- this.getCombatTracker().recordDamage(source, amount);
- this.setHealth(this.getHealth() - amount);
- if (amount < 3.4028235E37F) {
- this.awardStat(Stats.DAMAGE_TAKEN, Math.round(amount * 10.0F));
+ if (f != 0.0F) {
+ this.causeFoodExhaustion(damagesource.getFoodExhaustion(), EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
+ this.getCombatTracker().recordDamage(damagesource, f);
+ this.setHealth(this.getHealth() - f);
+ if (f < 3.4028235E37F) {
+ this.awardStat(Stats.DAMAGE_TAKEN, Math.round(f * 10.0F));
}
this.gameEvent(GameEvent.ENTITY_DAMAGE);
}
}
+ return false; // CraftBukkit
}
public boolean isTextFilteringEnabled() {
@@ -1061,13 +1147,19 @@
@Override
public void removeVehicle() {
- super.removeVehicle();
+ // Paper start - Force entity dismount during teleportation
+ this.removeVehicle(false);
+ }
+ @Override
+ public void removeVehicle(boolean suppressCancellation) {
+ super.removeVehicle(suppressCancellation);
+ // Paper end - Force entity dismount during teleportation
this.boardingCooldown = 0;
}
@Override
protected boolean isImmobile() {
- return super.isImmobile() || this.isSleeping();
+ return super.isImmobile() || this.isSleeping() || this.isRemoved() || !valid; // Paper - player's who are dead or not in a world shouldn't move...
}
@Override
@@ -1134,8 +1226,17 @@
}
public void attack(Entity target) {
- if (target.isAttackable()) {
- if (!target.skipAttackInteraction(this)) {
+ // Paper start - PlayerAttackEntityEvent
+ boolean willAttack = target.isAttackable() && !target.skipAttackInteraction(this); // Vanilla logic
+ io.papermc.paper.event.player.PrePlayerAttackEntityEvent playerAttackEntityEvent = new io.papermc.paper.event.player.PrePlayerAttackEntityEvent(
+ (org.bukkit.entity.Player) this.getBukkitEntity(),
+ target.getBukkitEntity(),
+ willAttack
+ );
+
+ if (playerAttackEntityEvent.callEvent() && willAttack) { // Logic moved to willAttack local variable.
+ {
+ // Paper end - PlayerAttackEntityEvent
float f = this.isAutoSpinAttack() ? this.autoSpinAttackDmg : (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE);
ItemStack itemstack = this.getWeaponItem();
DamageSource damagesource = (DamageSource) Optional.ofNullable(itemstack.getItem().getDamageSource(this)).orElse(this.damageSources().playerAttack(this));
@@ -1144,10 +1245,15 @@
f *= 0.2F + f2 * f2 * 0.8F;
f1 *= f2;
- this.resetAttackStrengthTicker();
+ // this.resetAttackStrengthTicker(); // CraftBukkit - Moved to EntityLiving to reset the cooldown after the damage is dealt
if (target.getType().is(EntityTypeTags.REDIRECTABLE_PROJECTILE) && target instanceof Projectile) {
Projectile iprojectile = (Projectile) target;
+ // CraftBukkit start
+ if (CraftEventFactory.handleNonLivingEntityDamageEvent(target, damagesource, f1, false)) {
+ return;
+ }
+ // CraftBukkit end
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());
return;
@@ -1159,7 +1265,7 @@
boolean flag1;
if (this.isSprinting() && flag) {
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
flag1 = true;
} else {
flag1 = false;
@@ -1168,7 +1274,9 @@
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();
+ flag2 = flag2 && !this.level().paperConfig().entities.behavior.disablePlayerCrits; // Paper - Toggleable player crits
if (flag2) {
+ damagesource = damagesource.critical(true); // Paper start - critical damage API
f *= 1.5F;
}
@@ -1202,13 +1310,17 @@
if (target instanceof LivingEntity) {
LivingEntity entityliving1 = (LivingEntity) target;
- entityliving1.knockback((double) (f5 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
+ entityliving1.knockback((double) (f5 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // Paper - knockback events
} else {
- target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * f5 * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * f5 * 0.5F));
+ target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * f5 * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * f5 * 0.5F), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
}
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
+ // Paper start - Configurable sprint interruption on attack
+ if (!this.level().paperConfig().misc.disableSprintInterruptionOnAttack) {
this.setSprinting(false);
+ }
+ // Paper end - Configurable sprint interruption on attack
}
LivingEntity entityliving2;
@@ -1223,8 +1335,13 @@
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;
- entityliving2.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
- entityliving2.hurt(damagesource, f7);
+ // CraftBukkit start - Only apply knockback if the damage hits
+ if (!entityliving2.hurtServer((ServerLevel) this.level(), this.damageSources().playerAttack(this).sweep().critical(flag2), f7)) { // Paper - add critical damage API
+ continue;
+ }
+ // CraftBukkit end
+ entityliving2.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.SWEEP_ATTACK); // CraftBukkit // Paper - knockback events
+ // entityliving2.hurt(damagesource, f7); // CraftBukkit - moved up
Level world = this.level();
if (world instanceof ServerLevel) {
@@ -1235,26 +1352,43 @@
}
}
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
this.sweepAttack();
}
if (target instanceof ServerPlayer && target.hurtMarked) {
+ // CraftBukkit start - Add Velocity Event
+ boolean cancelled = false;
+ org.bukkit.entity.Player player = (org.bukkit.entity.Player) target.getBukkitEntity();
+ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d);
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+
+ if (!cancelled) {
((ServerPlayer) target).connection.send(new ClientboundSetEntityMotionPacket(target));
target.hurtMarked = false;
target.setDeltaMovement(vec3d);
+ }
+ // CraftBukkit end
}
if (flag2) {
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
this.crit(target);
}
if (!flag2 && !flag3) {
if (flag) {
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
} else {
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
}
}
@@ -1308,9 +1442,14 @@
}
}
- this.causeFoodExhaustion(0.1F);
+ this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent // Spigot - Change to use configurable value
} else {
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
+ // CraftBukkit start - resync on cancelled event
+ if (this instanceof ServerPlayer) {
+ ((ServerPlayer) this).getBukkitEntity().updateInventory();
+ }
+ // CraftBukkit end
}
}
@@ -1327,8 +1466,21 @@
this.attack(target);
}
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper - Add PlayerShieldDisableEvent
public void disableShield(ItemStack shield) {
- this.getCooldowns().addCooldown(shield, 100);
+ // Paper start - Add PlayerShieldDisableEvent
+ this.disableShield(shield, null);
+ }
+ public void disableShield(ItemStack shield, @Nullable LivingEntity attacker) {
+ final org.bukkit.entity.Entity finalAttacker = attacker != null ? attacker.getBukkitEntity() : null;
+ if (finalAttacker != null) {
+ final io.papermc.paper.event.player.PlayerShieldDisableEvent shieldDisableEvent = new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) getBukkitEntity(), finalAttacker, 100);
+ if (!shieldDisableEvent.callEvent()) return;
+ this.getCooldowns().addCooldown(shield, shieldDisableEvent.getCooldown());
+ } else {
+ this.getCooldowns().addCooldown(shield, 100);
+ }
+ // Paper end - Add PlayerShieldDisableEvent
this.stopUsingItem();
this.level().broadcastEntityEvent(this, (byte) 30);
}
@@ -1351,7 +1503,14 @@
@Override
public void remove(Entity.RemovalReason reason) {
- super.remove(reason);
+ // CraftBukkit start - add Bukkit remove cause
+ this.remove(reason, null);
+ }
+
+ @Override
+ public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) {
+ super.remove(entity_removalreason, cause);
+ // CraftBukkit end
this.inventoryMenu.removed(this);
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
@@ -1391,7 +1550,13 @@
}
public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos pos) {
- this.startSleeping(pos);
+ // CraftBukkit start
+ return this.startSleepInBed(pos, false);
+ }
+
+ public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos blockposition, boolean force) {
+ // CraftBukkit end
+ this.startSleeping(blockposition);
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
}
@@ -1503,7 +1668,7 @@
@Override
public boolean causeFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) {
- if (this.abilities.mayfly) {
+ if (this.abilities.mayfly && !this.flyingFallDamage.toBooleanOrElse(false)) { // Paper - flying fall damage
return false;
} else {
if (fallDistance >= 2.0F) {
@@ -1545,12 +1710,24 @@
}
public void startFallFlying() {
- this.setSharedFlag(7, true);
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, true).isCancelled()) {
+ this.setSharedFlag(7, true);
+ } else {
+ // SPIGOT-5542: must toggle like below
+ this.setSharedFlag(7, true);
+ this.setSharedFlag(7, false);
+ }
+ // CraftBukkit end
}
public void stopFallFlying() {
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) {
this.setSharedFlag(7, true);
this.setSharedFlag(7, false);
+ }
+ // CraftBukkit end
}
@Override
@@ -1662,13 +1839,32 @@
}
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); // Paper - diff on change; calculateTotalExperiencePoints
+ }
+ // Paper start - send while respecting visibility
+ private static void sendSoundEffect(Player fromEntity, double x, double y, double z, SoundEvent soundEffect, SoundSource soundCategory, float volume, float pitch) {
+ fromEntity.level().playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity itself
+ if (fromEntity instanceof ServerPlayer serverPlayer) {
+ serverPlayer.connection.send(new net.minecraft.network.protocol.game.ClientboundSoundPacket(net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.wrapAsHolder(soundEffect), soundCategory, x, y, z, volume, pitch, fromEntity.random.nextLong()));
+ }
}
+ // Paper end - send while respecting visibility
+ // CraftBukkit start
public void causeFoodExhaustion(float exhaustion) {
+ this.causeFoodExhaustion(exhaustion, EntityExhaustionEvent.ExhaustionReason.UNKNOWN);
+ }
+
+ public void causeFoodExhaustion(float f, EntityExhaustionEvent.ExhaustionReason reason) {
+ // CraftBukkit end
if (!this.abilities.invulnerable) {
if (!this.level().isClientSide) {
- this.foodData.addExhaustion(exhaustion);
+ // CraftBukkit start
+ EntityExhaustionEvent event = CraftEventFactory.callPlayerExhaustionEvent(this, reason, f);
+ if (!event.isCancelled()) {
+ this.foodData.addExhaustion(event.getExhaustion());
+ }
+ // CraftBukkit end
}
}
@@ -1748,13 +1944,20 @@
@Override
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
- this.verifyEquippedItem(stack);
- if (slot == EquipmentSlot.MAINHAND) {
- this.onEquipItem(slot, (ItemStack) this.inventory.items.set(this.inventory.selected, stack), stack);
- } else if (slot == EquipmentSlot.OFFHAND) {
- this.onEquipItem(slot, (ItemStack) this.inventory.offhand.set(0, stack), stack);
- } else if (slot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
- this.onEquipItem(slot, (ItemStack) this.inventory.armor.set(slot.getIndex(), stack), stack);
+ // CraftBukkit start
+ this.setItemSlot(slot, stack, false);
+ }
+
+ @Override
+ public void setItemSlot(EquipmentSlot enumitemslot, ItemStack itemstack, boolean silent) {
+ // CraftBukkit end
+ this.verifyEquippedItem(itemstack);
+ if (enumitemslot == EquipmentSlot.MAINHAND) {
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.items.set(this.inventory.selected, itemstack), itemstack, silent); // CraftBukkit
+ } else if (enumitemslot == EquipmentSlot.OFFHAND) {
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.offhand.set(0, itemstack), itemstack, silent); // CraftBukkit
+ } else if (enumitemslot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.armor.set(enumitemslot.getIndex(), itemstack), itemstack, silent); // CraftBukkit
}
}
@@ -1798,26 +2001,55 @@
public void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
- this.respawnEntityOnShoulder(this.getShoulderEntityLeft());
+ // CraftBukkit start
+ if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) {
+ this.setShoulderEntityLeft(new CompoundTag());
+ }
+ if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) {
+ this.setShoulderEntityRight(new CompoundTag());
+ }
+ // CraftBukkit end
+ }
+
+ }
+
+ // Paper start - release entity api
+ public Entity releaseLeftShoulderEntity() {
+ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityLeft());
+ if (entity != null) {
this.setShoulderEntityLeft(new CompoundTag());
- this.respawnEntityOnShoulder(this.getShoulderEntityRight());
+ }
+ return entity;
+ }
+
+ public Entity releaseRightShoulderEntity() {
+ Entity entity = this.respawnEntityOnShoulder0(this.getShoulderEntityRight());
+ if (entity != null) {
this.setShoulderEntityRight(new CompoundTag());
}
+ return entity;
+ }
+ // Paper end - release entity api
+ private boolean respawnEntityOnShoulder(CompoundTag nbttagcompound) { // CraftBukkit void->boolean
+ // Paper start - release entity api - return entity - overload
+ return this.respawnEntityOnShoulder0(nbttagcompound) != null;
}
- private void respawnEntityOnShoulder(CompoundTag entityNbt) {
- if (!this.level().isClientSide && !entityNbt.isEmpty()) {
- EntityType.create(entityNbt, this.level(), EntitySpawnReason.LOAD).ifPresent((entity) -> {
+ private Entity respawnEntityOnShoulder0(CompoundTag nbttagcompound) { // CraftBukkit void->boolean
+ // Paper end - release entity api - return entity - overload
+ if (!this.level().isClientSide && !nbttagcompound.isEmpty()) {
+ return EntityType.create(nbttagcompound, this.level(), EntitySpawnReason.LOAD).map((entity) -> { // CraftBukkit
if (entity instanceof TamableAnimal) {
((TamableAnimal) entity).setOwnerUUID(this.uuid);
}
entity.setPos(this.getX(), this.getY() + 0.699999988079071D, this.getZ());
- ((ServerLevel) this.level()).addWithUUID(entity);
- });
+ return ((ServerLevel) this.level()).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY) ? entity : null; // CraftBukkit // Paper start - release entity api - return entity
+ }).orElse(null); // CraftBukkit // Paper end - release entity api - return entity
}
+ return null; // Paper - return null
}
@Override
@@ -2003,20 +2235,31 @@
@Override
public ImmutableList<Pose> getDismountPoses() {
return ImmutableList.of(Pose.STANDING, Pose.CROUCHING, Pose.SWIMMING);
+ }
+
+ // Paper start - PlayerReadyArrowEvent
+ protected boolean tryReadyArrow(ItemStack bow, ItemStack itemstack) {
+ return !(this instanceof ServerPlayer) ||
+ new com.destroystokyo.paper.event.player.PlayerReadyArrowEvent(
+ ((ServerPlayer) this).getBukkitEntity(),
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(bow),
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack)
+ ).callEvent();
}
+ // Paper end - PlayerReadyArrowEvent
@Override
public ItemStack getProjectile(ItemStack stack) {
if (!(stack.getItem() instanceof ProjectileWeaponItem)) {
return ItemStack.EMPTY;
} else {
- Predicate<ItemStack> predicate = ((ProjectileWeaponItem) stack.getItem()).getSupportedHeldProjectiles();
+ Predicate<ItemStack> predicate = ((ProjectileWeaponItem) stack.getItem()).getSupportedHeldProjectiles().and(item -> tryReadyArrow(stack, item)); // Paper - PlayerReadyArrowEvent
ItemStack itemstack1 = ProjectileWeaponItem.getHeldProjectile(this, predicate);
if (!itemstack1.isEmpty()) {
return itemstack1;
} else {
- predicate = ((ProjectileWeaponItem) stack.getItem()).getAllSupportedProjectiles();
+ predicate = ((ProjectileWeaponItem) stack.getItem()).getAllSupportedProjectiles().and(item -> tryReadyArrow(stack, item)); // Paper - PlayerReadyArrowEvent
for (int i = 0; i < this.inventory.getContainerSize(); ++i) {
ItemStack itemstack2 = this.inventory.getItem(i);