@@ -108,8 +108,8 @@ public boolean check(final Event e) {
108108 ItemStack offHand = clickEvent .getPlayer ().getInventory ().getItemInOffHand ();
109109
110110 Player player = clickEvent .getPlayer ();
111- @ SuppressWarnings ( " null" )
112- boolean useOffHand = checkOffHandUse (mainHand , offHand , click , player );
111+ assert player != null ;
112+ boolean useOffHand = checkOffHandUse (mainHand , offHand , click , player , null );
113113 if ((useOffHand && clickEvent .getHand () == EquipmentSlot .HAND ) || (!useOffHand && clickEvent .getHand () == EquipmentSlot .OFF_HAND )) {
114114 return false ;
115115 }
@@ -126,8 +126,8 @@ public boolean check(final Event e) {
126126 ItemStack offHand = clickEvent .getPlayer ().getInventory ().getItemInOffHand ();
127127
128128 Player player = clickEvent .getPlayer ();
129- @ SuppressWarnings ( " null" )
130- boolean useOffHand = checkOffHandUse (mainHand , offHand , click , player );
129+ assert player != null ;
130+ boolean useOffHand = checkOffHandUse (mainHand , offHand , click , player , clickEvent . getClickedBlock () );
131131 if ((useOffHand && clickEvent .getHand () == EquipmentSlot .HAND ) || (!useOffHand && clickEvent .getHand () == EquipmentSlot .OFF_HAND )) {
132132 return false ;
133133 }
@@ -186,10 +186,12 @@ public String toString(final @Nullable Event e, final boolean debug) {
186186 return (click == LEFT ? "left" : click == RIGHT ? "right" : "" ) + "click" + (types != null ? " on " + types .toString (e , debug ) : "" ) + (tools != null ? " holding " + tools .toString (e , debug ) : "" );
187187 }
188188
189- private boolean checkOffHandUse (ItemStack mainHand , ItemStack offHand , int clickType , Player player ) {
189+ private boolean checkOffHandUse (@ Nullable ItemStack mainHand , @ Nullable ItemStack offHand , int clickType , Player player , @ Nullable Block target ) {
190190 boolean mainUsable = false ;
191191 boolean offUsable = false ;
192192
193+ if (mainHand == null ) mainHand = new ItemStack (Material .AIR );
194+
193195 if (clickType == RIGHT ) {
194196 if (offHand == null || offHand .getType () == Material .AIR ) return false ;
195197 switch (offHand .getType ()) {
@@ -225,7 +227,6 @@ private boolean checkOffHandUse(ItemStack mainHand, ItemStack offHand, int click
225227 offUsable = true ;
226228 }
227229
228- if (mainHand == null || mainHand .getType () == Material .AIR ) return true ;
229230 switch (mainHand .getType ()) {
230231 case BOW :
231232 case EGG :
@@ -256,6 +257,44 @@ private boolean checkOffHandUse(ItemStack mainHand, ItemStack offHand, int click
256257
257258 if (mainHand .getType ().isBlock () || mainHand .getType ().isEdible ()) {
258259 mainUsable = true ;
260+ } else if (target != null ) {
261+ switch (target .getType ()) {
262+ case ANVIL :
263+ case BEACON :
264+ case BED :
265+ case BREWING_STAND :
266+ case CAKE :
267+ case CAULDRON :
268+ case CHEST :
269+ case TRAPPED_CHEST :
270+ case ENDER_CHEST :
271+ case WORKBENCH :
272+ case ENCHANTMENT_TABLE :
273+ case FURNACE :
274+ case WOOD_DOOR :
275+ case ACACIA_DOOR :
276+ case JUNGLE_DOOR :
277+ case DARK_OAK_DOOR :
278+ case SPRUCE_DOOR :
279+ case BIRCH_DOOR :
280+ case IRON_DOOR :
281+ case TRAP_DOOR :
282+ case IRON_TRAPDOOR :
283+ case FENCE_GATE :
284+ case ACACIA_FENCE_GATE :
285+ case JUNGLE_FENCE_GATE :
286+ case DARK_OAK_FENCE_GATE :
287+ case SPRUCE_FENCE_GATE :
288+ case BIRCH_FENCE_GATE :
289+ case HOPPER :
290+ case DISPENSER :
291+ case DROPPER :
292+ case LEVER :
293+ case WOOD_BUTTON :
294+ case STONE_BUTTON :
295+ case COMMAND :
296+ if (!player .isSneaking ()) mainUsable = true ;
297+ }
259298 }
260299 }
261300
0 commit comments