Add API for quit reason

This commit is contained in:
Mariell Hoversholm 2020-11-14 16:19:52 +01:00
parent 5b1f73e2dc
commit 4b0e4655fd
4 changed files with 107 additions and 84 deletions

View file

@ -65,7 +65,26 @@
if (this.delayedDisconnect != null) { if (this.delayedDisconnect != null) {
this.disconnect(this.delayedDisconnect); this.disconnect(this.delayedDisconnect);
} }
@@ -176,6 +202,7 @@ @@ -141,8 +167,10 @@
this.handlingFault = true;
if (this.channel.isOpen()) {
+ net.minecraft.server.level.ServerPlayer player = this.getPlayer(); // Paper - Add API for quit reason
if (throwable instanceof TimeoutException) {
Connection.LOGGER.debug("Timeout", throwable);
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.TIMED_OUT; // Paper - Add API for quit reason
this.disconnect((Component) Component.translatable("disconnect.timeout"));
} else {
MutableComponent ichatmutablecomponent = Component.translatable("disconnect.genericReason", "Internal Exception: " + String.valueOf(throwable));
@@ -155,6 +183,7 @@
disconnectiondetails = new DisconnectionDetails(ichatmutablecomponent);
}
+ if (player != null) player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.ERRONEOUS_STATE; // Paper - Add API for quit reason
if (flag) {
Connection.LOGGER.debug("Failed to sent packet", throwable);
if (this.getSending() == PacketFlow.CLIENTBOUND) {
@@ -176,6 +205,7 @@
} }
} }
@ -73,7 +92,7 @@
} }
protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet<?> packet) { protected void channelRead0(ChannelHandlerContext channelhandlercontext, Packet<?> packet) {
@@ -205,7 +232,7 @@ @@ -205,7 +235,7 @@
} }
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener listener) { private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener listener) {
@ -82,7 +101,7 @@
} }
private void validateListener(ProtocolInfo<?> state, PacketListener listener) { private void validateListener(ProtocolInfo<?> state, PacketListener listener) {
@@ -418,12 +445,26 @@ @@ -418,12 +448,26 @@
} }
} }
@ -109,7 +128,7 @@
} }
if (!this.isConnected() && !this.disconnectionHandled) { if (!this.isConnected() && !this.disconnectionHandled) {
@@ -431,7 +472,7 @@ @@ -431,7 +475,7 @@
} }
if (this.channel != null) { if (this.channel != null) {
@ -118,7 +137,7 @@
} }
if (this.tickCount++ % 20 == 0) { if (this.tickCount++ % 20 == 0) {
@@ -464,12 +505,15 @@ @@ -464,12 +508,15 @@
} }
public void disconnect(DisconnectionDetails disconnectionInfo) { public void disconnect(DisconnectionDetails disconnectionInfo) {
@ -135,7 +154,7 @@
this.disconnectionDetails = disconnectionInfo; this.disconnectionDetails = disconnectionInfo;
} }
@@ -537,7 +581,7 @@ @@ -537,7 +584,7 @@
} }
public void configurePacketHandler(ChannelPipeline pipeline) { public void configurePacketHandler(ChannelPipeline pipeline) {
@ -144,7 +163,7 @@
public void write(ChannelHandlerContext channelhandlercontext, Object object, ChannelPromise channelpromise) throws Exception { public void write(ChannelHandlerContext channelhandlercontext, Object object, ChannelPromise channelpromise) throws Exception {
super.write(channelhandlercontext, object, channelpromise); super.write(channelhandlercontext, object, channelpromise);
} }
@@ -661,6 +705,27 @@ @@ -661,6 +708,27 @@
packetlistener1.onDisconnect(disconnectiondetails); packetlistener1.onDisconnect(disconnectiondetails);
} }

View file

@ -114,7 +114,7 @@
@Nullable @Nullable
private Vec3 startingToFallPosition; private Vec3 startingToFallPosition;
@Nullable @Nullable
@@ -258,7 +293,35 @@ @@ -258,7 +293,36 @@
private final CommandSource commandSource; private final CommandSource commandSource;
private int containerCounter; private int containerCounter;
public boolean wonGame; public boolean wonGame;
@ -146,11 +146,12 @@
+ public boolean isRealPlayer; // Paper + public boolean isRealPlayer; // Paper
+ 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 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; this.chatVisibility = ChatVisiblity.FULL;
@@ -266,7 +329,7 @@ @@ -266,7 +330,7 @@
this.canChatColor = true; this.canChatColor = true;
this.lastActionTime = Util.getMillis(); this.lastActionTime = Util.getMillis();
this.requestedViewDistance = 2; this.requestedViewDistance = 2;
@ -159,7 +160,7 @@
this.lastSectionPos = SectionPos.of(0, 0, 0); this.lastSectionPos = SectionPos.of(0, 0, 0);
this.chunkTrackingView = ChunkTrackingView.EMPTY; this.chunkTrackingView = ChunkTrackingView.EMPTY;
this.respawnDimension = Level.OVERWORLD; this.respawnDimension = Level.OVERWORLD;
@@ -340,6 +403,13 @@ @@ -340,6 +404,13 @@
public void sendSystemMessage(Component message) { public void sendSystemMessage(Component message) {
ServerPlayer.this.sendSystemMessage(message); ServerPlayer.this.sendSystemMessage(message);
} }
@ -173,7 +174,7 @@
}; };
this.textFilter = server.createTextFilterForPlayer(this); this.textFilter = server.createTextFilterForPlayer(this);
this.gameMode = server.createGameModeForPlayer(this); this.gameMode = server.createGameModeForPlayer(this);
@@ -349,17 +419,71 @@ @@ -349,17 +420,71 @@
this.server = server; this.server = server;
this.stats = server.getPlayerList().getPlayerStats(this); this.stats = server.getPlayerList().getPlayerStats(this);
this.advancements = server.getPlayerList().getPlayerAdvancements(this); this.advancements = server.getPlayerList().getPlayerAdvancements(this);
@ -188,8 +189,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
+ public void resendItemInHands() { + public void resendItemInHands() {
@ -235,9 +236,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);
@ -248,7 +249,7 @@
int i = Math.max(0, this.server.getSpawnRadius(world)); int i = Math.max(0, this.server.getSpawnRadius(world));
int j = Mth.floor(world.getWorldBorder().getDistanceToBorder((double) basePos.getX(), (double) basePos.getZ())); int j = Mth.floor(world.getWorldBorder().getDistanceToBorder((double) basePos.getX(), (double) basePos.getZ()));
@@ -395,14 +519,20 @@ @@ -395,14 +520,20 @@
Objects.requireNonNull(basePos); Objects.requireNonNull(basePos);
crashreportsystemdetails.setDetail("Origin", basePos::toString); crashreportsystemdetails.setDetail("Origin", basePos::toString);
@ -271,7 +272,7 @@
}); });
throw new ReportedException(crashreport); throw new ReportedException(crashreport);
} }
@@ -440,7 +570,7 @@ @@ -440,7 +571,7 @@
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(NbtOps.INSTANCE, nbt.get("warden_spawn_tracker"))); dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(NbtOps.INSTANCE, nbt.get("warden_spawn_tracker")));
logger = ServerPlayer.LOGGER; logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@ -280,7 +281,7 @@
this.wardenSpawnTracker = wardenspawntracker; this.wardenSpawnTracker = wardenspawntracker;
}); });
} }
@@ -457,17 +587,26 @@ @@ -457,17 +588,26 @@
return this.server.getRecipeManager().byKey(resourcekey).isPresent(); return this.server.getRecipeManager().byKey(resourcekey).isPresent();
}); });
} }
@ -308,7 +309,7 @@
Logger logger1 = ServerPlayer.LOGGER; Logger logger1 = ServerPlayer.LOGGER;
Objects.requireNonNull(logger1); Objects.requireNonNull(logger1);
@@ -482,7 +621,7 @@ @@ -482,7 +622,7 @@
dataresult = BlockPos.CODEC.parse(NbtOps.INSTANCE, nbtbase); dataresult = BlockPos.CODEC.parse(NbtOps.INSTANCE, nbtbase);
logger = ServerPlayer.LOGGER; logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@ -317,7 +318,7 @@
this.raidOmenPosition = blockposition; this.raidOmenPosition = blockposition;
}); });
} }
@@ -492,7 +631,7 @@ @@ -492,7 +632,7 @@
@Override @Override
public void addAdditionalSaveData(CompoundTag nbt) { public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt); super.addAdditionalSaveData(nbt);
@ -326,7 +327,7 @@
Logger logger = ServerPlayer.LOGGER; Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -526,6 +665,7 @@ @@ -526,6 +666,7 @@
nbt.put("SpawnDimension", nbtbase); nbt.put("SpawnDimension", nbtbase);
}); });
} }
@ -334,7 +335,7 @@
nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall); nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
if (this.raidOmenPosition != null) { if (this.raidOmenPosition != null) {
@@ -544,7 +684,20 @@ @@ -544,7 +685,20 @@
Entity entity = this.getRootVehicle(); Entity entity = this.getRootVehicle();
Entity entity1 = this.getVehicle(); Entity entity1 = this.getVehicle();
@ -356,7 +357,7 @@
CompoundTag nbttagcompound1 = new CompoundTag(); CompoundTag nbttagcompound1 = new CompoundTag();
CompoundTag nbttagcompound2 = new CompoundTag(); CompoundTag nbttagcompound2 = new CompoundTag();
@@ -564,7 +717,7 @@ @@ -564,7 +718,7 @@
ServerLevel worldserver = (ServerLevel) world; ServerLevel worldserver = (ServerLevel) world;
CompoundTag nbttagcompound = ((CompoundTag) nbt.get()).getCompound("RootVehicle"); CompoundTag nbttagcompound = ((CompoundTag) nbt.get()).getCompound("RootVehicle");
Entity entity = EntityType.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver, EntitySpawnReason.LOAD, (entity1) -> { Entity entity = EntityType.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver, EntitySpawnReason.LOAD, (entity1) -> {
@ -365,7 +366,7 @@
}); });
if (entity == null) { if (entity == null) {
@@ -598,12 +751,12 @@ @@ -598,12 +752,12 @@
if (!this.isPassenger()) { if (!this.isPassenger()) {
ServerPlayer.LOGGER.warn("Couldn't reattach entity to player"); ServerPlayer.LOGGER.warn("Couldn't reattach entity to player");
@ -380,7 +381,7 @@
} }
} }
} }
@@ -625,7 +778,7 @@ @@ -625,7 +779,7 @@
CompoundTag nbttagcompound1 = new CompoundTag(); CompoundTag nbttagcompound1 = new CompoundTag();
entityenderpearl.save(nbttagcompound1); entityenderpearl.save(nbttagcompound1);
@ -389,7 +390,7 @@
Logger logger = ServerPlayer.LOGGER; Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -651,7 +804,7 @@ @@ -651,7 +805,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")) {
@ -398,7 +399,7 @@
Logger logger = ServerPlayer.LOGGER; Logger logger = ServerPlayer.LOGGER;
Objects.requireNonNull(logger); Objects.requireNonNull(logger);
@@ -686,6 +839,29 @@ @@ -686,6 +840,29 @@
} }
@ -428,7 +429,7 @@
public void setExperiencePoints(int points) { public void setExperiencePoints(int points) {
float f = (float) this.getXpNeededForNextLevel(); float f = (float) this.getXpNeededForNextLevel();
float f1 = (f - 1.0F) / f; float f1 = (f - 1.0F) / f;
@@ -744,6 +920,11 @@ @@ -744,6 +921,11 @@
@Override @Override
public void tick() { public void tick() {
@ -440,7 +441,7 @@
this.tickClientLoadTimeout(); this.tickClientLoadTimeout();
this.gameMode.tick(); this.gameMode.tick();
this.wardenSpawnTracker.tick(); this.wardenSpawnTracker.tick();
@@ -751,9 +932,13 @@ @@ -751,9 +933,13 @@
--this.invulnerableTime; --this.invulnerableTime;
} }
@ -457,7 +458,7 @@
this.containerMenu = this.inventoryMenu; this.containerMenu = this.inventoryMenu;
} }
@@ -807,7 +992,7 @@ @@ -807,7 +993,7 @@
public void doTick() { public void doTick() {
try { try {
@ -466,7 +467,7 @@
super.tick(); super.tick();
} }
@@ -820,7 +1005,7 @@ @@ -820,7 +1006,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) {
@ -475,7 +476,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 +1036,12 @@ @@ -851,6 +1037,12 @@
this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience)); this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience));
} }
@ -488,10 +489,12 @@
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 +1056,20 @@ @@ -863,8 +1055,22 @@
CriteriaTriggers.LOCATION.trigger(this);
}
if (this.tickCount % 20 == 0) {
CriteriaTriggers.LOCATION.trigger(this);
+ }
+
+ // CraftBukkit start - initialize oldLevel, fire PlayerLevelChangeEvent, and tick client-sided world border + // CraftBukkit start - initialize oldLevel, fire PlayerLevelChangeEvent, and tick client-sided world border
+ if (this.oldLevel == -1) { + if (this.oldLevel == -1) {
+ this.oldLevel = this.experienceLevel; + this.oldLevel = this.experienceLevel;
@ -500,8 +503,8 @@
+ if (this.oldLevel != this.experienceLevel) { + if (this.oldLevel != this.experienceLevel) {
+ CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel); + CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel);
+ this.oldLevel = this.experienceLevel; + this.oldLevel = this.experienceLevel;
+ } }
+
+ if (this.getBukkitEntity().hasClientWorldBorder()) { + if (this.getBukkitEntity().hasClientWorldBorder()) {
+ ((CraftWorldBorder) this.getBukkitEntity().getWorldBorder()).getHandle().tick(); + ((CraftWorldBorder) this.getBukkitEntity().getWorldBorder()).getHandle().tick();
+ } + }
@ -509,7 +512,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 +1098,7 @@ @@ -893,7 +1099,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()) {
@ -518,7 +521,7 @@
} }
float f = this.foodData.getSaturationLevel(); float f = this.foodData.getSaturationLevel();
@@ -946,19 +1151,103 @@ @@ -946,19 +1152,103 @@
} }
private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) { private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) {
@ -626,7 +629,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 +1277,23 @@ @@ -988,12 +1278,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();
} }
@ -654,7 +657,7 @@
LivingEntity entityliving = this.getKillCredit(); LivingEntity entityliving = this.getKillCredit();
if (entityliving != null) { if (entityliving != null) {
@@ -1028,10 +1328,12 @@ @@ -1028,10 +1329,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);
@ -670,7 +673,7 @@
} else { } else {
this.awardStat(Stats.MOB_KILLS); this.awardStat(Stats.MOB_KILLS);
} }
@@ -1049,7 +1351,8 @@ @@ -1049,7 +1352,8 @@
int i = scoreboardteam.getColor().getId(); int i = scoreboardteam.getColor().getId();
if (i >= 0 && i < criterions.length) { if (i >= 0 && i < criterions.length) {
@ -680,7 +683,7 @@
} }
} }
@@ -1062,8 +1365,8 @@ @@ -1062,8 +1366,8 @@
} else { } else {
Entity entity = source.getEntity(); Entity entity = source.getEntity();
@ -691,7 +694,7 @@
if (!this.canHarmPlayer(entityhuman)) { if (!this.canHarmPlayer(entityhuman)) {
return false; return false;
@@ -1074,8 +1377,8 @@ @@ -1074,8 +1378,8 @@
AbstractArrow entityarrow = (AbstractArrow) entity; AbstractArrow entityarrow = (AbstractArrow) entity;
Entity entity1 = entityarrow.getOwner(); Entity entity1 = entityarrow.getOwner();
@ -702,7 +705,7 @@
if (!this.canHarmPlayer(entityhuman1)) { if (!this.canHarmPlayer(entityhuman1)) {
return false; return false;
@@ -1083,38 +1386,78 @@ @@ -1083,38 +1387,78 @@
} }
} }
@ -789,7 +792,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 +1472,11 @@ @@ -1129,11 +1473,11 @@
} }
return optional.map((vec3d) -> { return optional.map((vec3d) -> {
@ -803,7 +806,7 @@
}); });
} else if (!spawnForced) { } else if (!spawnForced) {
return Optional.empty(); return Optional.empty();
@@ -1142,7 +1485,7 @@ @@ -1142,7 +1486,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);
@ -812,7 +815,7 @@
} }
} }
@@ -1160,6 +1503,7 @@ @@ -1160,6 +1504,7 @@
@Nullable @Nullable
@Override @Override
public ServerPlayer teleport(TeleportTransition teleportTarget) { public ServerPlayer teleport(TeleportTransition teleportTarget) {
@ -820,7 +823,7 @@
if (this.isRemoved()) { if (this.isRemoved()) {
return null; return null;
} else { } else {
@@ -1169,39 +1513,78 @@ @@ -1169,39 +1514,78 @@
ServerLevel worldserver = teleportTarget.newLevel(); ServerLevel worldserver = teleportTarget.newLevel();
ServerLevel worldserver1 = this.serverLevel(); ServerLevel worldserver1 = this.serverLevel();
@ -907,7 +910,7 @@
this.connection.resetPosition(); this.connection.resetPosition();
worldserver.addDuringTeleport(this); worldserver.addDuringTeleport(this);
gameprofilerfiller.pop(); gameprofilerfiller.pop();
@@ -1215,12 +1598,30 @@ @@ -1215,12 +1599,30 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -938,7 +941,7 @@
public void forceSetRotation(float yaw, float pitch) { public void forceSetRotation(float yaw, float pitch) {
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch)); this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
} }
@@ -1228,13 +1629,21 @@ @@ -1228,13 +1630,21 @@
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();
@ -963,7 +966,7 @@
this.enteredNetherPosition = null; this.enteredNetherPosition = null;
} }
@@ -1251,36 +1660,63 @@ @@ -1251,36 +1661,63 @@
this.containerMenu.broadcastChanges(); this.containerMenu.broadcastChanges();
} }
@ -1042,7 +1045,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 +1729,8 @@ @@ -1293,9 +1730,8 @@
return either; return either;
} }
} }
@ -1053,7 +1056,7 @@
} }
@Override @Override
@@ -1322,13 +1757,31 @@ @@ -1322,13 +1758,31 @@
@Override @Override
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) { public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
@ -1086,7 +1089,7 @@
} }
} }
@@ -1387,8 +1840,9 @@ @@ -1387,8 +1841,9 @@
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front)); this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
} }
@ -1097,7 +1100,7 @@
} }
@Override @Override
@@ -1396,13 +1850,35 @@ @@ -1396,13 +1851,35 @@
if (factory == null) { if (factory == null) {
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -1133,7 +1136,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 +1886,11 @@ @@ -1410,9 +1887,11 @@
return OptionalInt.empty(); return OptionalInt.empty();
} else { } else {
@ -1147,7 +1150,7 @@
return OptionalInt.of(this.containerCounter); return OptionalInt.of(this.containerCounter);
} }
} }
@@ -1425,15 +1903,26 @@ @@ -1425,15 +1904,26 @@
@Override @Override
public void openHorseInventory(AbstractHorse horse, Container inventory) { public void openHorseInventory(AbstractHorse horse, Container inventory) {
@ -1177,7 +1180,7 @@
this.initMenu(this.containerMenu); this.initMenu(this.containerMenu);
} }
@@ -1456,6 +1945,13 @@ @@ -1456,6 +1946,13 @@
@Override @Override
public void closeContainer() { public void closeContainer() {
@ -1191,7 +1194,7 @@
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId)); this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
this.doCloseContainer(); this.doCloseContainer();
} }
@@ -1485,19 +1981,19 @@ @@ -1485,19 +1982,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);
@ -1214,7 +1217,7 @@
} }
} else if (this.onClimbable()) { } else if (this.onClimbable()) {
if (deltaY > 0.0D) { if (deltaY > 0.0D) {
@@ -1508,13 +2004,13 @@ @@ -1508,13 +2005,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);
@ -1231,7 +1234,7 @@
} }
} }
} else if (this.isFallFlying()) { } else if (this.isFallFlying()) {
@@ -1557,7 +2053,7 @@ @@ -1557,7 +2054,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);
@ -1240,7 +1243,7 @@
scoreaccess.add(amount); scoreaccess.add(amount);
}); });
} }
@@ -1565,7 +2061,7 @@ @@ -1565,7 +2062,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);
@ -1249,7 +1252,7 @@
} }
@Override @Override
@@ -1597,9 +2093,9 @@ @@ -1597,9 +2094,9 @@
super.jumpFromGround(); super.jumpFromGround();
this.awardStat(Stats.JUMP); this.awardStat(Stats.JUMP);
if (this.isSprinting()) { if (this.isSprinting()) {
@ -1261,7 +1264,7 @@
} }
} }
@@ -1613,6 +2109,13 @@ @@ -1613,6 +2110,13 @@
public void disconnect() { public void disconnect() {
this.disconnected = true; this.disconnected = true;
this.ejectPassengers(); this.ejectPassengers();
@ -1275,7 +1278,7 @@
if (this.isSleeping()) { if (this.isSleeping()) {
this.stopSleepInBed(true, false); this.stopSleepInBed(true, false);
} }
@@ -1625,6 +2128,7 @@ @@ -1625,6 +2129,7 @@
public void resetSentInfo() { public void resetSentInfo() {
this.lastSentHealth = -1.0E8F; this.lastSentHealth = -1.0E8F;
@ -1283,7 +1286,7 @@
} }
@Override @Override
@@ -1661,7 +2165,7 @@ @@ -1661,7 +2166,7 @@
this.onUpdateAbilities(); this.onUpdateAbilities();
if (alive) { if (alive) {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1292,7 +1295,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 +2173,7 @@ @@ -1669,7 +2174,7 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next(); MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
@ -1301,7 +1304,7 @@
} }
this.getInventory().replaceWith(oldPlayer.getInventory()); this.getInventory().replaceWith(oldPlayer.getInventory());
@@ -1680,7 +2184,7 @@ @@ -1680,7 +2185,7 @@
this.portalProcess = oldPlayer.portalProcess; this.portalProcess = oldPlayer.portalProcess;
} else { } else {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes()); this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@ -1310,7 +1313,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 +2200,7 @@ @@ -1696,7 +2201,7 @@
this.lastSentExp = -1; this.lastSentExp = -1;
this.lastSentHealth = -1.0F; this.lastSentHealth = -1.0F;
this.lastSentFood = -1; this.lastSentFood = -1;
@ -1319,7 +1322,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 +2256,19 @@ @@ -1752,19 +2257,19 @@
} }
@Override @Override
@ -1343,7 +1346,7 @@
} }
return flag1; return flag1;
@@ -1861,8 +2365,13 @@ @@ -1861,8 +2366,13 @@
} }
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) { public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
@ -1358,7 +1361,7 @@
} }
} }
@@ -1878,7 +2387,36 @@ @@ -1878,7 +2388,36 @@
} }
public void updateOptions(ClientInformation clientOptions) { public void updateOptions(ClientInformation clientOptions) {
@ -1395,7 +1398,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 +2495,27 @@ @@ -1957,12 +2496,27 @@
this.camera = (Entity) (entity == null ? this : entity); this.camera = (Entity) (entity == null ? this : entity);
if (entity1 != this.camera) { if (entity1 != this.camera) {
@ -1424,7 +1427,7 @@
} }
if (entity != null) { if (entity != null) {
@@ -1999,11 +2552,11 @@ @@ -1999,11 +2553,11 @@
@Nullable @Nullable
public Component getTabListDisplayName() { public Component getTabListDisplayName() {
@ -1438,7 +1441,7 @@
} }
@Override @Override
@@ -2046,17 +2599,43 @@ @@ -2046,17 +2600,43 @@
} }
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) { public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
@ -1489,7 +1492,7 @@
} else { } else {
this.respawnPosition = null; this.respawnPosition = null;
this.respawnDimension = Level.OVERWORLD; this.respawnDimension = Level.OVERWORLD;
@@ -2088,18 +2667,44 @@ @@ -2088,18 +2668,44 @@
} }
@Override @Override
@ -1538,7 +1541,7 @@
} }
this.awardStat(Stats.DROP); this.awardStat(Stats.DROP);
@@ -2275,9 +2880,15 @@ @@ -2275,9 +2881,15 @@
@Override @Override
public void stopRiding() { public void stopRiding() {
@ -1555,7 +1558,7 @@
if (entity instanceof LivingEntity entityliving) { if (entity instanceof LivingEntity entityliving) {
Iterator iterator = entityliving.getActiveEffects().iterator(); Iterator iterator = entityliving.getActiveEffects().iterator();
@@ -2375,10 +2986,12 @@ @@ -2375,10 +2987,12 @@
return TicketType.ENDER_PEARL.timeout(); return TicketType.ENDER_PEARL.timeout();
} }
@ -1571,7 +1574,7 @@
} }
private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) { private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) {
@@ -2387,4 +3000,147 @@ @@ -2387,4 +3001,147 @@
return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
} }
} }

View file

@ -153,7 +153,7 @@
+ PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); + PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
+ ResourceLocation identifier = packet.payload().type().id(); + ResourceLocation identifier = packet.payload().type().id();
+ ByteBuf payload = ((DiscardedPayload)packet.payload()).data(); + ByteBuf payload = ((DiscardedPayload)packet.payload()).data();
+
+ if (identifier.equals(ServerCommonPacketListenerImpl.CUSTOM_REGISTER)) { + if (identifier.equals(ServerCommonPacketListenerImpl.CUSTOM_REGISTER)) {
+ try { + try {
+ String channels = payload.toString(com.google.common.base.Charsets.UTF_8); + String channels = payload.toString(com.google.common.base.Charsets.UTF_8);
@ -193,7 +193,7 @@
+ this.disconnect(Component.literal("Invalid custom payload!")); + this.disconnect(Component.literal("Invalid custom payload!"));
+ } + }
+ } + }
+
+ } + }
+ +
+ public final boolean isDisconnected() { + public final boolean isDisconnected() {
@ -281,7 +281,7 @@
if (packet.isTerminal()) { if (packet.isTerminal()) {
this.close(); this.close();
} }
@@ -175,20 +328,72 @@ @@ -175,20 +328,73 @@
} }
} }
@ -342,6 +342,7 @@
+ +
+ private void disconnect0(DisconnectionDetails disconnectiondetails) { + private void disconnect0(DisconnectionDetails disconnectiondetails) {
+ // CraftBukkit end + // CraftBukkit end
+ this.player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.KICKED; // Paper - Add API for quit reason
+ this.connection.send(new ClientboundDisconnectPacket(disconnectiondetails.reason()), PacketSendListener.thenRun(() -> { + this.connection.send(new ClientboundDisconnectPacket(disconnectiondetails.reason()), PacketSendListener.thenRun(() -> {
+ this.connection.disconnect(disconnectiondetails); + this.connection.disconnect(disconnectiondetails);
})); }));

View file

@ -401,7 +401,7 @@
+ entityplayer.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper - Inventory close reason + entityplayer.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper - Inventory close reason
+ } + }
+ +
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName()))); // Paper - Adventure + PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName())), entityplayer.quitReason); // Paper - Adventure & Add API for quit reason
+ this.cserver.getPluginManager().callEvent(playerQuitEvent); + this.cserver.getPluginManager().callEvent(playerQuitEvent);
+ entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); + entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
+ +