fix player loottables running when mob loot gamerule is false

This commit is contained in:
Jake Potrebic 2022-03-22 09:50:40 -07:00
parent 58f0db0820
commit 7b3898ad66

View File

@ -188,8 +188,8 @@
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper
+ this.bukkitPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth();
+ }
+
}
+ // Use method to resend items in hands in case of client desync, because the item use got cancelled.
+ // For example, when cancelling the leash event
+ public void resendItemInHands() {
@ -235,9 +235,9 @@
+ }
+
+ return blockposition;
}
+ }
+ // CraftBukkit end
+
@Override
public BlockPos adjustSpawnLocation(ServerLevel world, BlockPos basePos) {
AABB axisalignedbb = this.getDimensions(Pose.STANDING).makeBoundingBox(Vec3.ZERO);
@ -398,12 +398,9 @@
Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger);
@@ -683,8 +836,31 @@
});
}
}
+
+ }
@@ -686,6 +839,29 @@
}
+ // CraftBukkit start - World fallback code, either respawn location or global spawn
+ public void spawnIn(Level world) {
@ -425,11 +422,12 @@
+ this.setPosRaw(position.x(), position.y(), position.z()); // Paper - don't register to chunks yet
+ }
+ this.gameMode.setLevel((ServerLevel) world);
}
+ }
+ // CraftBukkit end
+
public void setExperiencePoints(int points) {
float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f;
@@ -744,6 +920,11 @@
@Override
@ -520,7 +518,7 @@
}
float f = this.foodData.getSaturationLevel();
@@ -946,19 +1151,103 @@
@@ -946,19 +1151,105 @@
}
private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) {
@ -529,8 +527,8 @@
+ this.level().getCraftServer().getScoreboardManager().forAllObjectives(criterion, this, (scoreaccess) -> {
scoreaccess.set(score);
});
}
+ }
+
+ // Paper start - PlayerDeathEvent#getItemsToKeep
+ private static void processKeep(org.bukkit.event.entity.PlayerDeathEvent event, NonNullList<ItemStack> inv) {
+ List<org.bukkit.inventory.ItemStack> itemsToKeep = event.getItemsToKeep();
@ -568,9 +566,9 @@
+ inv.set(i, ItemStack.EMPTY);
+ }
+ }
+ }
}
+ // Paper end - PlayerDeathEvent#getItemsToKeep
+
@Override
public void die(DamageSource damageSource) {
- this.gameEvent(GameEvent.ENTITY_DIE);
@ -592,12 +590,14 @@
+ }
+ }
+ }
+ if (this.shouldDropLoot() && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { // Paper - fix player loottables running when mob loot gamerule is false
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
+ this.dropFromLootTable(this.serverLevel(), damageSource, this.lastHurtByPlayerTime > 0);
+ this.dropCustomDeathLoot(this.serverLevel(), damageSource, flag);
+ loot.addAll(this.drops);
+ this.drops.clear(); // SPIGOT-5188: make sure to clear
+ } // Paper - fix player loottables running when mob loot gamerule is false
+
+ Component defaultMessage = this.getCombatTracker().getDeathMessage();
+
@ -628,7 +628,7 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true;
String s = ichatbasecomponent.getString(256);
@@ -988,12 +1277,23 @@
@@ -988,12 +1279,23 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied();
}
@ -656,7 +656,7 @@
LivingEntity entityliving = this.getKillCredit();
if (entityliving != null) {
@@ -1028,10 +1328,12 @@
@@ -1028,10 +1330,12 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled != this) {
super.awardKillScore(entityKilled, damageSource);
@ -672,7 +672,7 @@
} else {
this.awardStat(Stats.MOB_KILLS);
}
@@ -1049,7 +1351,8 @@
@@ -1049,7 +1353,8 @@
int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < criterions.length) {
@ -682,7 +682,7 @@
}
}
@@ -1062,8 +1365,8 @@
@@ -1062,8 +1367,8 @@
} else {
Entity entity = source.getEntity();
@ -693,7 +693,7 @@
if (!this.canHarmPlayer(entityhuman)) {
return false;
@@ -1074,8 +1377,8 @@
@@ -1074,8 +1379,8 @@
AbstractArrow entityarrow = (AbstractArrow) entity;
Entity entity1 = entityarrow.getOwner();
@ -704,7 +704,7 @@
if (!this.canHarmPlayer(entityhuman1)) {
return false;
@@ -1083,38 +1386,84 @@
@@ -1083,38 +1388,84 @@
}
}
@ -797,7 +797,7 @@
}
public static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) {
@@ -1129,11 +1478,11 @@
@@ -1129,11 +1480,11 @@
}
return optional.map((vec3d) -> {
@ -811,7 +811,7 @@
});
} else if (!spawnForced) {
return Optional.empty();
@@ -1142,7 +1491,7 @@
@@ -1142,7 +1493,7 @@
BlockState iblockdata1 = world.getBlockState(pos.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@ -820,7 +820,7 @@
}
}
@@ -1160,6 +1509,7 @@
@@ -1160,6 +1511,7 @@
@Nullable
@Override
public ServerPlayer teleport(TeleportTransition teleportTarget) {
@ -828,7 +828,7 @@
if (this.isRemoved()) {
return null;
} else {
@@ -1169,39 +1519,78 @@
@@ -1169,39 +1521,78 @@
ServerLevel worldserver = teleportTarget.newLevel();
ServerLevel worldserver1 = this.serverLevel();
@ -915,7 +915,7 @@
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
gameprofilerfiller.pop();
@@ -1215,12 +1604,35 @@
@@ -1215,12 +1606,35 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -951,7 +951,7 @@
public void forceSetRotation(float yaw, float pitch) {
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
}
@@ -1228,13 +1640,21 @@
@@ -1228,13 +1642,21 @@
public void triggerDimensionChangeTriggers(ServerLevel origin) {
ResourceKey<Level> resourcekey = origin.dimension();
ResourceKey<Level> resourcekey1 = this.level().dimension();
@ -976,7 +976,7 @@
this.enteredNetherPosition = null;
}
@@ -1251,36 +1671,63 @@
@@ -1251,36 +1673,63 @@
this.containerMenu.broadcastChanges();
}
@ -1055,7 +1055,7 @@
this.awardStat(Stats.SLEEP_IN_BED);
CriteriaTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -1293,9 +1740,8 @@
@@ -1293,9 +1742,8 @@
return either;
}
}
@ -1066,7 +1066,7 @@
}
@Override
@@ -1322,13 +1768,31 @@
@@ -1322,13 +1770,31 @@
@Override
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
@ -1099,7 +1099,7 @@
}
}
@@ -1341,7 +1805,7 @@
@@ -1341,7 +1807,7 @@
@Override
public boolean isInvulnerableTo(ServerLevel world, DamageSource source) {
@ -1108,7 +1108,7 @@
}
@Override
@@ -1387,8 +1851,9 @@
@@ -1387,8 +1853,9 @@
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
}
@ -1119,7 +1119,7 @@
}
@Override
@@ -1396,13 +1861,35 @@
@@ -1396,13 +1863,35 @@
if (factory == null) {
return OptionalInt.empty();
} else {
@ -1155,7 +1155,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true);
@@ -1410,9 +1897,11 @@
@@ -1410,9 +1899,11 @@
return OptionalInt.empty();
} else {
@ -1169,7 +1169,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1425,15 +1914,26 @@
@@ -1425,15 +1916,26 @@
@Override
public void openHorseInventory(AbstractHorse horse, Container inventory) {
@ -1199,7 +1199,7 @@
this.initMenu(this.containerMenu);
}
@@ -1456,9 +1956,28 @@
@@ -1456,9 +1958,28 @@
@Override
public void closeContainer() {
@ -1228,7 +1228,7 @@
@Override
public void doCloseContainer() {
@@ -1485,19 +2004,19 @@
@@ -1485,19 +2006,19 @@
i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F);
if (i > 0) {
this.awardStat(Stats.SWIM_ONE_CM, i);
@ -1251,7 +1251,7 @@
}
} else if (this.onClimbable()) {
if (deltaY > 0.0D) {
@@ -1508,13 +2027,13 @@
@@ -1508,13 +2029,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(Stats.SPRINT_ONE_CM, i);
@ -1268,7 +1268,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1557,7 +2076,7 @@
@@ -1557,7 +2078,7 @@
@Override
public void awardStat(Stat<?> stat, int amount) {
this.stats.increment(this, stat, amount);
@ -1277,7 +1277,7 @@
scoreaccess.add(amount);
});
}
@@ -1565,7 +2084,7 @@
@@ -1565,7 +2086,7 @@
@Override
public void resetStat(Stat<?> stat) {
this.stats.setValue(this, stat, 0);
@ -1286,7 +1286,7 @@
}
@Override
@@ -1597,9 +2116,9 @@
@@ -1597,9 +2118,9 @@
super.jumpFromGround();
this.awardStat(Stats.JUMP);
if (this.isSprinting()) {
@ -1298,7 +1298,7 @@
}
}
@@ -1613,6 +2132,13 @@
@@ -1613,6 +2134,13 @@
public void disconnect() {
this.disconnected = true;
this.ejectPassengers();
@ -1312,7 +1312,7 @@
if (this.isSleeping()) {
this.stopSleepInBed(true, false);
}
@@ -1625,6 +2151,7 @@
@@ -1625,6 +2153,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@ -1320,7 +1320,7 @@
}
@Override
@@ -1661,7 +2188,7 @@
@@ -1661,7 +2190,7 @@
this.onUpdateAbilities();
if (alive) {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1329,7 +1329,7 @@
this.setHealth(oldPlayer.getHealth());
this.foodData = oldPlayer.foodData;
Iterator iterator = oldPlayer.getActiveEffects().iterator();
@@ -1669,7 +2196,7 @@
@@ -1669,7 +2198,7 @@
while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
@ -1338,7 +1338,7 @@
}
this.getInventory().replaceWith(oldPlayer.getInventory());
@@ -1680,7 +2207,7 @@
@@ -1680,7 +2209,7 @@
this.portalProcess = oldPlayer.portalProcess;
} else {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1347,7 +1347,7 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) {
this.getInventory().replaceWith(oldPlayer.getInventory());
this.experienceLevel = oldPlayer.experienceLevel;
@@ -1696,7 +2223,7 @@
@@ -1696,7 +2225,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@ -1356,7 +1356,7 @@
this.seenCredits = oldPlayer.seenCredits;
this.enteredNetherPosition = oldPlayer.enteredNetherPosition;
this.chunkTrackingView = oldPlayer.chunkTrackingView;
@@ -1752,19 +2279,19 @@
@@ -1752,19 +2281,19 @@
}
@Override
@ -1380,7 +1380,7 @@
}
return flag1;
@@ -1799,10 +2326,18 @@
@@ -1799,10 +2328,18 @@
}
public boolean setGameMode(GameType gameMode) {
@ -1401,7 +1401,7 @@
} else {
this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gameMode.getId()));
if (gameMode == GameType.SPECTATOR) {
@@ -1818,7 +2353,7 @@
@@ -1818,7 +2355,7 @@
this.onUpdateAbilities();
this.updateEffectVisibility();
@ -1410,7 +1410,7 @@
}
}
@@ -1861,8 +2396,13 @@
@@ -1861,8 +2398,13 @@
}
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
@ -1425,7 +1425,7 @@
}
}
@@ -1878,7 +2418,36 @@
@@ -1878,7 +2420,36 @@
}
public void updateOptions(ClientInformation clientOptions) {
@ -1462,7 +1462,7 @@
this.requestedViewDistance = clientOptions.viewDistance();
this.chatVisibility = clientOptions.chatVisibility();
this.canChatColor = clientOptions.chatColors();
@@ -1957,12 +2526,27 @@
@@ -1957,12 +2528,27 @@
this.camera = (Entity) (entity == null ? this : entity);
if (entity1 != this.camera) {
@ -1491,7 +1491,7 @@
}
if (entity != null) {
@@ -1999,11 +2583,11 @@
@@ -1999,11 +2585,11 @@
@Nullable
public Component getTabListDisplayName() {
@ -1505,7 +1505,7 @@
}
@Override
@@ -2045,12 +2629,44 @@
@@ -2045,12 +2631,44 @@
this.setRespawnPosition(player.getRespawnDimension(), player.getRespawnPosition(), player.getRespawnAngle(), player.isRespawnForced(), false);
}
@ -1552,7 +1552,7 @@
}
this.respawnPosition = pos;
@@ -2064,6 +2680,7 @@
@@ -2064,6 +2682,7 @@
this.respawnForced = false;
}
@ -1560,7 +1560,7 @@
}
public SectionPos getLastSectionPos() {
@@ -2088,18 +2705,44 @@
@@ -2088,18 +2707,44 @@
}
@Override
@ -1609,7 +1609,7 @@
}
this.awardStat(Stats.DROP);
@@ -2115,6 +2758,11 @@
@@ -2115,6 +2760,11 @@
return null;
} else {
double d0 = this.getEyeY() - 0.30000001192092896D;
@ -1621,7 +1621,7 @@
ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), d0, this.getZ(), stack);
entityitem.setPickUpDelay(40);
@@ -2166,6 +2814,16 @@
@@ -2166,6 +2816,16 @@
}
public void loadGameTypes(@Nullable CompoundTag nbt) {
@ -1638,7 +1638,7 @@
this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType"));
}
@@ -2275,9 +2933,15 @@
@@ -2275,9 +2935,15 @@
@Override
public void stopRiding() {
@ -1655,7 +1655,7 @@
if (entity instanceof LivingEntity entityliving) {
Iterator iterator = entityliving.getActiveEffects().iterator();
@@ -2375,10 +3039,12 @@
@@ -2375,10 +3041,12 @@
return TicketType.ENDER_PEARL.timeout();
}
@ -1671,7 +1671,7 @@
}
private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) {
@@ -2387,4 +3053,147 @@
@@ -2387,4 +3055,147 @@
return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
}
}