Remove Spigot timings

This commit is contained in:
Aikar
2016-03-03 04:00:11 -06:00
parent a371d5fefe
commit 770ee3eebd
19 changed files with 475 additions and 926 deletions

View File

@ -18,7 +18,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FenceGateBlock;
@@ -138,9 +138,68 @@
@@ -138,9 +138,67 @@
import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Team;
import org.slf4j.Logger;
@ -33,7 +33,6 @@
+import org.bukkit.entity.Hanging;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Vehicle;
+import org.spigotmc.CustomTimingsHandler; // Spigot
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
+import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
@ -87,7 +86,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers";
@@ -224,7 +283,7 @@
@@ -224,7 +282,7 @@
private static final EntityDataAccessor<Boolean> DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_NO_GRAVITY = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
@ -96,7 +95,7 @@
private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT);
private EntityInLevelCallback levelCallback;
private final VecDeltaCodec packetPositionCodec;
@@ -253,6 +312,42 @@
@@ -253,6 +311,41 @@
private final List<Entity.Movement> movementThisTick;
private final Set<BlockState> blocksInside;
private final LongSet visitedBlocks;
@ -115,7 +114,6 @@
+ // Marks an entity, that it was removed by a plugin via Entity#remove
+ // Main use case currently is for SPIGOT-7487, preventing dropping of leash when leash is removed
+ public boolean pluginRemoved = false;
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
+ // Spigot start
+ public final org.spigotmc.ActivationRange.ActivationType activationType = org.spigotmc.ActivationRange.initializeEntityActivationType(this);
+ public final boolean defaultActivationState;
@ -139,7 +137,7 @@
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -284,6 +379,13 @@
@@ -284,6 +377,13 @@
this.position = Vec3.ZERO;
this.blockPosition = BlockPos.ZERO;
this.chunkPosition = ChunkPos.ZERO;
@ -153,7 +151,7 @@
SynchedEntityData.Builder datawatcher_a = new SynchedEntityData.Builder(this);
datawatcher_a.define(Entity.DATA_SHARED_FLAGS_ID, (byte) 0);
@@ -292,7 +394,7 @@
@@ -292,7 +392,7 @@
datawatcher_a.define(Entity.DATA_CUSTOM_NAME, Optional.empty());
datawatcher_a.define(Entity.DATA_SILENT, false);
datawatcher_a.define(Entity.DATA_NO_GRAVITY, false);
@ -162,7 +160,7 @@
datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0);
this.defineSynchedData(datawatcher_a);
this.entityData = datawatcher_a.build();
@@ -362,20 +464,36 @@
@@ -362,20 +462,36 @@
}
public void kill(ServerLevel world) {
@ -201,7 +199,7 @@
public boolean equals(Object object) {
return object instanceof Entity ? ((Entity) object).id == this.id : false;
}
@@ -385,22 +503,34 @@
@@ -385,22 +501,34 @@
}
public void remove(Entity.RemovalReason reason) {
@ -241,7 +239,7 @@
return this.getPose() == pose;
}
@@ -417,6 +547,33 @@
@@ -417,6 +545,33 @@
}
public void setRot(float yaw, float pitch) {
@ -275,7 +273,7 @@
this.setYRot(yaw % 360.0F);
this.setXRot(pitch % 360.0F);
}
@@ -462,6 +619,15 @@
@@ -462,6 +617,15 @@
this.baseTick();
}
@ -291,7 +289,7 @@
public void baseTick() {
ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -475,7 +641,7 @@
@@ -475,7 +639,7 @@
--this.boardingCooldown;
}
@ -300,7 +298,7 @@
if (this.canSpawnSprintParticle()) {
this.spawnSprintParticle();
}
@@ -514,6 +680,10 @@
@@ -514,6 +678,10 @@
if (this.isInLava()) {
this.lavaHurt();
this.fallDistance *= 0.5F;
@ -311,7 +309,7 @@
}
this.checkBelowWorld();
@@ -525,7 +695,7 @@
@@ -525,7 +693,7 @@
world = this.level();
if (world instanceof ServerLevel worldserver) {
if (this instanceof Leashable) {
@ -320,7 +318,7 @@
}
}
@@ -568,15 +738,32 @@
@@ -568,15 +736,32 @@
public void lavaHurt() {
if (!this.fireImmune()) {
@ -355,7 +353,7 @@
}
}
@@ -587,9 +774,25 @@
@@ -587,9 +772,25 @@
}
public final void igniteForSeconds(float seconds) {
@ -382,7 +380,7 @@
public void igniteForTicks(int ticks) {
if (this.remainingFireTicks < ticks) {
this.setRemainingFireTicks(ticks);
@@ -610,7 +813,7 @@
@@ -610,7 +811,7 @@
}
protected void onBelowWorld() {
@ -391,21 +389,10 @@
}
public boolean isFree(double offsetX, double offsetY, double offsetZ) {
@@ -672,6 +875,7 @@
}
@@ -750,6 +951,28 @@
}
}
public void move(MoverType type, Vec3 movement) {
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -747,8 +951,30 @@
if (movement.y != vec3d1.y) {
block.updateEntityMovementAfterFallOn(this.level(), this);
+ }
+ }
+
+ // CraftBukkit start
+ if (this.horizontalCollision && this.getBukkitEntity() instanceof Vehicle) {
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
@ -419,26 +406,19 @@
+ bl = bl.getRelative(BlockFace.SOUTH);
+ } else if (movement.z < vec3d1.z) {
+ bl = bl.getRelative(BlockFace.NORTH);
}
+ }
+
+ if (!bl.getType().isAir()) {
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ }
}
+ }
+ // CraftBukkit end
+
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
Entity.MovementEmission entity_movementemission = this.getMovementEmission();
@@ -764,6 +990,7 @@
gameprofilerfiller.pop();
}
}
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
}
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission moveEffect, Vec3 movement, BlockPos landingPos, BlockState landingState) {
@@ -1133,6 +1360,20 @@
@@ -1133,6 +1356,20 @@
return SoundEvents.GENERIC_SPLASH;
}
@ -459,7 +439,7 @@
public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) {
this.movementThisTick.add(new Entity.Movement(oldPos, newPos));
}
@@ -1609,6 +1850,7 @@
@@ -1609,6 +1846,7 @@
this.yo = y;
this.zo = d4;
this.setPos(d3, y, d4);
@ -467,7 +447,7 @@
}
public void moveTo(Vec3 pos) {
@@ -1861,6 +2103,12 @@
@@ -1861,6 +2099,12 @@
return false;
}
@ -480,7 +460,7 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled instanceof ServerPlayer) {
CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer) entityKilled, this, damageSource);
@@ -1889,16 +2137,22 @@
@@ -1889,16 +2133,22 @@
}
public boolean saveAsPassenger(CompoundTag nbt) {
@ -506,7 +486,7 @@
return true;
}
}
@@ -1909,54 +2163,98 @@
@@ -1909,54 +2159,98 @@
}
public CompoundTag saveWithoutId(CompoundTag nbt) {
@ -625,7 +605,7 @@
}
ListTag nbttaglist;
@@ -1972,10 +2270,10 @@
@@ -1972,10 +2266,10 @@
nbttaglist.add(StringTag.valueOf(s));
}
@ -638,7 +618,7 @@
if (this.isVehicle()) {
nbttaglist = new ListTag();
iterator = this.getPassengers().iterator();
@@ -1984,17 +2282,22 @@
@@ -1984,17 +2278,22 @@
Entity entity = (Entity) iterator.next();
CompoundTag nbttagcompound1 = new CompoundTag();
@ -664,10 +644,11 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved");
@@ -2080,6 +2383,50 @@
@@ -2079,7 +2378,51 @@
}
} else {
throw new IllegalStateException("Entity has invalid position");
}
+ }
+
+ // CraftBukkit start
+ // Spigot start
@ -703,7 +684,7 @@
+ }
+
+ ((ServerPlayer) this).setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle());
+ }
}
+ this.getBukkitEntity().readBukkitValues(nbt);
+ if (nbt.contains("Bukkit.invisible")) {
+ boolean bukkitInvisible = nbt.getBoolean("Bukkit.invisible");
@ -715,7 +696,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -2101,6 +2448,12 @@
@@ -2101,6 +2444,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
}
@ -728,7 +709,7 @@
protected abstract void readAdditionalSaveData(CompoundTag nbt);
protected abstract void addAdditionalSaveData(CompoundTag nbt);
@@ -2153,9 +2506,22 @@
@@ -2153,9 +2502,22 @@
if (stack.isEmpty()) {
return null;
} else {
@ -751,7 +732,7 @@
world.addFreshEntity(entityitem);
return entityitem;
}
@@ -2184,6 +2550,12 @@
@@ -2184,6 +2546,12 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) {
@ -764,7 +745,7 @@
if (player.hasInfiniteMaterials()) {
leashable.removeLeash();
} else {
@@ -2200,6 +2572,13 @@
@@ -2200,6 +2568,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) {
@ -778,7 +759,7 @@
leashable.setLeashedTo(player, true);
}
@@ -2265,7 +2644,7 @@
@@ -2265,7 +2640,7 @@
}
public boolean showVehicleHealth() {
@ -787,7 +768,7 @@
}
public boolean startRiding(Entity entity, boolean force) {
@@ -2273,7 +2652,7 @@
@@ -2273,7 +2648,7 @@
return false;
} else if (!entity.couldAcceptPassenger()) {
return false;
@ -796,7 +777,7 @@
return false;
} else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2664,32 @@
@@ -2285,11 +2660,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@ -830,7 +811,7 @@
this.vehicle = entity;
this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2318,7 +2718,7 @@
@@ -2318,7 +2714,7 @@
Entity entity = this.vehicle;
this.vehicle = null;
@ -839,7 +820,7 @@
}
}
@@ -2349,21 +2749,50 @@
@@ -2349,21 +2745,50 @@
}
}
@ -896,7 +877,7 @@
}
protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +2893,7 @@
@@ -2464,7 +2889,7 @@
if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel();
@ -905,7 +886,7 @@
this.teleport(teleporttransition);
}
}
@@ -2547,7 +2976,7 @@
@@ -2547,7 +2972,7 @@
}
public boolean isCrouching() {
@ -914,7 +895,7 @@
}
public boolean isSprinting() {
@@ -2563,7 +2992,7 @@
@@ -2563,7 +2988,7 @@
}
public boolean isVisuallySwimming() {
@ -923,7 +904,7 @@
}
public boolean isVisuallyCrawling() {
@@ -2571,6 +3000,13 @@
@@ -2571,6 +2996,13 @@
}
public void setSwimming(boolean swimming) {
@ -937,7 +918,7 @@
this.setSharedFlag(4, swimming);
}
@@ -2624,8 +3060,12 @@
@@ -2624,8 +3056,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
}
@ -951,7 +932,7 @@
}
public boolean getSharedFlag(int index) {
@@ -2644,7 +3084,7 @@
@@ -2644,7 +3080,7 @@
}
public int getMaxAirSupply() {
@ -960,7 +941,7 @@
}
public int getAirSupply() {
@@ -2652,7 +3092,18 @@
@@ -2652,7 +3088,18 @@
}
public void setAirSupply(int air) {
@ -980,7 +961,7 @@
}
public int getTicksFrozen() {
@@ -2679,11 +3130,40 @@
@@ -2679,11 +3126,40 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@ -1023,7 +1004,7 @@
}
public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3193,7 @@
@@ -2713,7 +3189,7 @@
this.resetFallDistance();
}
@ -1032,7 +1013,7 @@
return true;
}
@@ -2852,6 +3332,18 @@
@@ -2852,6 +3328,18 @@
if (world instanceof ServerLevel worldserver) {
if (!this.isRemoved()) {
@ -1051,7 +1032,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2920,8 +3412,12 @@
@@ -2920,8 +3408,12 @@
} else {
entity.restoreFrom(this);
this.removeAfterChangingDimensions();
@ -1065,7 +1046,7 @@
Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) {
@@ -2947,7 +3443,7 @@
@@ -2947,7 +3439,7 @@
}
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@ -1074,7 +1055,7 @@
Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
@@ -2995,8 +3491,9 @@
@@ -2995,8 +3487,9 @@
}
protected void removeAfterChangingDimensions() {
@ -1085,7 +1066,7 @@
leashable.removeLeash();
}
@@ -3006,6 +3503,20 @@
@@ -3006,6 +3499,20 @@
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
}
@ -1106,7 +1087,7 @@
public boolean canUsePortal(boolean allowVehicles) {
return (allowVehicles || !this.isPassenger()) && this.isAlive();
}
@@ -3134,9 +3645,15 @@
@@ -3134,10 +3641,16 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
}
@ -1117,15 +1098,16 @@
+ public final boolean teleportTo(ServerLevel world, double destX, double destY, double destZ, Set<Relative> flags, float yaw, float pitch, boolean resetCamera) {
+ return this.teleportTo(world, destX, destY, destZ, flags, yaw, pitch, resetCamera, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ }
+
+ public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ float f2 = Mth.clamp(f1, -90.0F, 90.0F);
+ Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3(d0, d1, d2), Vec3.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause));
+ // CraftBukkit end
+
return entity != null;
}
@@ -3187,7 +3704,7 @@
@@ -3187,7 +3700,7 @@
/** @deprecated */
@Deprecated
protected void fixupDimensions() {
@ -1134,7 +1116,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize;
@@ -3196,7 +3713,7 @@
@@ -3196,7 +3709,7 @@
public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions;
@ -1143,7 +1125,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1;
@@ -3258,10 +3775,29 @@
@@ -3258,10 +3771,29 @@
}
public final void setBoundingBox(AABB boundingBox) {
@ -1175,7 +1157,7 @@
return this.getDimensions(pose).eyeHeight();
}
@@ -3335,7 +3871,7 @@
@@ -3335,7 +3867,7 @@
}
@Nullable
@ -1184,7 +1166,7 @@
return null;
}
@@ -3435,7 +3971,7 @@
@@ -3435,7 +3967,7 @@
}
public boolean isControlledByLocalInstance() {
@ -1193,7 +1175,7 @@
if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer();
@@ -3445,7 +3981,7 @@
@@ -3445,7 +3977,7 @@
}
public boolean isControlledByClient() {
@ -1202,7 +1184,7 @@
return entityliving != null && entityliving.isControlledByClient();
}
@@ -3463,7 +3999,7 @@
@@ -3463,7 +3995,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
}
@ -1211,7 +1193,7 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
}
@@ -3489,8 +4025,37 @@
@@ -3489,8 +4021,37 @@
return 1;
}
@ -1250,7 +1232,7 @@
}
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3550,7 +4115,12 @@
@@ -3550,7 +4111,12 @@
vec3d = vec3d.add(vec3d1);
++k1;
@ -1263,7 +1245,7 @@
}
}
}
@@ -3613,7 +4183,7 @@
@@ -3613,7 +4179,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry);
}
@ -1272,7 +1254,7 @@
return this.type.getDimensions();
}
@@ -3818,8 +4388,16 @@
@@ -3818,8 +4384,16 @@
@Override
public final void setRemoved(Entity.RemovalReason reason) {
@ -1290,7 +1272,7 @@
}
if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4405,8 @@
@@ -3827,8 +4401,8 @@
}
this.getPassengers().forEach(Entity::stopRiding);
@ -1301,7 +1283,7 @@
}
public void unsetRemoved() {
@@ -3887,7 +4465,7 @@
@@ -3887,7 +4461,7 @@
}
public Vec3 getKnownMovement() {