2019-06-06 17:36:57 +02:00
|
|
|
From 9ee58b2c80de2903db18ea2c163a6b6e2aae5084 Mon Sep 17 00:00:00 2001
|
2016-12-22 03:22:02 +01:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sun, 4 Dec 2016 01:19:14 -0500
|
|
|
|
Subject: [PATCH] IllegalPacketEvent
|
|
|
|
|
|
|
|
Fire an event when an illegal packet is received to let plugins handle it
|
|
|
|
|
|
|
|
Lets plugins change the kick message and if it should kick or not.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/event/player/IllegalPacketEvent.java b/src/main/java/com/destroystokyo/paper/event/player/IllegalPacketEvent.java
|
|
|
|
new file mode 100644
|
2019-06-06 17:36:57 +02:00
|
|
|
index 000000000..37a17f0bb
|
2016-12-22 03:22:02 +01:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/player/IllegalPacketEvent.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -0,0 +1,70 @@
|
2016-12-22 03:22:02 +01:00
|
|
|
+package com.destroystokyo.paper.event.player;
|
|
|
|
+
|
|
|
|
+import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.entity.Player;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
|
|
|
+import org.bukkit.event.player.PlayerEvent;
|
2019-03-20 01:28:15 +01:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
2016-12-22 03:22:02 +01:00
|
|
|
+
|
|
|
|
+public class IllegalPacketEvent extends PlayerEvent {
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @Nullable private final String type;
|
|
|
|
+ @Nullable private final String ex;
|
|
|
|
+ @Nullable private String kickMessage;
|
2016-12-22 03:22:02 +01:00
|
|
|
+ private boolean shouldKick = true;
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public IllegalPacketEvent(@NotNull Player player, @Nullable String type, @Nullable String kickMessage, @NotNull Exception e) {
|
2016-12-22 03:22:02 +01:00
|
|
|
+ super(player);
|
|
|
|
+ this.type = type;
|
|
|
|
+ this.kickMessage = kickMessage;
|
|
|
|
+ this.ex = e.getMessage();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean isShouldKick() {
|
|
|
|
+ return shouldKick;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setShouldKick(boolean shouldKick) {
|
|
|
|
+ this.shouldKick = shouldKick;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @Nullable
|
2016-12-22 03:22:02 +01:00
|
|
|
+ public String getKickMessage() {
|
|
|
|
+ return kickMessage;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public void setKickMessage(@Nullable String kickMessage) {
|
2016-12-22 03:22:02 +01:00
|
|
|
+ this.kickMessage = kickMessage;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @Nullable
|
2016-12-22 03:22:02 +01:00
|
|
|
+ public String getType() {
|
|
|
|
+ return type;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @Nullable
|
2016-12-22 03:22:02 +01:00
|
|
|
+ public String getExceptionMessage() {
|
|
|
|
+ return ex;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2016-12-22 03:22:02 +01:00
|
|
|
+ public HandlerList getHandlers() {
|
|
|
|
+ return handlers;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2016-12-22 03:22:02 +01:00
|
|
|
+ public static HandlerList getHandlerList() {
|
|
|
|
+ return handlers;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public static void process(@NotNull Player player, @Nullable String type, @Nullable String kickMessage, @NotNull Exception exception) {
|
2016-12-22 03:22:02 +01:00
|
|
|
+ IllegalPacketEvent event = new IllegalPacketEvent(player, type, kickMessage, exception);
|
|
|
|
+ event.callEvent();
|
|
|
|
+ if (event.shouldKick) {
|
|
|
|
+ player.kickPlayer(kickMessage);
|
|
|
|
+ }
|
|
|
|
+ Bukkit.getLogger().severe(player.getName() + "/" + type + ": " + exception.getMessage());
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
--
|
2019-03-20 01:28:15 +01:00
|
|
|
2.21.0
|
2016-12-22 03:22:02 +01:00
|
|
|
|