-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PlayerSwapHandItemsEvent NPE when a hand set to null (#9763)
* Fix PlayerSwapHandItemsEvent throwing exception when mainhand or offhand set to null * use fully qualified import * Use ItemStack#empty() instead of new ItemStack * Add NotNull annotation to getters * Add missing Paper comments
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
patches/api/Fix-PlayerSwapHandItemsEvent-throwing-exception-when.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Tamion <[email protected]> | ||
Date: Mon, 25 Sep 2023 19:55:51 +0200 | ||
Subject: [PATCH] Fix PlayerSwapHandItemsEvent throwing exception when mainhand | ||
or offhand set to null | ||
|
||
|
||
diff --git a/src/main/java/org/bukkit/event/player/PlayerSwapHandItemsEvent.java b/src/main/java/org/bukkit/event/player/PlayerSwapHandItemsEvent.java | ||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 | ||
--- a/src/main/java/org/bukkit/event/player/PlayerSwapHandItemsEvent.java | ||
+++ b/src/main/java/org/bukkit/event/player/PlayerSwapHandItemsEvent.java | ||
@@ -0,0 +0,0 @@ public class PlayerSwapHandItemsEvent extends PlayerEvent implements Cancellable | ||
* | ||
* @return item in the main hand | ||
*/ | ||
- @Nullable | ||
+ @NotNull // Paper | ||
public ItemStack getMainHandItem() { | ||
return mainHandItem; | ||
} | ||
@@ -0,0 +0,0 @@ public class PlayerSwapHandItemsEvent extends PlayerEvent implements Cancellable | ||
* @param mainHandItem new item in the main hand | ||
*/ | ||
public void setMainHandItem(@Nullable ItemStack mainHandItem) { | ||
- this.mainHandItem = mainHandItem; | ||
+ this.mainHandItem = mainHandItem == null ? ItemStack.empty() : mainHandItem; // Paper | ||
} | ||
|
||
/** | ||
@@ -0,0 +0,0 @@ public class PlayerSwapHandItemsEvent extends PlayerEvent implements Cancellable | ||
* | ||
* @return item in the off hand | ||
*/ | ||
- @Nullable | ||
+ @NotNull // Paper | ||
public ItemStack getOffHandItem() { | ||
return offHandItem; | ||
} | ||
@@ -0,0 +0,0 @@ public class PlayerSwapHandItemsEvent extends PlayerEvent implements Cancellable | ||
* @param offHandItem new item in the off hand | ||
*/ | ||
public void setOffHandItem(@Nullable ItemStack offHandItem) { | ||
- this.offHandItem = offHandItem; | ||
+ this.offHandItem = offHandItem == null ? ItemStack.empty() : offHandItem; // Paper | ||
} | ||
|
||
@Override |