Allow using old ender pearl behavior

When enabled, ender pearls will not load chunks and will save to the world instead of the player.

== AT ==
public net.minecraft.world.entity.projectile.Projectile cachedOwner
This commit is contained in:
Jason Penilla 2024-10-27 12:36:53 -07:00
parent 21f51ebd74
commit cf7a1191a9
3 changed files with 140 additions and 110 deletions

View File

@ -114,7 +114,7 @@
@Nullable @Nullable
private Vec3 startingToFallPosition; private Vec3 startingToFallPosition;
@Nullable @Nullable
@@ -258,6 +293,34 @@ @@ -258,7 +293,35 @@
private final CommandSource commandSource; private final CommandSource commandSource;
private int containerCounter; private int containerCounter;
public boolean wonGame; public boolean wonGame;
@ -125,7 +125,7 @@
+ public boolean queueHealthUpdatePacket; + public boolean queueHealthUpdatePacket;
+ public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket; + public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket;
+ // Paper end - cancellable death event + // Paper end - cancellable death event
+
+ // CraftBukkit start + // CraftBukkit start
+ public CraftPlayer.TransferCookieConnection transferCookieConnection; + public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName; + public String displayName;
@ -146,9 +146,10 @@
+ public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent + public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
+ public @Nullable String clientBrandName = null; // Paper - Brand support + public @Nullable String clientBrandName = null; // Paper - Brand support
+ public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event + public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
+
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) { public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile); super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
@@ -266,7 +329,7 @@ @@ -266,7 +329,7 @@
this.canChatColor = true; this.canChatColor = true;
this.lastActionTime = Util.getMillis(); this.lastActionTime = Util.getMillis();
@ -228,8 +229,8 @@
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper + this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper
+ this.bukkitPickUpLoot = true; + this.bukkitPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth(); + this.maxHealthCache = this.getMaxHealth();
} + }
+
+ // Use method to resend items in hands in case of client desync, because the item use got cancelled. + // 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 + // For example, when cancelling the leash event
+ @Deprecated // Paper - this shouldn't be used, use the regular sendAllDataToRemote call to resync all + @Deprecated // Paper - this shouldn't be used, use the regular sendAllDataToRemote call to resync all
@ -276,9 +277,9 @@
+ } + }
+ +
+ return blockposition; + return blockposition;
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
@Override @Override
public BlockPos adjustSpawnLocation(ServerLevel world, BlockPos basePos) { public BlockPos adjustSpawnLocation(ServerLevel world, BlockPos basePos) {
AABB axisalignedbb = this.getDimensions(Pose.STANDING).makeBoundingBox(Vec3.ZERO); AABB axisalignedbb = this.getDimensions(Pose.STANDING).makeBoundingBox(Vec3.ZERO);
@ -421,7 +422,15 @@
} }
} }
} }
@@ -625,7 +805,7 @@ @@ -618,6 +798,7 @@
while (iterator.hasNext()) {
ThrownEnderpearl entityenderpearl = (ThrownEnderpearl) iterator.next();
+ if (entityenderpearl.level().paperConfig().misc.legacyEnderPearlBehavior) continue; // Paper - Allow using old ender pearl behavior
if (entityenderpearl.isRemoved()) {
ServerPlayer.LOGGER.warn("Trying to save removed ender pearl, skipping");
@@ -625,7 +806,7 @@
CompoundTag nbttagcompound1 = new CompoundTag(); CompoundTag nbttagcompound1 = new CompoundTag();
entityenderpearl.save(nbttagcompound1); entityenderpearl.save(nbttagcompound1);
@ -430,7 +439,7 @@
Logger logger = ServerPlayer.LOGGER; Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -651,7 +831,7 @@ @@ -651,7 +832,7 @@
nbttaglist.forEach((nbtbase1) -> { nbttaglist.forEach((nbtbase1) -> {
if (nbtbase1 instanceof CompoundTag nbttagcompound) { if (nbtbase1 instanceof CompoundTag nbttagcompound) {
if (nbttagcompound.contains("ender_pearl_dimension")) { if (nbttagcompound.contains("ender_pearl_dimension")) {
@ -439,7 +448,7 @@
Logger logger = ServerPlayer.LOGGER; Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -684,7 +864,30 @@ @@ -684,7 +865,30 @@
} }
} }
@ -470,7 +479,7 @@
public void setExperiencePoints(int points) { public void setExperiencePoints(int points) {
float f = (float) this.getXpNeededForNextLevel(); float f = (float) this.getXpNeededForNextLevel();
@@ -744,6 +947,11 @@ @@ -744,6 +948,11 @@
@Override @Override
public void tick() { public void tick() {
@ -482,7 +491,7 @@
this.tickClientLoadTimeout(); this.tickClientLoadTimeout();
this.gameMode.tick(); this.gameMode.tick();
this.wardenSpawnTracker.tick(); this.wardenSpawnTracker.tick();
@@ -751,9 +959,13 @@ @@ -751,9 +960,13 @@
--this.invulnerableTime; --this.invulnerableTime;
} }
@ -499,7 +508,7 @@
this.containerMenu = this.inventoryMenu; this.containerMenu = this.inventoryMenu;
} }
@@ -807,7 +1019,7 @@ @@ -807,7 +1020,7 @@
public void doTick() { public void doTick() {
try { try {
@ -508,7 +517,7 @@
super.tick(); super.tick();
} }
@@ -820,7 +1032,7 @@ @@ -820,7 +1033,7 @@
} }
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
@ -517,7 +526,7 @@
this.lastSentHealth = this.getHealth(); this.lastSentHealth = this.getHealth();
this.lastSentFood = this.foodData.getFoodLevel(); this.lastSentFood = this.foodData.getFoodLevel();
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
@@ -851,6 +1063,12 @@ @@ -851,6 +1064,12 @@
this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience)); this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience));
} }
@ -530,7 +539,7 @@
if (this.experienceLevel != this.lastRecordedLevel) { if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel; this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel)); this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel));
@@ -865,6 +1083,20 @@ @@ -865,6 +1084,20 @@
CriteriaTriggers.LOCATION.trigger(this); CriteriaTriggers.LOCATION.trigger(this);
} }
@ -551,7 +560,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Player being ticked"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Player being ticked");
@@ -893,7 +1125,7 @@ @@ -893,7 +1126,7 @@
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) { if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
if (this.tickCount % 20 == 0) { if (this.tickCount % 20 == 0) {
if (this.getHealth() < this.getMaxHealth()) { if (this.getHealth() < this.getMaxHealth()) {
@ -560,7 +569,7 @@
} }
float f = this.foodData.getSaturationLevel(); float f = this.foodData.getSaturationLevel();
@@ -946,19 +1178,105 @@ @@ -946,19 +1179,105 @@
} }
private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) { private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) {
@ -670,7 +679,7 @@
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> { this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
boolean flag1 = true; boolean flag1 = true;
String s = ichatbasecomponent.getString(256); String s = ichatbasecomponent.getString(256);
@@ -988,12 +1306,23 @@ @@ -988,12 +1307,23 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
this.tellNeutralMobsThatIDied(); this.tellNeutralMobsThatIDied();
} }
@ -698,7 +707,7 @@
LivingEntity entityliving = this.getKillCredit(); LivingEntity entityliving = this.getKillCredit();
if (entityliving != null) { if (entityliving != null) {
@@ -1028,10 +1357,12 @@ @@ -1028,10 +1358,12 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) { public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled != this) { if (entityKilled != this) {
super.awardKillScore(entityKilled, damageSource); super.awardKillScore(entityKilled, damageSource);
@ -714,7 +723,7 @@
} else { } else {
this.awardStat(Stats.MOB_KILLS); this.awardStat(Stats.MOB_KILLS);
} }
@@ -1049,7 +1380,8 @@ @@ -1049,7 +1381,8 @@
int i = scoreboardteam.getColor().getId(); int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < criterions.length) { if (i >= 0 && i < criterions.length) {
@ -724,7 +733,7 @@
} }
} }
@@ -1062,8 +1394,8 @@ @@ -1062,8 +1395,8 @@
} else { } else {
Entity entity = source.getEntity(); Entity entity = source.getEntity();
@ -735,7 +744,7 @@
if (!this.canHarmPlayer(entityhuman)) { if (!this.canHarmPlayer(entityhuman)) {
return false; return false;
@@ -1074,8 +1406,8 @@ @@ -1074,8 +1407,8 @@
AbstractArrow entityarrow = (AbstractArrow) entity; AbstractArrow entityarrow = (AbstractArrow) entity;
Entity entity1 = entityarrow.getOwner(); Entity entity1 = entityarrow.getOwner();
@ -746,7 +755,7 @@
if (!this.canHarmPlayer(entityhuman1)) { if (!this.canHarmPlayer(entityhuman1)) {
return false; return false;
@@ -1083,38 +1415,84 @@ @@ -1083,38 +1416,84 @@
} }
} }
@ -839,7 +848,7 @@
} }
public static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) { public static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) {
@@ -1129,11 +1507,11 @@ @@ -1129,11 +1508,11 @@
} }
return optional.map((vec3d) -> { return optional.map((vec3d) -> {
@ -853,7 +862,7 @@
}); });
} else if (!spawnForced) { } else if (!spawnForced) {
return Optional.empty(); return Optional.empty();
@@ -1142,7 +1520,7 @@ @@ -1142,7 +1521,7 @@
BlockState iblockdata1 = world.getBlockState(pos.above()); BlockState iblockdata1 = world.getBlockState(pos.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1); boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@ -862,7 +871,7 @@
} }
} }
@@ -1160,6 +1538,7 @@ @@ -1160,6 +1539,7 @@
@Nullable @Nullable
@Override @Override
public ServerPlayer teleport(TeleportTransition teleportTarget) { public ServerPlayer teleport(TeleportTransition teleportTarget) {
@ -870,7 +879,7 @@
if (this.isRemoved()) { if (this.isRemoved()) {
return null; return null;
} else { } else {
@@ -1169,39 +1548,78 @@ @@ -1169,39 +1549,78 @@
ServerLevel worldserver = teleportTarget.newLevel(); ServerLevel worldserver = teleportTarget.newLevel();
ServerLevel worldserver1 = this.serverLevel(); ServerLevel worldserver1 = this.serverLevel();
@ -957,7 +966,7 @@
this.connection.resetPosition(); this.connection.resetPosition();
worldserver.addDuringTeleport(this); worldserver.addDuringTeleport(this);
gameprofilerfiller.pop(); gameprofilerfiller.pop();
@@ -1215,12 +1633,35 @@ @@ -1215,10 +1634,33 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -973,27 +982,25 @@
+ // Paper end - Reset shield blocking on dimension change + // Paper end - Reset shield blocking on dimension change
return this; return this;
} }
} + }
} + }
+
+ // CraftBukkit start + // CraftBukkit start
@Override + @Override
+ public CraftPortalEvent callPortalEvent(Entity entity, Location exit, TeleportCause cause, int searchRadius, int creationRadius) { + public CraftPortalEvent callPortalEvent(Entity entity, Location exit, TeleportCause cause, int searchRadius, int creationRadius) {
+ Location enter = this.getBukkitEntity().getLocation(); + Location enter = this.getBukkitEntity().getLocation();
+ PlayerPortalEvent event = new PlayerPortalEvent(this.getBukkitEntity(), enter, exit, cause, searchRadius, true, creationRadius); + PlayerPortalEvent event = new PlayerPortalEvent(this.getBukkitEntity(), enter, exit, cause, searchRadius, true, creationRadius);
+ Bukkit.getServer().getPluginManager().callEvent(event); + Bukkit.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null) { + if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null) {
+ return null; + return null;
+ } }
+ return new CraftPortalEvent(event); + return new CraftPortalEvent(event);
+ }
+ // CraftBukkit end
+
+ @Override
public void forceSetRotation(float yaw, float pitch) {
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
} }
@@ -1228,13 +1669,27 @@ + // CraftBukkit end
@Override
public void forceSetRotation(float yaw, float pitch) {
@@ -1228,13 +1670,27 @@
public void triggerDimensionChangeTriggers(ServerLevel origin) { public void triggerDimensionChangeTriggers(ServerLevel origin) {
ResourceKey<Level> resourcekey = origin.dimension(); ResourceKey<Level> resourcekey = origin.dimension();
ResourceKey<Level> resourcekey1 = this.level().dimension(); ResourceKey<Level> resourcekey1 = this.level().dimension();
@ -1024,7 +1031,7 @@
this.enteredNetherPosition = null; this.enteredNetherPosition = null;
} }
@@ -1251,36 +1706,63 @@ @@ -1251,36 +1707,63 @@
this.containerMenu.broadcastChanges(); this.containerMenu.broadcastChanges();
} }
@ -1103,7 +1110,7 @@
this.awardStat(Stats.SLEEP_IN_BED); this.awardStat(Stats.SLEEP_IN_BED);
CriteriaTriggers.SLEPT_IN_BED.trigger(this); CriteriaTriggers.SLEPT_IN_BED.trigger(this);
}); });
@@ -1293,9 +1775,8 @@ @@ -1293,9 +1776,8 @@
return either; return either;
} }
} }
@ -1114,7 +1121,7 @@
} }
@Override @Override
@@ -1322,13 +1803,31 @@ @@ -1322,13 +1804,31 @@
@Override @Override
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) { public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
@ -1147,7 +1154,7 @@
} }
} }
@@ -1341,7 +1840,7 @@ @@ -1341,7 +1841,7 @@
@Override @Override
public boolean isInvulnerableTo(ServerLevel world, DamageSource source) { public boolean isInvulnerableTo(ServerLevel world, DamageSource source) {
@ -1156,7 +1163,7 @@
} }
@Override @Override
@@ -1387,8 +1886,9 @@ @@ -1387,8 +1887,9 @@
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front)); this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
} }
@ -1167,7 +1174,7 @@
} }
@Override @Override
@@ -1396,13 +1896,44 @@ @@ -1396,13 +1897,44 @@
if (factory == null) { if (factory == null) {
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -1212,7 +1219,7 @@
if (container == null) { if (container == null) {
if (this.isSpectator()) { if (this.isSpectator()) {
this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true); this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true);
@@ -1410,9 +1941,11 @@ @@ -1410,9 +1942,11 @@
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -1226,7 +1233,7 @@
return OptionalInt.of(this.containerCounter); return OptionalInt.of(this.containerCounter);
} }
} }
@@ -1425,15 +1958,26 @@ @@ -1425,15 +1959,26 @@
@Override @Override
public void openHorseInventory(AbstractHorse horse, Container inventory) { public void openHorseInventory(AbstractHorse horse, Container inventory) {
@ -1256,7 +1263,7 @@
this.initMenu(this.containerMenu); this.initMenu(this.containerMenu);
} }
@@ -1456,9 +2000,28 @@ @@ -1456,9 +2001,28 @@
@Override @Override
public void closeContainer() { public void closeContainer() {
@ -1285,7 +1292,7 @@
@Override @Override
public void doCloseContainer() { public void doCloseContainer() {
@@ -1485,19 +2048,19 @@ @@ -1485,19 +2049,19 @@
i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F); i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F);
if (i > 0) { if (i > 0) {
this.awardStat(Stats.SWIM_ONE_CM, i); this.awardStat(Stats.SWIM_ONE_CM, i);
@ -1308,7 +1315,7 @@
} }
} else if (this.onClimbable()) { } else if (this.onClimbable()) {
if (deltaY > 0.0D) { if (deltaY > 0.0D) {
@@ -1508,13 +2071,13 @@ @@ -1508,13 +2072,13 @@
if (i > 0) { if (i > 0) {
if (this.isSprinting()) { if (this.isSprinting()) {
this.awardStat(Stats.SPRINT_ONE_CM, i); this.awardStat(Stats.SPRINT_ONE_CM, i);
@ -1325,7 +1332,7 @@
} }
} }
} else if (this.isFallFlying()) { } else if (this.isFallFlying()) {
@@ -1557,7 +2120,7 @@ @@ -1557,7 +2121,7 @@
@Override @Override
public void awardStat(Stat<?> stat, int amount) { public void awardStat(Stat<?> stat, int amount) {
this.stats.increment(this, stat, amount); this.stats.increment(this, stat, amount);
@ -1334,7 +1341,7 @@
scoreaccess.add(amount); scoreaccess.add(amount);
}); });
} }
@@ -1565,7 +2128,7 @@ @@ -1565,7 +2129,7 @@
@Override @Override
public void resetStat(Stat<?> stat) { public void resetStat(Stat<?> stat) {
this.stats.setValue(this, stat, 0); this.stats.setValue(this, stat, 0);
@ -1343,7 +1350,7 @@
} }
@Override @Override
@@ -1597,9 +2160,9 @@ @@ -1597,9 +2161,9 @@
super.jumpFromGround(); super.jumpFromGround();
this.awardStat(Stats.JUMP); this.awardStat(Stats.JUMP);
if (this.isSprinting()) { if (this.isSprinting()) {
@ -1355,7 +1362,7 @@
} }
} }
@@ -1613,6 +2176,13 @@ @@ -1613,6 +2177,13 @@
public void disconnect() { public void disconnect() {
this.disconnected = true; this.disconnected = true;
this.ejectPassengers(); this.ejectPassengers();
@ -1369,7 +1376,7 @@
if (this.isSleeping()) { if (this.isSleeping()) {
this.stopSleepInBed(true, false); this.stopSleepInBed(true, false);
} }
@@ -1625,6 +2195,7 @@ @@ -1625,6 +2196,7 @@
public void resetSentInfo() { public void resetSentInfo() {
this.lastSentHealth = -1.0E8F; this.lastSentHealth = -1.0E8F;
@ -1377,7 +1384,7 @@
} }
@Override @Override
@@ -1661,7 +2232,7 @@ @@ -1661,7 +2233,7 @@
this.onUpdateAbilities(); this.onUpdateAbilities();
if (alive) { if (alive) {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1386,7 +1393,7 @@
this.setHealth(oldPlayer.getHealth()); this.setHealth(oldPlayer.getHealth());
this.foodData = oldPlayer.foodData; this.foodData = oldPlayer.foodData;
Iterator iterator = oldPlayer.getActiveEffects().iterator(); Iterator iterator = oldPlayer.getActiveEffects().iterator();
@@ -1669,7 +2240,7 @@ @@ -1669,7 +2241,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next(); MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
@ -1395,7 +1402,7 @@
} }
this.getInventory().replaceWith(oldPlayer.getInventory()); this.getInventory().replaceWith(oldPlayer.getInventory());
@@ -1680,7 +2251,7 @@ @@ -1680,7 +2252,7 @@
this.portalProcess = oldPlayer.portalProcess; this.portalProcess = oldPlayer.portalProcess;
} else { } else {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1404,7 +1411,7 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) { if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) {
this.getInventory().replaceWith(oldPlayer.getInventory()); this.getInventory().replaceWith(oldPlayer.getInventory());
this.experienceLevel = oldPlayer.experienceLevel; this.experienceLevel = oldPlayer.experienceLevel;
@@ -1696,7 +2267,7 @@ @@ -1696,7 +2268,7 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -1413,7 +1420,7 @@
this.seenCredits = oldPlayer.seenCredits; this.seenCredits = oldPlayer.seenCredits;
this.enteredNetherPosition = oldPlayer.enteredNetherPosition; this.enteredNetherPosition = oldPlayer.enteredNetherPosition;
this.chunkTrackingView = oldPlayer.chunkTrackingView; this.chunkTrackingView = oldPlayer.chunkTrackingView;
@@ -1752,19 +2323,19 @@ @@ -1752,19 +2324,19 @@
} }
@Override @Override
@ -1437,7 +1444,7 @@
} }
return flag1; return flag1;
@@ -1799,10 +2370,18 @@ @@ -1799,10 +2371,18 @@
} }
public boolean setGameMode(GameType gameMode) { public boolean setGameMode(GameType gameMode) {
@ -1458,7 +1465,7 @@
} else { } else {
this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gameMode.getId())); this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gameMode.getId()));
if (gameMode == GameType.SPECTATOR) { if (gameMode == GameType.SPECTATOR) {
@@ -1818,7 +2397,7 @@ @@ -1818,7 +2398,7 @@
this.onUpdateAbilities(); this.onUpdateAbilities();
this.updateEffectVisibility(); this.updateEffectVisibility();
@ -1467,7 +1474,7 @@
} }
} }
@@ -1861,8 +2440,13 @@ @@ -1861,8 +2441,13 @@
} }
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) { public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
@ -1482,7 +1489,7 @@
} }
} }
@@ -1878,7 +2462,36 @@ @@ -1878,7 +2463,36 @@
} }
public void updateOptions(ClientInformation clientOptions) { public void updateOptions(ClientInformation clientOptions) {
@ -1519,7 +1526,7 @@
this.requestedViewDistance = clientOptions.viewDistance(); this.requestedViewDistance = clientOptions.viewDistance();
this.chatVisibility = clientOptions.chatVisibility(); this.chatVisibility = clientOptions.chatVisibility();
this.canChatColor = clientOptions.chatColors(); this.canChatColor = clientOptions.chatColors();
@@ -1957,12 +2570,27 @@ @@ -1957,12 +2571,27 @@
this.camera = (Entity) (entity == null ? this : entity); this.camera = (Entity) (entity == null ? this : entity);
if (entity1 != this.camera) { if (entity1 != this.camera) {
@ -1548,7 +1555,7 @@
} }
if (entity != null) { if (entity != null) {
@@ -1999,11 +2627,11 @@ @@ -1999,11 +2628,11 @@
@Nullable @Nullable
public Component getTabListDisplayName() { public Component getTabListDisplayName() {
@ -1562,7 +1569,7 @@
} }
@Override @Override
@@ -2045,12 +2673,44 @@ @@ -2045,12 +2674,44 @@
this.setRespawnPosition(player.getRespawnDimension(), player.getRespawnPosition(), player.getRespawnAngle(), player.isRespawnForced(), false); this.setRespawnPosition(player.getRespawnDimension(), player.getRespawnPosition(), player.getRespawnAngle(), player.isRespawnForced(), false);
} }
@ -1609,7 +1616,7 @@
} }
this.respawnPosition = pos; this.respawnPosition = pos;
@@ -2064,6 +2724,7 @@ @@ -2064,6 +2725,7 @@
this.respawnForced = false; this.respawnForced = false;
} }
@ -1617,7 +1624,7 @@
} }
public SectionPos getLastSectionPos() { public SectionPos getLastSectionPos() {
@@ -2088,18 +2749,44 @@ @@ -2088,18 +2750,44 @@
} }
@Override @Override
@ -1666,7 +1673,7 @@
} }
this.awardStat(Stats.DROP); this.awardStat(Stats.DROP);
@@ -2115,6 +2802,11 @@ @@ -2115,6 +2803,11 @@
return null; return null;
} else { } else {
double d0 = this.getEyeY() - 0.30000001192092896D; double d0 = this.getEyeY() - 0.30000001192092896D;
@ -1678,7 +1685,7 @@
ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), d0, this.getZ(), stack); ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), d0, this.getZ(), stack);
entityitem.setPickUpDelay(40); entityitem.setPickUpDelay(40);
@@ -2166,6 +2858,16 @@ @@ -2166,6 +2859,16 @@
} }
public void loadGameTypes(@Nullable CompoundTag nbt) { public void loadGameTypes(@Nullable CompoundTag nbt) {
@ -1695,7 +1702,7 @@
this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType")); this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType"));
} }
@@ -2275,9 +2977,15 @@ @@ -2275,9 +2978,15 @@
@Override @Override
public void stopRiding() { public void stopRiding() {
@ -1712,7 +1719,12 @@
if (entity instanceof LivingEntity entityliving) { if (entity instanceof LivingEntity entityliving) {
Iterator iterator = entityliving.getActiveEffects().iterator(); Iterator iterator = entityliving.getActiveEffects().iterator();
@@ -2375,16 +3083,161 @@ @@ -2371,20 +3080,165 @@
}
public static long placeEnderPearlTicket(ServerLevel world, ChunkPos chunkPos) {
- world.getChunkSource().addRegionTicket(TicketType.ENDER_PEARL, chunkPos, 2, chunkPos);
+ if (!world.paperConfig().misc.legacyEnderPearlBehavior) world.getChunkSource().addRegionTicket(TicketType.ENDER_PEARL, chunkPos, 2, chunkPos); // Paper - Allow using old ender pearl behavior
return TicketType.ENDER_PEARL.timeout(); return TicketType.ENDER_PEARL.timeout();
} }

View File

@ -405,7 +405,7 @@
if (advancementdataplayer != null) { if (advancementdataplayer != null) {
advancementdataplayer.save(); advancementdataplayer.save();
@@ -334,95 +533,210 @@ @@ -334,95 +533,216 @@
} }
@ -488,7 +488,13 @@
ThrownEnderpearl entityenderpearl = (ThrownEnderpearl) iterator.next(); ThrownEnderpearl entityenderpearl = (ThrownEnderpearl) iterator.next();
- entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER); - entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER);
+ // Paper start - Allow using old ender pearl behavior
+ if (!entityenderpearl.level().paperConfig().misc.legacyEnderPearlBehavior) {
+ entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER, EntityRemoveEvent.Cause.PLAYER_QUIT); // CraftBukkit - add Bukkit remove cause + entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER, EntityRemoveEvent.Cause.PLAYER_QUIT); // CraftBukkit - add Bukkit remove cause
+ } else {
+ entityenderpearl.cachedOwner = null;
+ }
+ // Paper end - Allow using old ender pearl behavior
} }
- worldserver.removePlayerImmediately(player, Entity.RemovalReason.UNLOADED_WITH_PLAYER); - worldserver.removePlayerImmediately(player, Entity.RemovalReason.UNLOADED_WITH_PLAYER);
@ -654,7 +660,7 @@
if (entityplayer1 != null) { if (entityplayer1 != null) {
set.add(entityplayer1); set.add(entityplayer1);
@@ -431,72 +745,160 @@ @@ -431,72 +751,160 @@
Iterator iterator1 = set.iterator(); Iterator iterator1 = set.iterator();
while (iterator1.hasNext()) { while (iterator1.hasNext()) {
@ -836,7 +842,7 @@
return entityplayer1; return entityplayer1;
} }
@@ -516,15 +918,32 @@ @@ -516,15 +924,32 @@
} }
public void sendPlayerPermissionLevel(ServerPlayer player) { public void sendPlayerPermissionLevel(ServerPlayer player) {
@ -871,10 +877,14 @@
this.sendAllPlayerInfoIn = 0; this.sendAllPlayerInfoIn = 0;
} }
@@ -541,6 +960,25 @@ @@ -537,9 +962,28 @@
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
}
entityplayer.connection.send(packet);
+ }
+
+ }
+
+ // CraftBukkit start - add a world/entity limited version + // CraftBukkit start - add a world/entity limited version
+ public void broadcastAll(Packet packet, net.minecraft.world.entity.player.Player entityhuman) { + public void broadcastAll(Packet packet, net.minecraft.world.entity.player.Player entityhuman) {
+ for (int i = 0; i < this.players.size(); ++i) { + for (int i = 0; i < this.players.size(); ++i) {
@ -889,15 +899,14 @@
+ public void broadcastAll(Packet packet, Level world) { + public void broadcastAll(Packet packet, Level world) {
+ for (int i = 0; i < world.players().size(); ++i) { + for (int i = 0; i < world.players().size(); ++i) {
+ ((ServerPlayer) world.players().get(i)).connection.send(packet); + ((ServerPlayer) world.players().get(i)).connection.send(packet);
+ } }
+
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) { public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
Iterator iterator = this.players.iterator(); Iterator iterator = this.players.iterator();
@@ -554,7 +998,7 @@
@@ -554,7 +992,7 @@
} }
@ -906,7 +915,7 @@
PlayerTeam scoreboardteam = source.getTeam(); PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam != null) { if (scoreboardteam != null) {
@@ -573,7 +1011,7 @@ @@ -573,7 +1017,7 @@
} }
} }
@ -915,7 +924,7 @@
PlayerTeam scoreboardteam = source.getTeam(); PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam == null) { if (scoreboardteam == null) {
@@ -619,7 +1057,7 @@ @@ -619,7 +1063,7 @@
} }
public void deop(GameProfile profile) { public void deop(GameProfile profile) {
@ -924,7 +933,7 @@
ServerPlayer entityplayer = this.getPlayer(profile.getId()); ServerPlayer entityplayer = this.getPlayer(profile.getId());
if (entityplayer != null) { if (entityplayer != null) {
@@ -629,6 +1067,11 @@ @@ -629,6 +1073,11 @@
} }
private void sendPlayerPermissionLevel(ServerPlayer player, int permissionLevel) { private void sendPlayerPermissionLevel(ServerPlayer player, int permissionLevel) {
@ -936,7 +945,7 @@
if (player.connection != null) { if (player.connection != null) {
byte b0; byte b0;
@@ -643,35 +1086,52 @@ @@ -643,36 +1092,53 @@
player.connection.send(new ClientboundEntityEventPacket(player, b0)); player.connection.send(new ClientboundEntityEventPacket(player, b0));
} }
@ -993,16 +1002,17 @@
+ public void broadcast(@Nullable net.minecraft.world.entity.player.Player player, double x, double y, double z, double distance, ResourceKey<Level> worldKey, Packet<?> packet) { + public void broadcast(@Nullable net.minecraft.world.entity.player.Player player, double x, double y, double z, double distance, ResourceKey<Level> worldKey, Packet<?> packet) {
for (int i = 0; i < this.players.size(); ++i) { for (int i = 0; i < this.players.size(); ++i) {
ServerPlayer entityplayer = (ServerPlayer) this.players.get(i); ServerPlayer entityplayer = (ServerPlayer) this.players.get(i);
+
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet + // CraftBukkit start - Test if player receiving packet can see the source of the packet
+ if (player != null && !entityplayer.getBukkitEntity().canSee(player.getBukkitEntity())) { + if (player != null && !entityplayer.getBukkitEntity().canSee(player.getBukkitEntity())) {
+ continue; + continue;
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+
if (entityplayer != player && entityplayer.level().dimension() == worldKey) { if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
double d4 = x - entityplayer.getX(); double d4 = x - entityplayer.getX();
@@ -687,10 +1147,12 @@ double d5 = y - entityplayer.getY();
@@ -687,10 +1153,12 @@
} }
public void saveAll() { public void saveAll() {
@ -1015,7 +1025,7 @@
} }
public UserWhiteList getWhiteList() { public UserWhiteList getWhiteList() {
@@ -712,15 +1174,19 @@ @@ -712,15 +1180,19 @@
public void reloadWhiteList() {} public void reloadWhiteList() {}
public void sendLevelInfo(ServerPlayer player, ServerLevel world) { public void sendLevelInfo(ServerPlayer player, ServerLevel world) {
@ -1039,7 +1049,7 @@
} }
player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F)); player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F));
@@ -729,8 +1195,16 @@ @@ -729,8 +1201,16 @@
public void sendAllPlayerInfo(ServerPlayer player) { public void sendAllPlayerInfo(ServerPlayer player) {
player.inventoryMenu.sendAllDataToRemote(); player.inventoryMenu.sendAllDataToRemote();
@ -1057,7 +1067,7 @@
} }
public int getPlayerCount() { public int getPlayerCount() {
@@ -746,6 +1220,7 @@ @@ -746,6 +1226,7 @@
} }
public void setUsingWhiteList(boolean whitelistEnabled) { public void setUsingWhiteList(boolean whitelistEnabled) {
@ -1065,7 +1075,7 @@
this.doWhiteList = whitelistEnabled; this.doWhiteList = whitelistEnabled;
} }
@@ -786,12 +1261,36 @@ @@ -786,11 +1267,35 @@
} }
public void removeAll() { public void removeAll() {
@ -1081,30 +1091,29 @@
+ for (ServerPlayer player : this.players) { + for (ServerPlayer player : this.players) {
+ if (isRestarting) player.connection.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.restartMessage), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN); else // Paper - kick event cause (cause is never used here) + if (isRestarting) player.connection.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.restartMessage), org.bukkit.event.player.PlayerKickEvent.Cause.UNKNOWN); else // Paper - kick event cause (cause is never used here)
+ player.connection.disconnect(java.util.Objects.requireNonNullElseGet(this.server.server.shutdownMessage(), net.kyori.adventure.text.Component::empty)); // CraftBukkit - add custom shutdown message // Paper - Adventure + player.connection.disconnect(java.util.Objects.requireNonNullElseGet(this.server.server.shutdownMessage(), net.kyori.adventure.text.Component::empty)); // CraftBukkit - add custom shutdown message // Paper - Adventure
} + }
+ // CraftBukkit end + // CraftBukkit end
+
+ // Paper start - Configurable player collision; Remove collideRule team if it exists + // Paper start - Configurable player collision; Remove collideRule team if it exists
+ if (this.collideRuleTeamName != null) { + if (this.collideRuleTeamName != null) {
+ final net.minecraft.world.scores.Scoreboard scoreboard = this.getServer().getLevel(Level.OVERWORLD).getScoreboard(); + final net.minecraft.world.scores.Scoreboard scoreboard = this.getServer().getLevel(Level.OVERWORLD).getScoreboard();
+ final PlayerTeam team = scoreboard.getPlayersTeam(this.collideRuleTeamName); + final PlayerTeam team = scoreboard.getPlayersTeam(this.collideRuleTeamName);
+ if (team != null) scoreboard.removePlayerTeam(team); + if (team != null) scoreboard.removePlayerTeam(team);
+ } }
+ // Paper end - Configurable player collision + // Paper end - Configurable player collision
} + }
+ // CraftBukkit start + // CraftBukkit start
+ public void broadcastMessage(Component[] iChatBaseComponents) { + public void broadcastMessage(Component[] iChatBaseComponents) {
+ for (Component component : iChatBaseComponents) { + for (Component component : iChatBaseComponents) {
+ this.broadcastSystemMessage(component, false); + this.broadcastSystemMessage(component, false);
+ } + }
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
public void broadcastSystemMessage(Component message, boolean overlay) { public void broadcastSystemMessage(Component message, boolean overlay) {
this.broadcastSystemMessage(message, (entityplayer) -> { this.broadcastSystemMessage(message, (entityplayer) -> {
return message; @@ -819,24 +1324,43 @@
@@ -819,24 +1318,43 @@
} }
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) { public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
@ -1151,7 +1160,7 @@
} }
if (flag1 && sender != null) { if (flag1 && sender != null) {
@@ -845,20 +1363,27 @@ @@ -845,20 +1369,27 @@
} }
@ -1184,7 +1193,7 @@
Path path = file2.toPath(); Path path = file2.toPath();
if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) { if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
@@ -867,7 +1392,7 @@ @@ -867,7 +1398,7 @@
} }
serverstatisticmanager = new ServerStatsCounter(this.server, file1); serverstatisticmanager = new ServerStatsCounter(this.server, file1);
@ -1193,7 +1202,7 @@
} }
return serverstatisticmanager; return serverstatisticmanager;
@@ -875,13 +1400,13 @@ @@ -875,13 +1406,13 @@
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) { public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
UUID uuid = player.getUUID(); UUID uuid = player.getUUID();
@ -1209,7 +1218,7 @@
} }
advancementdataplayer.setPlayer(player); advancementdataplayer.setPlayer(player);
@@ -932,15 +1457,39 @@ @@ -932,15 +1463,39 @@
} }
public void reloadResources() { public void reloadResources() {

View File

@ -75,6 +75,15 @@
break label30; break label30;
} }
} }
@@ -240,7 +252,7 @@
Entity entity = super.teleport(teleportTarget);
if (entity != null) {
- entity.placePortalTicket(BlockPos.containing(entity.position()));
+ if (!this.level().paperConfig().misc.legacyEnderPearlBehavior) entity.placePortalTicket(BlockPos.containing(entity.position())); // Paper - Allow using old ender pearl behavior
}
return entity;
@@ -248,7 +260,7 @@ @@ -248,7 +260,7 @@
@Override @Override