3737
3838import ch .njol .skript .Skript ;
3939import ch .njol .skript .aliases .ItemType ;
40+ import ch .njol .skript .bukkitutil .PlayerUtils ;
4041import ch .njol .skript .classes .Comparator .Relation ;
4142import ch .njol .skript .classes .data .DefaultComparators ;
4243import ch .njol .skript .entity .EntityData ;
@@ -103,7 +104,7 @@ public boolean check(final Event e) {
103104
104105 if (e instanceof PlayerInteractEntityEvent ) {
105106 PlayerInteractEntityEvent clickEvent = ((PlayerInteractEntityEvent ) e );
106- if (Skript .isRunningMinecraft (1 , 9 )) { // If player has empty hand, BOTH hands trigger the event (might be a bug?)
107+ if (Skript .isRunningMinecraft (1 , 9 )) {
107108 ItemStack mainHand = clickEvent .getPlayer ().getInventory ().getItemInMainHand ();
108109 ItemStack offHand = clickEvent .getPlayer ().getInventory ().getItemInOffHand ();
109110
@@ -123,7 +124,7 @@ public boolean check(final Event e) {
123124 block = null ;
124125 } else if (e instanceof PlayerInteractEvent ) {
125126 PlayerInteractEvent clickEvent = ((PlayerInteractEvent ) e );
126- if (Skript .isRunningMinecraft (1 , 9 )) { // If player has empty hand, BOTH hands trigger the event (might be a bug?)
127+ if (Skript .isRunningMinecraft (1 , 9 )) {
127128 ItemStack mainHand = clickEvent .getPlayer ().getInventory ().getItemInMainHand ();
128129 ItemStack offHand = clickEvent .getPlayer ().getInventory ().getItemInOffHand ();
129130
@@ -198,6 +199,11 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
198199 ItemStack mainHand = player .getInventory ().getItemInMainHand ();
199200 ItemStack offHand = player .getInventory ().getItemInOffHand ();
200201
202+ Material mainMat = mainHand .getType ();
203+ Material offMat = offHand .getType ();
204+ assert mainMat != null ;
205+ assert offMat != null ;
206+
201207 //Skript.info("block is " + block);
202208 //Skript.info("entity is " + entity);
203209
@@ -231,7 +237,7 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
231237 }
232238
233239 // Seriously? Empty hand -> block in hand, since id of AIR < 256 :O
234- if ((offHand . getType (). isBlock () && offHand . getType () != Material .AIR ) || offHand . getType (). isEdible ( )) {
240+ if ((offMat . isBlock () && offMat != Material .AIR ) || PlayerUtils . canEat ( player , offMat )) {
235241 offUsable = true ;
236242 }
237243
@@ -264,7 +270,7 @@ public static boolean checkUseOffHand(Player player, int clickType, @Nullable Bl
264270 }
265271
266272 // Seriously? Empty hand -> block in hand, since id of AIR < 256 :O
267- if ((mainHand . getType (). isBlock () && mainHand . getType () != Material .AIR ) || mainHand . getType (). isEdible ( )) {
273+ if ((mainMat . isBlock () && mainMat != Material .AIR ) || PlayerUtils . canEat ( player , mainMat )) {
268274 mainUsable = true ;
269275 }
270276
0 commit comments