mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2025-10-20 03:54:00 +00:00
324 lines
14 KiB
Diff
324 lines
14 KiB
Diff
--- a/net/minecraft/world/entity/player/EntityHuman.java
|
|
+++ b/net/minecraft/world/entity/player/EntityHuman.java
|
|
@@ -119,6 +119,20 @@
|
|
import net.minecraft.world.scores.ScoreboardTeam;
|
|
import net.minecraft.world.scores.ScoreboardTeamBase;
|
|
|
|
+
|
|
+// CraftBukkit start
|
|
+import net.minecraft.nbt.NBTBase;
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.craftbukkit.util.CraftVector;
|
|
+import org.bukkit.entity.Player;
|
|
+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 EntityHuman extends Avatar implements ContainerUser {
|
|
|
|
public static final int MAX_HEALTH = 20;
|
|
@@ -145,7 +159,7 @@
|
|
private static final boolean DEFAULT_IGNORE_FALL_DAMAGE_FROM_CURRENT_IMPULSE = false;
|
|
private static final int DEFAULT_CURRENT_IMPULSE_CONTEXT_RESET_GRACE_TIME = 0;
|
|
final PlayerInventory inventory;
|
|
- protected InventoryEnderChest enderChestInventory = new InventoryEnderChest();
|
|
+ protected InventoryEnderChest enderChestInventory = new InventoryEnderChest(this); // CraftBukkit - add "this" to constructor
|
|
public final ContainerPlayer inventoryMenu;
|
|
public Container containerMenu;
|
|
protected FoodMetaData foodData = new FoodMetaData();
|
|
@@ -177,6 +191,16 @@
|
|
private boolean ignoreFallDamageFromCurrentImpulse;
|
|
private int currentImpulseContextResetGraceTime;
|
|
|
|
+ // CraftBukkit start
|
|
+ public boolean fauxSleeping;
|
|
+ public int oldLevel = -1;
|
|
+
|
|
+ @Override
|
|
+ public CraftHumanEntity getBukkitEntity() {
|
|
+ return (CraftHumanEntity) super.getBukkitEntity();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
public EntityHuman(World world, GameProfile gameprofile) {
|
|
super(EntityTypes.PLAYER, world);
|
|
this.lastItemInMainHand = ItemStack.EMPTY;
|
|
@@ -322,7 +346,7 @@
|
|
}
|
|
|
|
private void turtleHelmetTick() {
|
|
- this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
|
|
+ this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit
|
|
}
|
|
|
|
private boolean isEquipped(Item item) {
|
|
@@ -430,8 +454,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();
|
|
}
|
|
}
|
|
@@ -653,7 +683,7 @@
|
|
|
|
this.setScore(valueinput.getIntOr("Score", 0));
|
|
this.foodData.readAdditionalSaveData(valueinput);
|
|
- Optional optional = valueinput.read("abilities", PlayerAbilities.a.CODEC);
|
|
+ Optional<PlayerAbilities.a> optional = valueinput.read("abilities", PlayerAbilities.a.CODEC); // CraftBukkit - decompile error
|
|
PlayerAbilities playerabilities = this.abilities;
|
|
|
|
Objects.requireNonNull(this.abilities);
|
|
@@ -661,7 +691,7 @@
|
|
this.getAttribute(GenericAttributes.MOVEMENT_SPEED).setBaseValue((double) this.abilities.getWalkingSpeed());
|
|
this.enderChestInventory.fromSlots(valueinput.listOrEmpty("EnderItems", ItemStackWithSlot.CODEC));
|
|
this.setLastDeathLocation(valueinput.read("LastDeathLocation", GlobalPos.CODEC));
|
|
- this.currentImpulseImpactPos = (Vec3D) valueinput.read("current_explosion_impact_pos", Vec3D.CODEC).orElse((Object) null);
|
|
+ this.currentImpulseImpactPos = (Vec3D) valueinput.read("current_explosion_impact_pos", Vec3D.CODEC).orElse(null); // CraftBukkit - decompile error
|
|
this.ignoreFallDamageFromCurrentImpulse = valueinput.getBooleanOr("ignore_fall_damage_from_current_explosion", false);
|
|
this.currentImpulseContextResetGraceTime = valueinput.getIntOr("current_impulse_context_reset_grace_time", 0);
|
|
}
|
|
@@ -705,10 +735,10 @@
|
|
if (this.isDeadOrDying()) {
|
|
return false;
|
|
} else {
|
|
- this.removeEntitiesOnShoulder();
|
|
+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
|
|
if (damagesource.scalesWithDifficulty()) {
|
|
if (worldserver.getDifficulty() == EnumDifficulty.PEACEFUL) {
|
|
- f = 0.0F;
|
|
+ return false; // CraftBukkit - f = 0.0f -> return false
|
|
}
|
|
|
|
if (worldserver.getDifficulty() == EnumDifficulty.EASY) {
|
|
@@ -720,7 +750,13 @@
|
|
}
|
|
}
|
|
|
|
- return f == 0.0F ? false : super.hurtServer(worldserver, damagesource, f);
|
|
+ // CraftBukkit start - Don't filter out 0 damage
|
|
+ boolean damaged = super.hurtServer(worldserver, damagesource, f);
|
|
+ if (damaged) {
|
|
+ this.removeEntitiesOnShoulder();
|
|
+ }
|
|
+ return damaged;
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
}
|
|
@@ -744,10 +780,29 @@
|
|
}
|
|
|
|
public boolean canHarmPlayer(EntityHuman entityhuman) {
|
|
- ScoreboardTeamBase scoreboardteambase = this.getTeam();
|
|
- ScoreboardTeamBase scoreboardteambase1 = entityhuman.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 (entityhuman instanceof EntityPlayer) {
|
|
+ EntityPlayer thatPlayer = (EntityPlayer) entityhuman;
|
|
+ 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 = entityhuman.level().getCraftServer().getOfflinePlayer(entityhuman.getScoreboardName());
|
|
+ team = entityhuman.level().getCraftServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
|
|
+ if (team == null || team.allowFriendlyFire()) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
|
|
- return scoreboardteambase == null ? true : (!scoreboardteambase.isAlliedTo(scoreboardteambase1) ? true : scoreboardteambase.isAllowFriendlyFire());
|
|
+ if (this instanceof EntityPlayer) {
|
|
+ return !team.hasPlayer(((EntityPlayer) this).getBukkitEntity());
|
|
+ }
|
|
+ return !team.hasPlayer(this.level().getCraftServer().getOfflinePlayer(this.getScoreboardName()));
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
@Override
|
|
@@ -761,7 +816,12 @@
|
|
}
|
|
|
|
@Override
|
|
- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) {
|
|
+ // CraftBukkit start
|
|
+ protected boolean actuallyHurt(WorldServer 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);
|
|
@@ -776,7 +836,7 @@
|
|
}
|
|
|
|
if (f != 0.0F) {
|
|
- this.causeFoodExhaustion(damagesource.getFoodExhaustion());
|
|
+ this.causeFoodExhaustion(damagesource.getFoodExhaustion(), EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
|
|
this.getCombatTracker().recordDamage(damagesource, f);
|
|
this.setHealth(this.getHealth() - f);
|
|
if (f < 3.4028235E37F) {
|
|
@@ -786,6 +846,7 @@
|
|
this.gameEvent(GameEvent.ENTITY_DAMAGE);
|
|
}
|
|
}
|
|
+ return false; // CraftBukkit
|
|
}
|
|
|
|
public boolean isTextFilteringEnabled() {
|
|
@@ -944,10 +1005,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 (entity.getType().is(TagsEntity.REDIRECTABLE_PROJECTILE) && entity instanceof IProjectile) {
|
|
IProjectile iprojectile = (IProjectile) entity;
|
|
|
|
+ // CraftBukkit start
|
|
+ if (CraftEventFactory.handleNonLivingEntityDamageEvent(entity, damagesource, f1, false)) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
if (iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, EntityReference.of(this), true)) {
|
|
this.level().playSound((Entity) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource());
|
|
return;
|
|
@@ -1045,9 +1111,26 @@
|
|
}
|
|
|
|
if (entity instanceof EntityPlayer && entity.hurtMarked) {
|
|
+ // CraftBukkit start - Add Velocity Event
|
|
+ boolean cancelled = false;
|
|
+ Player player = (Player) entity.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) {
|
|
((EntityPlayer) entity).connection.send(new PacketPlayOutEntityVelocity(entity));
|
|
entity.hurtMarked = false;
|
|
entity.setDeltaMovement(vec3d);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
if (flag2) {
|
|
@@ -1114,9 +1197,14 @@
|
|
}
|
|
}
|
|
|
|
- this.causeFoodExhaustion(0.1F);
|
|
+ this.causeFoodExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent
|
|
} else {
|
|
this.level().playSound((Entity) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
|
|
+ // CraftBukkit start - resync on cancelled event
|
|
+ if (this instanceof EntityPlayer) {
|
|
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
}
|
|
|
|
@@ -1151,7 +1239,14 @@
|
|
|
|
@Override
|
|
public void remove(Entity.RemovalReason entity_removalreason) {
|
|
- super.remove(entity_removalreason);
|
|
+ // CraftBukkit start - add Bukkit remove cause
|
|
+ this.remove(entity_removalreason, 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.hasContainerOpen()) {
|
|
this.doCloseContainer();
|
|
@@ -1219,6 +1314,12 @@
|
|
}
|
|
|
|
public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition) {
|
|
+ // CraftBukkit start
|
|
+ return this.startSleepInBed(blockposition, false);
|
|
+ }
|
|
+
|
|
+ public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition, boolean force) {
|
|
+ // CraftBukkit end
|
|
this.startSleeping(blockposition);
|
|
this.sleepCounter = 0;
|
|
return Either.right(Unit.INSTANCE);
|
|
@@ -1373,7 +1474,15 @@
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
@Override
|
|
@@ -1488,10 +1597,21 @@
|
|
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
public void causeFoodExhaustion(float f) {
|
|
+ this.causeFoodExhaustion(f, EntityExhaustionEvent.ExhaustionReason.UNKNOWN);
|
|
+ }
|
|
+
|
|
+ public void causeFoodExhaustion(float f, EntityExhaustionEvent.ExhaustionReason reason) {
|
|
+ // CraftBukkit end
|
|
if (!this.abilities.invulnerable) {
|
|
if (!this.level().isClientSide()) {
|
|
- this.foodData.addExhaustion(f);
|
|
+ // CraftBukkit start
|
|
+ EntityExhaustionEvent event = CraftEventFactory.callPlayerExhaustionEvent(this, reason, f);
|
|
+ if (!event.isCancelled()) {
|
|
+ this.foodData.addExhaustion(event.getExhaustion());
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
}
|
|
@@ -1687,7 +1807,7 @@
|
|
|
|
protected static Optional<EntityParrot.Variant> extractParrotVariant(NBTTagCompound nbttagcompound) {
|
|
if (!nbttagcompound.isEmpty()) {
|
|
- EntityTypes<?> entitytypes = (EntityTypes) nbttagcompound.read("id", EntityTypes.CODEC).orElse((Object) null);
|
|
+ EntityTypes<?> entitytypes = (EntityTypes) nbttagcompound.read("id", EntityTypes.CODEC).orElse(null); // CraftBukkit - decompile error
|
|
|
|
if (entitytypes == EntityTypes.PARROT) {
|
|
return nbttagcompound.read("Variant", EntityParrot.Variant.LEGACY_CODEC);
|