Fix PlayerInteractEvent error on pre-1.9 servers, fixes #594

This commit is contained in:
BuildTools 2018-12-29 17:35:52 -05:00
parent 84acca7152
commit f7b806bd63

View File

@ -189,11 +189,13 @@ public class PlayerListener implements Listener {
@SuppressWarnings("deprecation") // since 1.13 @SuppressWarnings("deprecation") // since 1.13
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent evt) { public void onPlayerInteract(PlayerInteractEvent evt) {
EquipmentSlot e = evt.getHand(); //Get the hand of the event and set it to 'e'. EquipmentSlot e = null;
if (e == null) { try {
return; e = evt.getHand();
} catch (NoSuchMethodError err) {
// Do nothing, getHand() not present pre-1.9
} }
if (e.equals(EquipmentSlot.HAND)) { //If the event is fired by HAND (main hand) if (e == null || e.equals(EquipmentSlot.HAND)) { //If the event is fired by HAND (main hand)
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) { if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if (evt.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {