Skip to content

Commit

Permalink
Don't throw error when swapping armor slots into the offhand.
Browse files Browse the repository at this point in the history
Lots of conflicting info here, but the offhand slot is in fact part of
the quickbar/hotbar (yay bukkit naming) but does *not* use a hotbar "button",
since it has its own hotkey (i.e., F by default instead of 0-8).
The result is a hotbar_swap *action* with a swap_offhand *clicktype*.

Fixes #1698.
  • Loading branch information
wizjany committed Jan 9, 2021
1 parent 04d5a3b commit cbb3212
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -49,6 +49,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockDispenseArmorEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCreativeEvent;
Expand All @@ -58,6 +59,7 @@
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;

import static com.sk89q.worldguard.bukkit.BukkitUtil.createTarget;

Expand Down Expand Up @@ -330,6 +332,9 @@ private ItemStack checkEquipped(InventoryClickEvent event) {
return cursor;
}
case HOTBAR_SWAP:
if (event.getClick() == ClickType.SWAP_OFFHAND) {
return clickedInventory == null ? null : ((PlayerInventory) clickedInventory).getItemInOffHand();
}
return clickedInventory == null ? null : clickedInventory.getItem(event.getHotbarButton());
default:
break;
Expand Down

0 comments on commit cbb3212

Please sign in to comment.