force entity dismount during teleportation

Entities must be dismounted before teleportation in order to avoid
multiple issues in the server with regards to teleportation, shamefully,
too many plugins rely on the events firing, which means that not firing
these events caues more issues than it solves;

In order to counteract this, Entity dismount/exit vehicle events have
been modified to supress cancellation (and has a method to allow plugins
to check if this has been set), noting that cancellation will be silently
surpressed given that plugins are not expecting this event to not be cancellable.

This is a far from ideal scenario, however: given the current state of this
event and other alternatives causing issues elsewhere, I believe that
this is going to be the best soultion all around.

Improvements/suggestions welcome!
This commit is contained in:
Shane Freeder
2018-11-15 13:38:37 +00:00
parent f944b0b8d6
commit 373c8ff0b2
5 changed files with 248 additions and 157 deletions

View File

@@ -162,24 +162,23 @@
}
public void onEquipItem(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack) {
- if (!this.level().isClientSide() && !this.isSpectator()) {
- boolean flag = newStack.isEmpty() && oldStack.isEmpty();
+ // CraftBukkit start
+ this.onEquipItem(slot, oldStack, newStack, false);
+ }
+
+ public void onEquipItem(EquipmentSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) {
+ // CraftBukkit end
if (!this.level().isClientSide() && !this.isSpectator()) {
- boolean flag = newStack.isEmpty() && oldStack.isEmpty();
+ boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
- if (!flag && !ItemStack.isSameItemSameComponents(oldStack, newStack) && !this.firstTick) {
- Equippable equippable = (Equippable) newStack.get(DataComponents.EQUIPPABLE);
+ public void onEquipItem(EquipmentSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) {
+ // CraftBukkit end
+ if (!this.level().isClientSide() && !this.isSpectator()) {
+ boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
+ if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
+ Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE);
- if (!this.isSilent() && equippable != null && slot == equippable.slot()) {
- this.level().playSeededSound((Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
+ if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
+ Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE);
+
+ if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot() && !silent) { // CraftBukkit
+ this.level().playSeededSound((net.minecraft.world.entity.player.Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
}
@@ -266,14 +265,10 @@
boolean flag = scoreboardteam != null && scoreboard.addPlayerToTeam(this.getStringUUID(), scoreboardteam);
if (!flag) {
@@ -815,13 +902,36 @@
@@ -819,9 +906,32 @@
}
if (nbt.contains("Brain", 10)) {
this.brain = this.makeBrain(new Dynamic(NbtOps.INSTANCE, nbt.get("Brain")));
+ }
+
+ }
+
+ // CraftBukkit start
+ private boolean isTickingEffects = false;
+ private List<ProcessableEffect> effectsToProcess = Lists.newArrayList();
@@ -287,15 +282,15 @@
+ private ProcessableEffect(MobEffectInstance effect, EntityPotionEffectEvent.Cause cause) {
+ this.effect = effect;
+ this.cause = cause;
}
+ }
+
+ private ProcessableEffect(Holder<MobEffect> type, EntityPotionEffectEvent.Cause cause) {
+ this.type = type;
+ this.cause = cause;
+ }
}
+ }
+ // CraftBukkit end
+
protected void tickEffects() {
Iterator<Holder<MobEffect>> iterator = this.activeEffects.keySet().iterator();
@@ -963,16 +958,17 @@
}
}
@@ -1682,6 +2053,20 @@
@@ -1681,8 +2052,22 @@
public LivingEntity.Fallsounds getFallSounds() {
return new LivingEntity.Fallsounds(SoundEvents.GENERIC_SMALL_FALL, SoundEvents.GENERIC_BIG_FALL);
}
+ }
+
+ // CraftBukkit start - Add delegate methods
+ public SoundEvent getHurtSound0(DamageSource damagesource) {
+ return this.getHurtSound(damagesource);
+ }
+
}
+ public SoundEvent getDeathSound0() {
+ return this.getDeathSound();
+ }
@@ -981,9 +977,10 @@
+ return this.getFallDamageSound(fallHeight);
+ }
+ // CraftBukkit end
+
public Optional<BlockPos> getLastClimbablePos() {
return this.lastClimbablePos;
}
@@ -1757,9 +2142,14 @@
int i = this.calculateFallDamage(fallDistance, damageMultiplier);
@@ -1092,7 +1089,7 @@
+ };
+ float resistanceModifier = resistance.apply((double) f).floatValue();
+ f += resistanceModifier;
+
+ com.google.common.base.Function<Double, Double> magic = new com.google.common.base.Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
@@ -1101,7 +1098,7 @@
+ };
+ float magicModifier = magic.apply((double) f).floatValue();
+ f += magicModifier;
+
+ com.google.common.base.Function<Double, Double> absorption = new com.google.common.base.Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
@@ -1256,19 +1253,19 @@
this.setHealth(0.0F);
this.die(this.damageSources().generic());
}
@@ -2182,6 +2744,12 @@
@@ -2181,6 +2743,12 @@
public abstract Iterable<ItemStack> getArmorSlots();
public abstract ItemStack getItemBySlot(EquipmentSlot slot);
+
+ // CraftBukkit start
+ public void setItemSlot(EquipmentSlot enumitemslot, ItemStack itemstack, boolean silent) {
+ this.setItemSlot(enumitemslot, itemstack);
+ }
+ // CraftBukkit end
+
public abstract void setItemSlot(EquipmentSlot slot, ItemStack stack);
public Iterable<ItemStack> getHandSlots() {
@@ -2494,7 +3062,7 @@
}
@@ -1381,19 +1378,35 @@
}
Iterator iterator1 = list.iterator();
-
- while (iterator1.hasNext()) {
- Entity entity1 = (Entity) iterator1.next();
+ this.numCollisions = Math.max(0, this.numCollisions - this.level().paperConfig().collisions.maxEntityCollisions); // Paper - Cap entity collisions
- while (iterator1.hasNext()) {
+ while (iterator1.hasNext() && this.numCollisions < this.level().paperConfig().collisions.maxEntityCollisions) { // Paper - Cap entity collisions
+ Entity entity1 = (Entity) iterator1.next();
Entity entity1 = (Entity) iterator1.next();
-
+ entity1.numCollisions++; // Paper - Cap entity collisions
+ this.numCollisions++; // Paper - Cap entity collisions
this.doPush(entity1);
}
}
@@ -3305,15 +3883,22 @@
@@ -3190,9 +3768,15 @@
@Override
public void stopRiding() {
+ // Paper start - Force entity dismount during teleportation
+ this.stopRiding(false);
+ }
+ @Override
+ public void stopRiding(boolean suppressCancellation) {
+ // Paper end - Force entity dismount during teleportation
Entity entity = this.getVehicle();
- super.stopRiding();
+ super.stopRiding(suppressCancellation); // Paper - Force entity dismount during teleportation
if (entity != null && entity != this.getVehicle() && !this.level().isClientSide) {
this.dismountVehicle(entity);
}
@@ -3305,15 +3889,22 @@
@Override
public boolean isPickable() {
@@ -1418,7 +1431,7 @@
public float getYHeadRot() {
return this.yHeadRot;
}
@@ -3342,7 +3927,7 @@
@@ -3342,7 +3933,7 @@
}
public final void setAbsorptionAmount(float absorptionAmount) {
@@ -1427,7 +1440,7 @@
}
protected void internalSetAbsorptionAmount(float absorptionAmount) {
@@ -3483,13 +4068,48 @@
@@ -3483,13 +4074,48 @@
this.releaseUsingItem();
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
@@ -1477,7 +1490,7 @@
}
}
@@ -3544,12 +4164,69 @@
@@ -3544,12 +4170,69 @@
if (this.isUsingItem() && !this.useItem.isEmpty()) {
Item item = this.useItem.getItem();
@@ -1548,7 +1561,7 @@
public boolean isSuppressingSlidingDownLadder() {
return this.isShiftKeyDown();
}
@@ -3568,12 +4245,18 @@
@@ -3568,12 +4251,18 @@
}
public boolean randomTeleport(double x, double y, double z, boolean particleEffects) {
@@ -1569,7 +1582,7 @@
Level world = this.level();
if (world.hasChunkAt(blockposition)) {
@@ -3592,18 +4275,43 @@
@@ -3592,18 +4281,43 @@
}
if (flag2) {
@@ -1581,7 +1594,7 @@
+ this.setPos(d0, d6, d2);
if (world.noCollision((Entity) this) && !world.containsAnyLiquid(this.getBoundingBox())) {
flag1 = true;
+ }
}
+ // now revert and call event if the teleport place is valid
+ this.setPos(d3, d4, d5);
+
@@ -1601,7 +1614,7 @@
+ return Optional.empty();
+ }
+ }
}
+ }
+ // CraftBukkit end
}
}
@@ -1617,7 +1630,7 @@
world.broadcastEntityEvent(this, (byte) 46);
}
@@ -3613,7 +4321,7 @@
@@ -3613,7 +4327,7 @@
entitycreature.getNavigation().stop();
}
@@ -1626,7 +1639,7 @@
}
}
@@ -3706,7 +4414,7 @@
@@ -3706,7 +4420,7 @@
}
public void stopSleeping() {
@@ -1635,7 +1648,7 @@
Level world = this.level();
java.util.Objects.requireNonNull(world);
@@ -3718,9 +4426,9 @@
@@ -3718,9 +4432,9 @@
this.level().setBlock(blockposition, (BlockState) iblockdata.setValue(BedBlock.OCCUPIED, false), 3);
Vec3 vec3d = (Vec3) BedBlock.findStandUpPosition(this.getType(), this.level(), blockposition, enumdirection, this.getYRot()).orElseGet(() -> {
@@ -1647,7 +1660,7 @@
});
Vec3 vec3d1 = Vec3.atBottomCenterOf(blockposition).subtract(vec3d).normalize();
float f = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
@@ -3740,7 +4448,7 @@
@@ -3740,7 +4454,7 @@
@Nullable
public Direction getBedOrientation() {
@@ -1656,7 +1669,7 @@
return blockposition != null ? BedBlock.getBedOrientation(this.level(), blockposition) : null;
}
@@ -3905,7 +4613,7 @@
@@ -3905,7 +4619,7 @@
public float maxUpStep() {
float f = (float) this.getAttributeValue(Attributes.STEP_HEIGHT);