diff --git a/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch b/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch index 2edf55e52a..45b14d7dce 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/EntityPlayer.java +++ b/net/minecraft/server/level/EntityPlayer.java -@@ -155,6 +155,35 @@ +@@ -155,6 +155,36 @@ import net.minecraft.world.scores.criteria.IScoreboardCriteria; import org.slf4j.Logger; @@ -30,13 +30,14 @@ +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; ++import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.inventory.MainHand; +// CraftBukkit end + public class EntityPlayer extends EntityHuman { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -212,6 +241,21 @@ +@@ -212,6 +242,21 @@ public int latency; public boolean wonGame; @@ -58,7 +59,7 @@ public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile) { super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile); this.chatVisibility = EnumChatVisibility.FULL; -@@ -275,12 +319,56 @@ +@@ -275,12 +320,56 @@ this.advancements = minecraftserver.getPlayerList().getPlayerAdvancements(this); this.setMaxUpStep(1.0F); this.fudgeSpawnLocation(worldserver); @@ -67,8 +68,8 @@ + this.displayName = this.getScoreboardName(); + this.bukkitPickUpLoot = true; + this.maxHealthCache = this.getMaxHealth(); -+ } -+ + } + + // Yes, this doesn't match Vanilla, but it's the best we can do for now. + // If this is an issue, PRs are welcome + public final BlockPosition getSpawnPoint(WorldServer worldserver) { @@ -105,9 +106,9 @@ + } + + return blockposition; - } ++ } + // CraftBukkit end - ++ private void fudgeSpawnLocation(WorldServer worldserver) { BlockPosition blockposition = worldserver.getSharedSpawnPos(); @@ -116,7 +117,7 @@ int i = Math.max(0, this.server.getSpawnRadius(worldserver)); int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ())); -@@ -329,7 +417,7 @@ +@@ -329,7 +418,7 @@ public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { super.readAdditionalSaveData(nbttagcompound); if (nbttagcompound.contains("warden_spawn_tracker", 10)) { @@ -125,7 +126,7 @@ Logger logger = EntityPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -348,17 +436,26 @@ +@@ -348,17 +437,26 @@ if (nbttagcompound.contains("recipeBook", 10)) { this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager()); } @@ -153,7 +154,7 @@ Logger logger1 = EntityPlayer.LOGGER; Objects.requireNonNull(logger1); -@@ -371,7 +468,7 @@ +@@ -371,7 +469,7 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); @@ -162,7 +163,7 @@ Logger logger = EntityPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -392,7 +489,20 @@ +@@ -392,7 +490,20 @@ Entity entity = this.getRootVehicle(); Entity entity1 = this.getVehicle(); @@ -184,7 +185,7 @@ NBTTagCompound nbttagcompound2 = new NBTTagCompound(); NBTTagCompound nbttagcompound3 = new NBTTagCompound(); -@@ -417,9 +527,33 @@ +@@ -417,9 +528,33 @@ nbttagcompound.put("SpawnDimension", nbtbase); }); } @@ -218,7 +219,7 @@ public void setExperiencePoints(int i) { float f = (float) this.getXpNeededForNextLevel(); float f1 = (f - 1.0F) / f; -@@ -478,6 +612,11 @@ +@@ -478,6 +613,11 @@ @Override public void tick() { @@ -230,7 +231,7 @@ this.gameMode.tick(); this.wardenSpawnTracker.tick(); --this.spawnInvulnerableTime; -@@ -534,7 +673,7 @@ +@@ -534,7 +674,7 @@ } if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { @@ -239,7 +240,7 @@ this.lastSentHealth = this.getHealth(); this.lastSentFood = this.foodData.getFoodLevel(); this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; -@@ -565,6 +704,12 @@ +@@ -565,6 +705,12 @@ this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience)); } @@ -252,7 +253,7 @@ if (this.experienceLevel != this.lastRecordedLevel) { this.lastRecordedLevel = this.experienceLevel; this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel)); -@@ -579,6 +724,20 @@ +@@ -579,6 +725,20 @@ CriterionTriggers.LOCATION.trigger(this); } @@ -273,7 +274,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked"); -@@ -621,7 +780,8 @@ +@@ -621,7 +781,8 @@ } private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) { @@ -283,7 +284,7 @@ scoreboardscore.setScore(i); }); } -@@ -630,9 +790,47 @@ +@@ -630,9 +791,47 @@ public void die(DamageSource damagesource) { this.gameEvent(GameEvent.ENTITY_DIE); boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); @@ -333,7 +334,7 @@ this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> { boolean flag1 = true; -@@ -663,12 +861,18 @@ +@@ -663,12 +862,18 @@ if (this.level.getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { this.tellNeutralMobsThatIDied(); } @@ -356,7 +357,7 @@ EntityLiving entityliving = this.getKillCredit(); if (entityliving != null) { -@@ -706,10 +910,12 @@ +@@ -706,10 +911,12 @@ String s = this.getScoreboardName(); String s1 = entity.getScoreboardName(); @@ -371,7 +372,7 @@ } else { this.awardStat(StatisticList.MOB_KILLS); } -@@ -727,7 +933,8 @@ +@@ -727,7 +934,8 @@ int i = scoreboardteam.getColor().getId(); if (i >= 0 && i < aiscoreboardcriteria.length) { @@ -381,7 +382,7 @@ } } -@@ -777,18 +984,20 @@ +@@ -777,18 +985,20 @@ } private boolean isPvpAllowed() { @@ -405,7 +406,7 @@ } else { return shapedetectorshape; } -@@ -797,11 +1006,20 @@ +@@ -797,11 +1007,20 @@ @Nullable @Override public Entity changeDimension(WorldServer worldserver) { @@ -429,7 +430,7 @@ this.unRide(); this.getLevel().removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); if (!this.wonGame) { -@@ -812,6 +1030,8 @@ +@@ -812,6 +1031,8 @@ return this; } else { @@ -438,7 +439,7 @@ WorldData worlddata = worldserver.getLevelData(); this.connection.send(new PacketPlayOutRespawn(worldserver.dimensionTypeId(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), (byte) 3, this.getLastDeathLocation())); -@@ -821,20 +1041,50 @@ +@@ -821,20 +1042,50 @@ playerlist.sendPlayerPermissionLevel(this); worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); this.unsetRemoved(); @@ -494,7 +495,7 @@ this.connection.resetPosition(); worldserver.addDuringPortalTeleport(this); worldserver1.getProfiler().pop(); -@@ -854,39 +1104,66 @@ +@@ -854,39 +1105,66 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -567,21 +568,21 @@ } return optional1; -@@ -896,13 +1173,21 @@ +@@ -896,13 +1174,21 @@ public void triggerDimensionChangeTriggers(WorldServer worldserver) { ResourceKey resourcekey = worldserver.dimension(); ResourceKey resourcekey1 = this.level.dimension(); + // CraftBukkit start + ResourceKey maindimensionkey = CraftDimensionUtil.getMainDimensionKey(worldserver); + ResourceKey maindimensionkey1 = CraftDimensionUtil.getMainDimensionKey(this.level); - -- CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1); -- if (resourcekey == World.NETHER && resourcekey1 == World.OVERWORLD && this.enteredNetherPosition != null) { ++ + CriterionTriggers.CHANGED_DIMENSION.trigger(this, maindimensionkey, maindimensionkey1); + if (maindimensionkey != resourcekey || maindimensionkey1 != resourcekey1) { + CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1); + } -+ + +- CriterionTriggers.CHANGED_DIMENSION.trigger(this, resourcekey, resourcekey1); +- if (resourcekey == World.NETHER && resourcekey1 == World.OVERWORLD && this.enteredNetherPosition != null) { + if (maindimensionkey == World.NETHER && maindimensionkey1 == World.OVERWORLD && this.enteredNetherPosition != null) { + // CraftBukkit end CriterionTriggers.NETHER_TRAVEL.trigger(this, this.enteredNetherPosition); @@ -592,7 +593,7 @@ this.enteredNetherPosition = null; } -@@ -919,12 +1204,10 @@ +@@ -919,12 +1205,10 @@ this.containerMenu.broadcastChanges(); } @@ -608,7 +609,7 @@ return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_HERE); } else if (!this.bedInRange(blockposition, enumdirection)) { return Either.left(EntityHuman.EnumBedResult.TOO_FAR_AWAY); -@@ -948,7 +1231,36 @@ +@@ -948,7 +1232,36 @@ } } @@ -646,7 +647,7 @@ this.awardStat(StatisticList.SLEEP_IN_BED); CriterionTriggers.SLEPT_IN_BED.trigger(this); }); -@@ -961,9 +1273,8 @@ +@@ -961,9 +1274,8 @@ return either; } } @@ -657,7 +658,7 @@ } @Override -@@ -990,6 +1301,24 @@ +@@ -990,6 +1302,24 @@ @Override public void stopSleepInBed(boolean flag, boolean flag1) { @@ -682,7 +683,7 @@ if (this.isSleeping()) { this.getLevel().getChunkSource().broadcastAndSend(this, new PacketPlayOutAnimation(this, 2)); } -@@ -1038,8 +1367,9 @@ +@@ -1038,8 +1368,9 @@ this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos())); } @@ -693,7 +694,7 @@ } @Override -@@ -1047,13 +1377,35 @@ +@@ -1047,13 +1378,35 @@ if (itileinventory == null) { return OptionalInt.empty(); } else { @@ -729,7 +730,7 @@ if (container == null) { if (this.isSpectator()) { this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true); -@@ -1061,9 +1413,11 @@ +@@ -1061,9 +1414,11 @@ return OptionalInt.empty(); } else { @@ -743,7 +744,7 @@ return OptionalInt.of(this.containerCounter); } } -@@ -1076,13 +1430,24 @@ +@@ -1076,13 +1431,24 @@ @Override public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { @@ -770,7 +771,7 @@ this.initMenu(this.containerMenu); } -@@ -1105,6 +1470,7 @@ +@@ -1105,6 +1471,7 @@ @Override public void closeContainer() { @@ -778,7 +779,24 @@ this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId)); this.doCloseContainer(); } -@@ -1135,7 +1501,7 @@ +@@ -1127,6 +1494,16 @@ + } + + this.jumping = flag; ++ // CraftBukkit start ++ if (flag1 != this.isShiftKeyDown()) { ++ PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getBukkitEntity(), flag1); ++ this.server.server.getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ return; ++ } ++ } ++ // CraftBukkit end + this.setShiftKeyDown(flag1); + } + +@@ -1135,7 +1512,7 @@ @Override public void awardStat(Statistic statistic, int i) { this.stats.increment(this, statistic, i); @@ -787,7 +805,7 @@ scoreboardscore.add(i); }); } -@@ -1143,7 +1509,7 @@ +@@ -1143,7 +1520,7 @@ @Override public void resetStat(Statistic statistic) { this.stats.setValue(this, statistic, 0); @@ -796,7 +814,7 @@ } @Override -@@ -1159,7 +1525,7 @@ +@@ -1159,7 +1536,7 @@ for (int j = 0; j < i; ++j) { MinecraftKey minecraftkey = aminecraftkey1[j]; @@ -805,7 +823,7 @@ Objects.requireNonNull(list); optional.ifPresent(list::add); -@@ -1194,6 +1560,7 @@ +@@ -1194,6 +1571,7 @@ public void resetSentInfo() { this.lastSentHealth = -1.0E8F; @@ -813,7 +831,7 @@ } @Override -@@ -1252,7 +1619,7 @@ +@@ -1252,7 +1630,7 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -822,7 +840,7 @@ this.seenCredits = entityplayer.seenCredits; this.enteredNetherPosition = entityplayer.enteredNetherPosition; this.setShoulderEntityLeft(entityplayer.getShoulderEntityLeft()); -@@ -1302,6 +1669,12 @@ +@@ -1302,6 +1680,12 @@ @Override public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1) { @@ -835,7 +853,7 @@ ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2)); worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId()); -@@ -1311,9 +1684,9 @@ +@@ -1311,9 +1695,9 @@ } if (worldserver == this.level) { @@ -847,7 +865,7 @@ } this.setYHeadRot(f); -@@ -1417,7 +1790,20 @@ +@@ -1417,7 +1801,20 @@ } } @@ -868,7 +886,7 @@ this.chatVisibility = packetplayinsettings.chatVisibility(); this.canChatColor = packetplayinsettings.chatColors(); this.textFilteringEnabled = packetplayinsettings.textFilteringEnabled(); -@@ -1492,7 +1878,7 @@ +@@ -1492,7 +1889,7 @@ if (world instanceof WorldServer) { WorldServer worldserver = (WorldServer) world; @@ -877,7 +895,7 @@ } if (entity != null) { -@@ -1529,7 +1915,7 @@ +@@ -1529,7 +1926,7 @@ @Nullable public IChatBaseComponent getTabListDisplayName() { @@ -886,7 +904,7 @@ } @Override -@@ -1550,9 +1936,16 @@ +@@ -1550,9 +1947,16 @@ return this.advancements; } @@ -903,7 +921,7 @@ if (worldserver == this.level) { this.connection.teleport(d0, d1, d2, f, f1); } else { -@@ -1572,6 +1965,9 @@ +@@ -1572,6 +1976,9 @@ this.server.getPlayerList().sendLevelInfo(this, worldserver); this.server.getPlayerList().sendAllPlayerInfo(this); } @@ -913,7 +931,7 @@ } -@@ -1762,4 +2158,146 @@ +@@ -1762,4 +2169,146 @@ this.hurtDir = (float) (MathHelper.atan2(d1, d0) * 57.2957763671875D - (double) this.getYRot()); this.connection.send(new ClientboundHurtAnimationPacket(this)); }