InventoryCloseEvent Reason API

Allows you to determine why an inventory was closed, enabling plugin developers
to "confirm" things based on if it was player triggered close or not.
This commit is contained in:
Aikar
2018-07-03 21:56:23 -04:00
parent 7749dcdd84
commit 3430a002d1
8 changed files with 168 additions and 112 deletions

View File

@@ -35,12 +35,12 @@
public final InventoryMenu inventoryMenu;
public AbstractContainerMenu containerMenu;
protected FoodData foodData = new FoodData();
@@ -188,7 +198,18 @@
@@ -188,6 +198,17 @@
public Entity currentExplosionCause;
private boolean ignoreFallDamageFromCurrentImpulse;
private int currentImpulseContextResetGraceTime;
+ public boolean affectsSpawning = true; // Paper - Affects Spawning API
+
+ // CraftBukkit start
+ public boolean fauxSleeping;
+ public int oldLevel = -1;
@@ -50,10 +50,18 @@
+ return (CraftHumanEntity) super.getBukkitEntity();
+ }
+ // CraftBukkit end
+
public Player(Level world, BlockPos pos, float yaw, GameProfile gameProfile) {
super(EntityType.PLAYER, world);
this.lastItemInMainHand = ItemStack.EMPTY;
@@ -261,7 +282,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 +374,7 @@
}
@@ -63,7 +71,22 @@
}
private boolean isEquipped(Item item) {
@@ -523,8 +544,14 @@
@@ -511,7 +532,14 @@
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
public void closeContainer() {
this.containerMenu = this.inventoryMenu;
@@ -523,8 +551,14 @@
public void rideTick() {
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
this.stopRiding();
@@ -80,7 +103,7 @@
super.rideTick();
this.oBob = this.bob;
this.bob = 0.0F;
@@ -593,6 +620,7 @@
@@ -593,6 +627,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) {
@@ -88,7 +111,7 @@
this.removeEntitiesOnShoulder();
}
@@ -719,7 +747,14 @@
@@ -719,7 +754,14 @@
@Nullable
public ItemEntity drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership) {
@@ -104,7 +127,7 @@
this.swing(InteractionHand.MAIN_HAND);
}
@@ -809,7 +844,7 @@
@@ -809,7 +851,7 @@
}
if (nbt.contains("LastDeathLocation", 10)) {
@@ -113,7 +136,7 @@
Logger logger = Player.LOGGER;
Objects.requireNonNull(logger);
@@ -817,7 +852,7 @@
@@ -817,7 +859,7 @@
}
if (nbt.contains("current_explosion_impact_pos", 9)) {
@@ -122,7 +145,7 @@
Logger logger1 = Player.LOGGER;
Objects.requireNonNull(logger1);
@@ -854,7 +889,7 @@
@@ -854,7 +896,7 @@
}
this.getLastDeathLocation().flatMap((globalpos) -> {
@@ -131,7 +154,7 @@
Logger logger = Player.LOGGER;
Objects.requireNonNull(logger);
@@ -886,10 +921,10 @@
@@ -886,10 +928,10 @@
if (this.isDeadOrDying()) {
return false;
} else {
@@ -144,7 +167,7 @@
}
if (world.getDifficulty() == Difficulty.EASY) {
@@ -901,7 +936,13 @@
@@ -901,7 +943,13 @@
}
}
@@ -159,7 +182,7 @@
}
}
}
@@ -923,10 +964,29 @@
@@ -923,10 +971,29 @@
}
public boolean canHarmPlayer(Player player) {
@@ -192,7 +215,7 @@
}
@Override
@@ -966,32 +1026,38 @@
@@ -966,32 +1033,38 @@
}
}
@@ -245,7 +268,7 @@
}
public boolean isTextFilteringEnabled() {
@@ -1144,10 +1210,15 @@
@@ -1144,10 +1217,15 @@
f *= 0.2F + f2 * f2 * 0.8F;
f1 *= f2;
@@ -262,7 +285,7 @@
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 +1230,7 @@
@@ -1159,7 +1237,7 @@
boolean flag1;
if (this.isSprinting() && flag) {
@@ -271,7 +294,7 @@
flag1 = true;
} else {
flag1 = false;
@@ -1168,6 +1239,7 @@
@@ -1168,6 +1246,7 @@
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();
@@ -279,7 +302,7 @@
if (flag2) {
f *= 1.5F;
}
@@ -1202,13 +1274,17 @@
@@ -1202,13 +1281,17 @@
if (target instanceof LivingEntity) {
LivingEntity entityliving1 = (LivingEntity) target;
@@ -299,7 +322,7 @@
}
LivingEntity entityliving2;
@@ -1223,8 +1299,13 @@
@@ -1223,8 +1306,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;
@@ -315,7 +338,7 @@
Level world = this.level();
if (world instanceof ServerLevel) {
@@ -1235,26 +1316,43 @@
@@ -1235,26 +1323,43 @@
}
}
@@ -363,7 +386,7 @@
}
}
@@ -1308,9 +1406,14 @@
@@ -1308,9 +1413,14 @@
}
}
@@ -380,7 +403,7 @@
}
}
@@ -1351,7 +1454,14 @@
@@ -1351,7 +1461,14 @@
@Override
public void remove(Entity.RemovalReason reason) {
@@ -396,7 +419,7 @@
this.inventoryMenu.removed(this);
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
@@ -1391,7 +1501,13 @@
@@ -1391,7 +1508,13 @@
}
public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos pos) {
@@ -411,7 +434,7 @@
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
}
@@ -1545,12 +1661,24 @@
@@ -1545,12 +1668,24 @@
}
public void startFallFlying() {
@@ -437,18 +460,17 @@
}
@Override
@@ -1663,12 +1791,31 @@
@@ -1664,11 +1799,30 @@
public int getXpNeededForNextLevel() {
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (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
+ // CraftBukkit start
@@ -470,7 +492,7 @@
}
}
@@ -1748,13 +1895,20 @@
@@ -1748,13 +1902,20 @@
@Override
public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
@@ -498,7 +520,7 @@
}
}
@@ -1798,26 +1952,55 @@
@@ -1798,26 +1959,55 @@
public void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
@@ -561,7 +583,7 @@
}
@Override
@@ -2003,20 +2186,31 @@
@@ -2003,20 +2193,31 @@
@Override
public ImmutableList<Pose> getDismountPoses() {
return ImmutableList.of(Pose.STANDING, Pose.CROUCHING, Pose.SWIMMING);