SPIGOT-3034: PlayerKickEvent.setLeaveMessage(String) doesn't actually do anything

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2022-03-16 19:49:07 +11:00
parent c46dd07f70
commit 6796896e63
3 changed files with 92 additions and 90 deletions

View File

@@ -137,7 +137,7 @@
this.disconnect(new ChatMessage("multiplayer.disconnect.idling"));
}
@@ -296,16 +384,46 @@
@@ -296,16 +384,47 @@
return this.server.isSingleplayerOwner(this.player.getGameProfile());
}
@@ -165,6 +165,7 @@
+ // Do not kick the player
+ return;
+ }
+ this.player.kickLeaveMessage = event.getLeaveMessage(); // CraftBukkit - SPIGOT-3034: Forward leave message to PlayerQuitEvent
+ // Send the possibly modified leave message
+ s = event.getReason();
+ final IChatBaseComponent ichatbasecomponent = CraftChatMessage.fromString(s, true)[0];
@@ -185,7 +186,7 @@
}
private <T, R> void filterTextPacket(T t0, Consumer<R> consumer, BiFunction<ITextFilter, T, CompletableFuture<R>> bifunction) {
@@ -376,7 +494,34 @@
@@ -376,7 +495,34 @@
double d9 = entity.getDeltaMovement().lengthSqr();
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
@@ -221,7 +222,7 @@
PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
this.connection.send(new PacketPlayOutVehicleMove(entity));
return;
@@ -408,14 +553,72 @@
@@ -408,14 +554,72 @@
}
entity.absMoveTo(d3, d4, d5, f, f1);
@@ -294,7 +295,7 @@
this.player.getLevel().getChunkSource().move(this.player);
this.player.checkMovementStatistics(this.player.getX() - d0, this.player.getY() - d1, this.player.getZ() - d2);
this.clientVehicleIsFloating = d11 >= -0.03125D && !flag1 && !this.server.isFlightAllowed() && !entity.isNoGravity() && this.noBlocksAround(entity);
@@ -434,7 +637,7 @@
@@ -434,7 +638,7 @@
@Override
public void handleAcceptTeleportPacket(PacketPlayInTeleportAccept packetplayinteleportaccept) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinteleportaccept, this, this.player.getLevel());
@@ -303,7 +304,7 @@
this.player.absMoveTo(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
this.lastGoodX = this.awaitingPositionFromClient.x;
this.lastGoodY = this.awaitingPositionFromClient.y;
@@ -444,6 +647,7 @@
@@ -444,6 +648,7 @@
}
this.awaitingPositionFromClient = null;
@@ -311,7 +312,7 @@
}
}
@@ -451,7 +655,7 @@
@@ -451,7 +656,7 @@
@Override
public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.getLevel());
@@ -320,7 +321,7 @@
RecipeBookServer recipebookserver = this.player.getRecipeBook();
Objects.requireNonNull(recipebookserver);
@@ -481,6 +685,12 @@
@@ -481,6 +686,12 @@
@Override
public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.getLevel());
@@ -333,7 +334,7 @@
StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand());
if (stringreader.canRead() && stringreader.peek() == '/') {
@@ -490,6 +700,7 @@
@@ -490,6 +701,7 @@
ParseResults<CommandListenerWrapper> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());
this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
@@ -341,7 +342,7 @@
this.connection.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions));
});
}
@@ -722,6 +933,13 @@
@@ -722,6 +934,13 @@
if (container instanceof ContainerMerchant) {
ContainerMerchant containermerchant = (ContainerMerchant) container;
@@ -355,7 +356,7 @@
containermerchant.setSelectionHint(i);
containermerchant.tryMoveItems(i);
@@ -731,6 +949,13 @@
@@ -731,6 +950,13 @@
@Override
public void handleEditBook(PacketPlayInBEdit packetplayinbedit) {
@@ -369,7 +370,7 @@
int i = packetplayinbedit.getSlot();
if (PlayerInventory.isHotbarSlot(i) || i == 40) {
@@ -739,7 +964,7 @@
@@ -739,7 +965,7 @@
Objects.requireNonNull(list);
optional.ifPresent(list::add);
@@ -378,7 +379,7 @@
Objects.requireNonNull(list);
stream.forEach(list::add);
@@ -755,7 +980,7 @@
@@ -755,7 +981,7 @@
ItemStack itemstack = this.player.getInventory().getItem(i);
if (itemstack.is(Items.WRITABLE_BOOK)) {
@@ -387,7 +388,7 @@
}
}
@@ -780,16 +1005,16 @@
@@ -780,16 +1006,16 @@
this.updateBookPages(list, (s) -> {
return IChatBaseComponent.ChatSerializer.toJson(new ChatComponentText(s));
@@ -408,7 +409,7 @@
return NBTTagString.valueOf((String) unaryoperator.apply(itextfilter_a.getFiltered()));
});
@@ -817,6 +1042,7 @@
@@ -817,6 +1043,7 @@
}
itemstack.addTagElement("pages", nbttaglist);
@@ -416,7 +417,7 @@
}
@Override
@@ -853,7 +1079,7 @@
@@ -853,7 +1080,7 @@
} else {
WorldServer worldserver = this.player.getLevel();
@@ -425,7 +426,7 @@
if (this.tickCount == 0) {
this.resetPosition();
}
@@ -863,7 +1089,7 @@
@@ -863,7 +1090,7 @@
this.awaitingTeleportTime = this.tickCount;
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
}
@@ -434,7 +435,7 @@
} else {
this.awaitingTeleportTime = this.tickCount;
double d0 = clampHorizontal(packetplayinflying.getX(this.player.getX()));
@@ -875,7 +1101,15 @@
@@ -875,7 +1102,15 @@
if (this.player.isPassenger()) {
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
this.player.getLevel().getChunkSource().move(this.player);
@@ -450,7 +451,7 @@
double d3 = this.player.getX();
double d4 = this.player.getY();
double d5 = this.player.getZ();
@@ -895,15 +1129,33 @@
@@ -895,15 +1130,33 @@
++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@@ -486,7 +487,7 @@
PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d7, d8, d9});
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
return;
@@ -924,6 +1176,7 @@
@@ -924,6 +1177,7 @@
boolean flag1 = this.player.verticalCollisionBelow;
this.player.move(EnumMoveType.PLAYER, new Vec3D(d7, d8, d9));
@@ -494,7 +495,7 @@
double d12 = d8;
d7 = d0 - this.player.getX();
@@ -945,6 +1198,69 @@
@@ -945,6 +1199,69 @@
if (!this.player.noPhysics && !this.player.isSleeping() && (flag2 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb))) {
this.teleport(d3, d4, d5, f, f1);
} else {
@@ -564,7 +565,7 @@
this.clientIsFloating = d12 >= -0.03125D && !flag1 && this.player.gameMode.getGameModeForPlayer() != EnumGamemode.SPECTATOR && !this.server.isFlightAllowed() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isFallFlying() && !this.player.isAutoSpinAttack() && this.noBlocksAround(this.player);
this.player.getLevel().getChunkSource().move(this.player);
this.player.doCheckFallDamage(this.player.getY() - d6, packetplayinflying.isOnGround());
@@ -983,19 +1299,80 @@
@@ -983,19 +1300,80 @@
return true;
}
@@ -649,7 +650,7 @@
double d3 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X) ? this.player.getX() : 0.0D;
double d4 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Y) ? this.player.getY() : 0.0D;
double d5 = set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.Z) ? this.player.getZ() : 0.0D;
@@ -1007,6 +1384,14 @@
@@ -1007,6 +1385,14 @@
this.awaitingTeleport = 0;
}
@@ -664,7 +665,7 @@
this.awaitingTeleportTime = this.tickCount;
this.player.absMoveTo(d0, d1, d2, f, f1);
this.player.connection.send(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport, flag));
@@ -1015,6 +1400,7 @@
@@ -1015,6 +1401,7 @@
@Override
public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.getLevel());
@@ -672,7 +673,7 @@
BlockPosition blockposition = packetplayinblockdig.getPos();
this.player.resetLastActionTime();
@@ -1025,14 +1411,46 @@
@@ -1025,14 +1412,46 @@
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND);
@@ -721,7 +722,7 @@
this.player.drop(false);
}
@@ -1069,6 +1487,7 @@
@@ -1069,6 +1488,7 @@
@Override
public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.getLevel());
@@ -729,7 +730,7 @@
WorldServer worldserver = this.player.getLevel();
EnumHand enumhand = packetplayinuseitem.getHand();
ItemStack itemstack = this.player.getItemInHand(enumhand);
@@ -1088,6 +1507,7 @@
@@ -1088,6 +1508,7 @@
if (blockposition.getY() < i) {
if (this.awaitingPositionFromClient == null && this.player.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.mayInteract(this.player, blockposition)) {
@@ -737,7 +738,7 @@
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enumdirection == EnumDirection.UP && !enuminteractionresult.consumesAction() && blockposition.getY() >= i - 1 && wasBlockPlacementAttempt(this.player, itemstack)) {
@@ -1117,12 +1537,51 @@
@@ -1117,12 +1538,51 @@
@Override
public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.getLevel());
@@ -789,7 +790,7 @@
EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult.shouldSwing()) {
@@ -1143,7 +1602,7 @@
@@ -1143,7 +1603,7 @@
Entity entity = packetplayinspectate.getEntity(worldserver);
if (entity != null) {
@@ -798,7 +799,7 @@
return;
}
}
@@ -1158,6 +1617,7 @@
@@ -1158,6 +1618,7 @@
PlayerConnection.LOGGER.info("Disconnecting {} due to resource pack rejection", this.player.getName());
this.disconnect(new ChatMessage("multiplayer.requiredTexturePrompt.disconnect"));
}
@@ -806,7 +807,7 @@
}
@@ -1177,11 +1637,26 @@
@@ -1177,11 +1638,26 @@
@Override
public void onDisconnect(IChatBaseComponent ichatbasecomponent) {
@@ -834,7 +835,7 @@
this.player.getTextFilter().leave();
if (this.isSingleplayerOwner()) {
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
@@ -1196,6 +1671,15 @@
@@ -1196,6 +1672,15 @@
}
public void send(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
@@ -850,7 +851,7 @@
try {
this.connection.send(packet, genericfuturelistener);
} catch (Throwable throwable) {
@@ -1212,7 +1696,16 @@
@@ -1212,7 +1697,16 @@
@Override
public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.getLevel());
@@ -867,7 +868,7 @@
if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) {
this.player.stopUsingItem();
}
@@ -1221,11 +1714,18 @@
@@ -1221,11 +1715,18 @@
this.player.resetLastActionTime();
} else {
PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
@@ -886,7 +887,7 @@
String s = StringUtils.normalizeSpace(packetplayinchat.getMessage());
for (int i = 0; i < s.length(); ++i) {
@@ -1239,20 +1739,42 @@
@@ -1239,20 +1740,42 @@
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinchat, this, this.player.getLevel());
this.handleChat(ITextFilter.a.passThrough(s));
} else {
@@ -933,7 +934,7 @@
} else {
String s1 = itextfilter_a.getFiltered();
ChatMessage chatmessage = s1.isEmpty() ? null : new ChatMessage("chat.type.text", new Object[]{this.player.getDisplayName(), s1});
@@ -1263,28 +1785,198 @@
@@ -1263,28 +1786,198 @@
}, ChatMessageType.CHAT, this.player.getUUID());
}
@@ -1136,7 +1137,7 @@
this.player.resetLastActionTime();
IJumpable ijumpable;
@@ -1342,6 +2034,7 @@
@@ -1342,6 +2035,7 @@
@Override
public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.getLevel());
@@ -1144,7 +1145,7 @@
WorldServer worldserver = this.player.getLevel();
final Entity entity = packetplayinuseentity.getTarget(worldserver);
@@ -1356,10 +2049,44 @@
@@ -1356,10 +2050,44 @@
if (this.player.distanceToSqr(entity) < 36.0D) {
packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() {
@@ -1190,7 +1191,7 @@
if (enuminteractionresult.consumesAction()) {
CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, itemstack, entity);
if (enuminteractionresult.shouldSwing()) {
@@ -1371,20 +2098,27 @@
@@ -1371,20 +2099,27 @@
@Override
public void onInteraction(EnumHand enumhand) {
@@ -1221,7 +1222,7 @@
} else {
PlayerConnection.this.disconnect(new ChatMessage("multiplayer.disconnect.invalid_entity_attacked"));
PlayerConnection.LOGGER.warn("Player {} tried to attack an invalid entity", PlayerConnection.this.player.getName().getString());
@@ -1429,15 +2163,21 @@
@@ -1429,15 +2164,21 @@
@Override
public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.getLevel());
@@ -1245,7 +1246,7 @@
this.player.containerMenu.sendAllDataToRemote();
} else {
int i = packetplayinwindowclick.getSlotNum();
@@ -1448,7 +2188,284 @@
@@ -1448,7 +2189,284 @@
boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates();
@@ -1531,7 +1532,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
@@ -1484,6 +2501,7 @@
@@ -1484,6 +2502,7 @@
@Override
public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.getLevel());
@@ -1539,7 +1540,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packetplayinenchantitem.getContainerId() && !this.player.isSpectator()) {
boolean flag = this.player.containerMenu.clickMenuButton(this.player, packetplayinenchantitem.getButtonId());
@@ -1514,6 +2532,43 @@
@@ -1514,6 +2533,43 @@
boolean flag1 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty();
@@ -1583,7 +1584,7 @@
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).set(itemstack);
@@ -1536,6 +2591,7 @@
@@ -1536,6 +2592,7 @@
}
private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List<ITextFilter.a> list) {
@@ -1591,7 +1592,7 @@
this.player.resetLastActionTime();
WorldServer worldserver = this.player.getLevel();
BlockPosition blockposition = packetplayinupdatesign.getPos();
@@ -1552,18 +2608,37 @@
@@ -1552,18 +2609,37 @@
if (!tileentitysign.isEditable() || !this.player.getUUID().equals(tileentitysign.getPlayerWhoMayEdit())) {
PlayerConnection.LOGGER.warn("Player {} just tried to change non-editable sign", this.player.getName().getString());
@@ -1631,7 +1632,7 @@
tileentitysign.setChanged();
worldserver.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3);
@@ -1573,6 +2648,7 @@
@@ -1573,6 +2649,7 @@
@Override
public void handleKeepAlive(PacketPlayInKeepAlive packetplayinkeepalive) {
@@ -1639,7 +1640,7 @@
if (this.keepAlivePending && packetplayinkeepalive.getId() == this.keepAliveChallenge) {
int i = (int) (SystemUtils.getMillis() - this.keepAliveTime);
@@ -1587,7 +2663,17 @@
@@ -1587,7 +2664,17 @@
@Override
public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.getLevel());
@@ -1658,7 +1659,7 @@
}
@Override
@@ -1596,8 +2682,50 @@
@@ -1596,8 +2683,50 @@
this.player.updateOptions(packetplayinsettings);
}