Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* Called when a player gets kicked from the server
*/
@NullMarked
public class PlayerKickEvent extends PlayerEvent implements Cancellable {

private static final HandlerList HANDLER_LIST = new HandlerList();

private Component kickReason;
private Component leaveMessage;
private @Nullable Component leaveMessage;
private final Cause cause;

private boolean cancelled;

@ApiStatus.Internal
@Deprecated(forRemoval = true)
public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final String kickReason, @NotNull final String leaveMessage) {
public PlayerKickEvent(final Player playerKicked, final String kickReason, final String leaveMessage) {
super(playerKicked);
this.kickReason = LegacyComponentSerializer.legacySection().deserialize(kickReason);
this.leaveMessage = LegacyComponentSerializer.legacySection().deserialize(leaveMessage);
Expand All @@ -32,15 +34,15 @@ public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final String

@ApiStatus.Internal
@Deprecated(forRemoval = true)
public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final Component kickReason, @NotNull final Component leaveMessage) {
public PlayerKickEvent(final Player playerKicked, final Component kickReason, final Component leaveMessage) {
super(playerKicked);
this.kickReason = kickReason;
this.leaveMessage = leaveMessage;
this.cause = Cause.UNKNOWN;
}

@ApiStatus.Internal
public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final Component kickReason, @NotNull final Component leaveMessage, @NotNull final Cause cause) {
public PlayerKickEvent(final Player playerKicked, final Component kickReason, final Component leaveMessage, final Cause cause) {
super(playerKicked);
this.kickReason = kickReason;
this.leaveMessage = leaveMessage;
Expand All @@ -52,7 +54,7 @@ public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final Compon
*
* @return string kick reason
*/
public @NotNull Component reason() {
public Component reason() {
return this.kickReason;
}

Expand All @@ -61,7 +63,7 @@ public PlayerKickEvent(@NotNull final Player playerKicked, @NotNull final Compon
*
* @param kickReason kick reason
*/
public void reason(@NotNull Component kickReason) {
public void reason(Component kickReason) {
this.kickReason = kickReason;
}

Expand All @@ -71,7 +73,6 @@ public void reason(@NotNull Component kickReason) {
* @return string kick reason
* @deprecated in favour of {@link #reason()}
*/
@NotNull
@Deprecated
public String getReason() {
return LegacyComponentSerializer.legacySection().serialize(this.kickReason);
Expand All @@ -81,10 +82,10 @@ public String getReason() {
* Sets the reason why the player is getting kicked
*
* @param kickReason kick reason
* @deprecated in favour of {@link #reason(net.kyori.adventure.text.Component)}
* @deprecated in favour of {@link #reason(Component)}
*/
@Deprecated
public void setReason(@NotNull String kickReason) {
public void setReason(String kickReason) {
this.kickReason = LegacyComponentSerializer.legacySection().deserialize(kickReason);
}

Expand All @@ -93,16 +94,16 @@ public void setReason(@NotNull String kickReason) {
*
* @return string kick reason
*/
public @NotNull Component leaveMessage() {
public @Nullable Component leaveMessage() {
return this.leaveMessage;
}

/**
* Sets the leave message send to all online players
*
* @param leaveMessage leave message
* @param leaveMessage leave message. If {@code null}, no message will be sent
*/
public void leaveMessage(@NotNull Component leaveMessage) {
public void leaveMessage(@Nullable Component leaveMessage) {
this.leaveMessage = leaveMessage;
}

Expand All @@ -112,28 +113,26 @@ public void leaveMessage(@NotNull Component leaveMessage) {
* @return string kick reason
* @deprecated in favour of {@link #leaveMessage()}
*/
@NotNull
@Deprecated
public String getLeaveMessage() {
return LegacyComponentSerializer.legacySection().serialize(this.leaveMessage);
public @Nullable String getLeaveMessage() {
return LegacyComponentSerializer.legacySection().serializeOrNull(this.leaveMessage);
}

/**
* Sets the leave message send to all online players
*
* @param leaveMessage leave message
* @deprecated in favour of {@link #leaveMessage(net.kyori.adventure.text.Component)}
* @param leaveMessage leave message. If {@code null}, no message will be sent
* @deprecated in favour of {@link #leaveMessage(Component)}
*/
@Deprecated
public void setLeaveMessage(@NotNull String leaveMessage) {
this.leaveMessage = LegacyComponentSerializer.legacySection().deserialize(leaveMessage);
public void setLeaveMessage(@Nullable String leaveMessage) {
this.leaveMessage = LegacyComponentSerializer.legacySection().deserializeOrNull(leaveMessage);
}

/**
* Gets the cause of this kick
*/
@NotNull
public org.bukkit.event.player.PlayerKickEvent.Cause getCause() {
public PlayerKickEvent.Cause getCause() {
return this.cause;
}

Expand All @@ -147,13 +146,11 @@ public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}

@NotNull
public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
+ if (!this.cserver.isPrimaryThread()) {
+ org.bukkit.craftbukkit.util.Waitable waitable = new org.bukkit.craftbukkit.util.Waitable() {
+ @Override
+ protected Object evaluate() {
+ protected @Nullable Object evaluate() {
+ ServerCommonPacketListenerImpl.this.disconnect(details);
+ return null;
+ }
Expand Down Expand Up @@ -285,7 +285,7 @@
+ }
+
+ reason = io.papermc.paper.adventure.PaperAdventure.asVanilla(event.reason());
+ leaveMessage = io.papermc.paper.adventure.PaperAdventure.asVanilla(event.leaveMessage());
+ leaveMessage = io.papermc.paper.adventure.PaperAdventure.asVanilla(event.leaveMessage());
+ serverGamePacketListener.player.quitReason = org.bukkit.event.player.PlayerQuitEvent.QuitReason.KICKED; // Paper - Add API for quit reason
+ // Log kick to console *after* event was processed.
+ switch (cause) {
Expand Down
Loading