@@ -233,23 +233,23 @@ public void onInventoryClick(InventoryClickEvent event) {
233233 HumanEntity human = event .getWhoClicked ();
234234 Inventory inventory = event .getClickedInventory ();
235235
236- if (human instanceof Player && inventory != null && inventory .getSize () == 9 && inventory .getItem (0 ).hasItemMeta () && inventory .getItem (8 ).getType () == Material .BLACK_STAINED_GLASS && inventory .getItem (7 ).getType () == Material .BLACK_STAINED_GLASS && inventory .getItem (6 ).getType () == Material .BLACK_STAINED_GLASS ) {
237- if (inventory .getItem (0 ) == null ) {
238-
239- }
236+ if (!(human instanceof Player ) || inventory == null || inventory .getSize () != 9 ) {
237+ return ;
238+ }
240239
241- if (inventory .getItem (6 ) == null ) {
242-
243- }
244-
245- if (inventory .getItem (7 ) == null ) {
246-
247- }
240+ ItemStack item0 = inventory .getItem (0 );
241+ ItemStack item6 = inventory .getItem (6 );
242+ ItemStack item7 = inventory .getItem (7 );
243+ ItemStack item8 = inventory .getItem (8 );
248244
249- if ( inventory . getItem ( 8 ) == null ) {
250-
251- }
245+ if ( item0 == null || item6 == null || item7 == null || item8 == null ) {
246+ return ;
247+ }
252248
249+ if (item0 .hasItemMeta () &&
250+ item8 .getType () == Material .BLACK_STAINED_GLASS_PANE &&
251+ item7 .getType () == Material .BLACK_STAINED_GLASS_PANE &&
252+ item6 .getType () == Material .BLACK_STAINED_GLASS_PANE ) {
253253
254254 event .setResult (Result .DENY ); // Cancel the click event
255255 event .setCancelled (true );
@@ -261,10 +261,25 @@ public void onInventoryClick(InventoryClickEvent event) {
261261 public void onInventoryDrag (InventoryDragEvent event ) {
262262 HumanEntity human = event .getWhoClicked ();
263263 Inventory inventory = event .getInventory ();
264-
265-
266264
267- if (human instanceof Player && inventory != null && inventory .getSize () == 9 && inventory .getItem (0 ).hasItemMeta () && inventory .getItem (8 ).getType () == Material .BLACK_STAINED_GLASS && inventory .getItem (7 ).getType () == Material .BLACK_STAINED_GLASS && inventory .getItem (6 ).getType () == Material .BLACK_STAINED_GLASS ) {
265+ if (!(human instanceof Player ) || inventory == null || inventory .getSize () != 9 ) {
266+ return ;
267+ }
268+
269+ ItemStack item0 = inventory .getItem (0 );
270+ ItemStack item6 = inventory .getItem (6 );
271+ ItemStack item7 = inventory .getItem (7 );
272+ ItemStack item8 = inventory .getItem (8 );
273+
274+ if (item0 == null || item6 == null || item7 == null || item8 == null ) {
275+ return ;
276+ }
277+
278+ if (item0 .hasItemMeta () &&
279+ item8 .getType () == Material .BLACK_STAINED_GLASS_PANE &&
280+ item7 .getType () == Material .BLACK_STAINED_GLASS_PANE &&
281+ item6 .getType () == Material .BLACK_STAINED_GLASS_PANE ) {
282+
268283 event .setCancelled (true ); // Cancel the drag event
269284 }
270285 }
0 commit comments