Skip to content

Commit

Permalink
Implement PlayerSwapHandItemsEvent (#934)
Browse files Browse the repository at this point in the history
Related to #922.
  • Loading branch information
jhg023 authored and aramperes committed Jun 2, 2018
1 parent 5b8c8e2 commit 5ea0b55
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.DoublePlant;
Expand Down Expand Up @@ -128,9 +129,13 @@ public void handle(GlowSession session, DiggingMessage message) {
} else if (message.getState() == DiggingMessage.SWAP_ITEM_IN_HAND) {
ItemStack main = player.getInventory().getItemInMainHand();
ItemStack off = player.getInventory().getItemInOffHand();
player.getInventory().setItemInOffHand(main);
player.getInventory().setItemInMainHand(off);
player.updateInventory();
PlayerSwapHandItemsEvent event = EventFactory.getInstance().callEvent(
new PlayerSwapHandItemsEvent(player, off, main));
if (!event.isCancelled()) {
player.getInventory().setItemInOffHand(main);
player.getInventory().setItemInMainHand(off);
player.updateInventory();
}
return;
} else {
return;
Expand Down

0 comments on commit 5ea0b55

Please sign in to comment.