6
6
import com .comphenix .protocol .events .ListenerPriority ;
7
7
import com .comphenix .protocol .events .PacketAdapter ;
8
8
import com .comphenix .protocol .events .PacketEvent ;
9
+ import com .google .gson .JsonParseException ;
9
10
import org .bukkit .entity .Player ;
10
11
import org .bukkit .inventory .ItemStack ;
11
12
import org .bukkit .plugin .Plugin ;
@@ -29,15 +30,33 @@ public static void activate(
29
30
public void onPacketReceiving (PacketEvent event ) {
30
31
final Player player = event .getPlayer ();
31
32
ItemStack item = event .getPacket ().getItemModifier ().readSafely (0 );
32
- ItemStack filteredItem = bookFilter .filterBook (item , player , FilterAction .CREATE );
33
- if (filteredItem != null ) {
33
+ try {
34
+ ItemStack filteredItem = bookFilter .filterBook (item , player , FilterAction .CREATE );
35
+
36
+ if (filteredItem != null ) {
37
+ event .setCancelled (true );
38
+ event .getPlayer ().updateInventory ();
39
+ logger .log (
40
+ Level .WARNING ,
41
+ "Player {0} {1} tried to create a book with illegal click events!" ,
42
+ new Object []{player .getName (), player .getUniqueId ()}
43
+ );
44
+ if (config .getPlayerMessage () != null ) {
45
+ player .sendMessage (config .getPlayerMessage ());
46
+ }
47
+ }
48
+ } catch (JsonParseException exception ) { // thrown if the book pages contain invalid JSON
49
+ logger .log (
50
+ Level .SEVERE ,
51
+ "Detected a book with invalid page content that could not be parsed in inventory of " +
52
+ "player " + player .getName () + " (" + player .getUniqueId () + "), removing the item."
53
+ ,
54
+ exception
55
+ );
34
56
event .setCancelled (true );
35
57
event .getPlayer ().updateInventory ();
36
- logger .log (Level .WARNING , "Player {0} {1} tried to create a book with illegal click events!" ,
37
- new Object []{player .getName (), player .getUniqueId ()});
38
- if (config .getPlayerMessage () != null ) {
39
- player .sendMessage (config .getPlayerMessage ());
40
- }
58
+ player .kickPlayer ("Invalid book content detected, please contact an administrator." );
59
+ logger .log (Level .SEVERE , item .toString ());
41
60
}
42
61
}
43
62
});
0 commit comments