From 497ac626bf00d4145382324adf1ac0ad6ca9d6ae Mon Sep 17 00:00:00 2001
From: Bukkit/Spigot <noreply+git-bukkit@papermc.io>
Date: Mon, 31 Jan 2011 01:34:23 +0000
Subject: [PATCH] Added PLAYER_ITEM_HELD event

By: Dinnerbone <dinnerbone@dinnerbone.com>
---
 .../src/main/java/org/bukkit/event/Event.java |  7 ++++
 .../event/player/PlayerItemHeldEvent.java     | 36 +++++++++++++++++++
 .../bukkit/event/player/PlayerListener.java   |  8 +++++
 .../bukkit/plugin/java/JavaPluginLoader.java  |  5 +++
 4 files changed, 56 insertions(+)
 create mode 100644 paper-api/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java

diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java
index 3bb78acddd..3eca4cdf94 100644
--- a/paper-api/src/main/java/org/bukkit/event/Event.java
+++ b/paper-api/src/main/java/org/bukkit/event/Event.java
@@ -206,6 +206,13 @@ public abstract class Event {
          */
         PLAYER_TELEPORT (Category.PLAYER),
 
+        /**
+         * Called when a player changes their held item
+         *
+         * @see org.bukkit.event.player.PlayerItemHeldEvent
+         */
+        PLAYER_ITEM_HELD (Category.PLAYER),
+
         /**
          * BLOCK EVENTS
          */
diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java
new file mode 100644
index 0000000000..3970428f19
--- /dev/null
+++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerItemHeldEvent.java
@@ -0,0 +1,36 @@
+
+package org.bukkit.event.player;
+
+import org.bukkit.entity.Player;
+
+/**
+ * Fired when a player changes their currently held item
+ */
+public class PlayerItemHeldEvent extends PlayerEvent {
+    private int previous;
+    private int current;
+
+    public PlayerItemHeldEvent(final Type type, final Player player, final int previous, final int current) {
+        super(type, player);
+        this.previous = previous;
+        this.current = current;
+    }
+
+    /**
+     * Gets the previous held slot index
+     *
+     * @return Previous slot index
+     */
+    public int getPreviousSlot() {
+        return previous;
+    }
+
+    /**
+     * Gets the new held slot index
+     *
+     * @return New slot index
+     */
+    public int getNewSlot() {
+        return current;
+    }
+}
diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java
index 79bc30ca69..3ab8d0374f 100644
--- a/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java
+++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerListener.java
@@ -97,4 +97,12 @@ public class PlayerListener implements Listener {
      */
     public void onInventoryOpen(PlayerInventoryEvent event) {
     }
+
+    /**
+     * Called when a player changes their held item
+     *
+     * @param event Relevant event details
+     */
+    public void onItemHeldChange(PlayerItemHeldEvent event) {
+    }
 }
diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
index e34b92a006..5d959978a1 100644
--- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
+++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
@@ -173,6 +173,11 @@ public final class JavaPluginLoader implements PluginLoader {
                     ((PlayerListener)listener).onInventoryOpen( (PlayerInventoryEvent)event );
                 }
             };
+        case PLAYER_ITEM_HELD:
+            return new EventExecutor() { public void execute( Listener listener, Event event ) {
+                    ((PlayerListener)listener).onItemHeldChange( (PlayerItemHeldEvent)event );
+                }
+            };
 
         // Block Events
         case BLOCK_PHYSICS: