Skip to content

Commit 32c67f0

Browse files
committed
fix: allow specific kick causes to kick players
1 parent 657a1f3 commit 32c67f0

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import pw.kaboom.extras.util.Utility;
2424

2525
import java.time.Duration;
26+
import java.util.EnumSet;
2627
import java.util.UUID;
2728
import java.util.concurrent.ThreadLocalRandom;
2829

@@ -56,6 +57,24 @@ public final class PlayerConnection implements Listener {
5657
private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin");
5758
private static final boolean RANDOMIZE_SPAWN = CONFIG.getBoolean("randomizeSpawn");
5859

60+
private static final EnumSet<PlayerKickEvent.Cause> ALLOWED_KICK_CAUSES = EnumSet.of(
61+
PlayerKickEvent.Cause.TIMEOUT, PlayerKickEvent.Cause.INVALID_VEHICLE_MOVEMENT,
62+
PlayerKickEvent.Cause.INVALID_PLAYER_MOVEMENT,
63+
PlayerKickEvent.Cause.INVALID_ENTITY_ATTACKED, PlayerKickEvent.Cause.INVALID_PAYLOAD,
64+
PlayerKickEvent.Cause.INVALID_COOKIE, PlayerKickEvent.Cause.ILLEGAL_ACTION,
65+
PlayerKickEvent.Cause.SELF_INTERACTION, PlayerKickEvent.Cause.RESOURCE_PACK_REJECTION
66+
);
67+
68+
// Kaboom does not use chat signatures, however some clones may wish to enable them.
69+
private static final boolean USE_SIGNED_CHAT = Bukkit.getServer().isEnforcingSecureProfiles();
70+
private static final EnumSet<PlayerKickEvent.Cause> SIGNED_CHAT_KICK_CAUSES = EnumSet.of(
71+
PlayerKickEvent.Cause.OUT_OF_ORDER_CHAT, PlayerKickEvent.Cause.UNSIGNED_CHAT,
72+
PlayerKickEvent.Cause.CHAT_VALIDATION_FAILED,
73+
PlayerKickEvent.Cause.EXPIRED_PROFILE_PUBLIC_KEY,
74+
PlayerKickEvent.Cause.INVALID_PUBLIC_KEY_SIGNATURE,
75+
PlayerKickEvent.Cause.TOO_MANY_PENDING_CHATS
76+
);
77+
5978
@EventHandler
6079
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
6180
final Player player = Utility.getPlayerExactIgnoreCase(event.getName());
@@ -92,11 +111,15 @@ void onPlayerJoin(final PlayerJoinEvent event) {
92111
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
93112
}
94113

95-
@EventHandler
114+
@EventHandler(ignoreCancelled = true)
96115
void onPlayerKick(final PlayerKickEvent event) {
97-
if (!ENABLE_KICK) {
98-
event.setCancelled(true);
99-
}
116+
if (ENABLE_KICK) return;
117+
118+
final PlayerKickEvent.Cause cause = event.getCause();
119+
if (ALLOWED_KICK_CAUSES.contains(cause)) return;
120+
if (USE_SIGNED_CHAT && SIGNED_CHAT_KICK_CAUSES.contains(cause)) return;
121+
122+
event.setCancelled(true);
100123
}
101124

102125
@EventHandler

0 commit comments

Comments
 (0)