-
-
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.
Add ItemSpawnEntityEvent and expand EntityPlaceEvent
- Loading branch information
1 parent
0ae58c0
commit b1092b2
Showing
2 changed files
with
678 additions
and
0 deletions.
There are no files selected for viewing
295 changes: 295 additions & 0 deletions
295
patches/api/0457-Add-ItemSpawnEntityEvent-and-expand-EntityPlaceEvent.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,295 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Jake Potrebic <[email protected]> | ||
Date: Thu, 20 Jan 2022 10:54:54 -0800 | ||
Subject: [PATCH] Add ItemSpawnEntityEvent and expand EntityPlaceEvent | ||
|
||
|
||
diff --git a/src/main/java/io/papermc/paper/event/entity/BlockPlaceEntityEvent.java b/src/main/java/io/papermc/paper/event/entity/BlockPlaceEntityEvent.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..b72ec53ddc0616c9904ca3b238e65abf848becab | ||
--- /dev/null | ||
+++ b/src/main/java/io/papermc/paper/event/entity/BlockPlaceEntityEvent.java | ||
@@ -0,0 +1,41 @@ | ||
+package io.papermc.paper.event.entity; | ||
+ | ||
+import org.bukkit.block.Block; | ||
+import org.bukkit.block.BlockFace; | ||
+import org.bukkit.block.Dispenser; | ||
+import org.bukkit.entity.Entity; | ||
+import org.bukkit.entity.Player; | ||
+import org.bukkit.inventory.ItemStack; | ||
+import org.jetbrains.annotations.ApiStatus; | ||
+import org.jetbrains.annotations.Contract; | ||
+import org.jetbrains.annotations.NotNull; | ||
+import org.jetbrains.annotations.Nullable; | ||
+ | ||
+public class BlockPlaceEntityEvent extends PlaceEntityEvent { | ||
+ | ||
+ private final Dispenser dispenser; | ||
+ | ||
+ @ApiStatus.Internal | ||
+ public BlockPlaceEntityEvent(final @NotNull Entity entity, final @NotNull Block block, final @NotNull BlockFace blockFace, final @NotNull ItemStack spawningStack, final @NotNull Dispenser dispenser) { | ||
+ super(entity, null, block, blockFace, spawningStack); | ||
+ this.dispenser = dispenser; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Get the dispenser responsible for placing the entity. | ||
+ * | ||
+ * @return a non-snapshot Dispenser | ||
+ */ | ||
+ public @NotNull Dispenser getDispenser() { | ||
+ return this.dispenser; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Player will always be null on this event. | ||
+ */ | ||
+ @Override | ||
+ @Contract("-> null") | ||
+ public @Nullable Player getPlayer() { | ||
+ return null; | ||
+ } | ||
+} | ||
diff --git a/src/main/java/io/papermc/paper/event/entity/ItemSpawnEntityEvent.java b/src/main/java/io/papermc/paper/event/entity/ItemSpawnEntityEvent.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..6668171113257f5383904ab145da089600630544 | ||
--- /dev/null | ||
+++ b/src/main/java/io/papermc/paper/event/entity/ItemSpawnEntityEvent.java | ||
@@ -0,0 +1,96 @@ | ||
+package io.papermc.paper.event.entity; | ||
+ | ||
+import org.bukkit.block.Block; | ||
+import org.bukkit.block.BlockFace; | ||
+import org.bukkit.entity.Entity; | ||
+import org.bukkit.entity.Player; | ||
+import org.bukkit.event.Cancellable; | ||
+import org.bukkit.event.HandlerList; | ||
+import org.bukkit.event.entity.EntityEvent; | ||
+import org.bukkit.inventory.ItemStack; | ||
+import org.jetbrains.annotations.ApiStatus; | ||
+import org.jetbrains.annotations.NotNull; | ||
+import org.jetbrains.annotations.Nullable; | ||
+ | ||
+/** | ||
+ * When an itemstack causes the spawning of an entity. Most event fires are going to | ||
+ * be the through the sub-event {@link org.bukkit.event.entity.EntityPlaceEvent} but this | ||
+ * event will also be fired for mob spawn eggs from players and dispensers. | ||
+ */ | ||
+public class ItemSpawnEntityEvent extends EntityEvent implements Cancellable { | ||
+ | ||
+ private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
+ | ||
+ private final Player player; | ||
+ private final Block block; | ||
+ private final BlockFace blockFace; | ||
+ private final ItemStack spawningStack; | ||
+ private boolean cancelled; | ||
+ | ||
+ @ApiStatus.Internal | ||
+ public ItemSpawnEntityEvent(final @NotNull Entity entity, final @Nullable Player player, final @NotNull Block block, final @NotNull BlockFace blockFace, final @NotNull ItemStack spawningStack) { | ||
+ super(entity); | ||
+ this.player = player; | ||
+ this.block = block; | ||
+ this.blockFace = blockFace; | ||
+ this.spawningStack = spawningStack; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Returns the player placing the entity (if one is available). | ||
+ * | ||
+ * @return the player placing the entity | ||
+ */ | ||
+ public @Nullable Player getPlayer() { | ||
+ return this.player; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Returns the block that the entity was placed on | ||
+ * | ||
+ * @return the block that the entity was placed on | ||
+ */ | ||
+ public @NotNull Block getBlock() { | ||
+ return this.block; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Returns the face of the block that the entity was placed on | ||
+ * | ||
+ * @return the face of the block that the entity was placed on | ||
+ */ | ||
+ public @NotNull BlockFace getBlockFace() { | ||
+ return this.blockFace; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Gets the itemstack responsible for spawning the entity. Mutating | ||
+ * this itemstack has no effect. | ||
+ * <p> | ||
+ * May return an empty itemstack if the actual stack isn't available. | ||
+ * | ||
+ * @return the spawning itemstack | ||
+ */ | ||
+ public @NotNull ItemStack getSpawningStack() { | ||
+ return this.spawningStack; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public boolean isCancelled() { | ||
+ return this.cancelled; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public void setCancelled(final boolean cancel) { | ||
+ this.cancelled = cancel; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public @NotNull HandlerList getHandlers() { | ||
+ return HANDLER_LIST; | ||
+ } | ||
+ | ||
+ public static @NotNull HandlerList getHandlerList() { | ||
+ return HANDLER_LIST; | ||
+ } | ||
+} | ||
diff --git a/src/main/java/io/papermc/paper/event/entity/PlaceEntityEvent.java b/src/main/java/io/papermc/paper/event/entity/PlaceEntityEvent.java | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..bfd7204c71a1ca46df3e5174aef3fe33e59b4ee6 | ||
--- /dev/null | ||
+++ b/src/main/java/io/papermc/paper/event/entity/PlaceEntityEvent.java | ||
@@ -0,0 +1,28 @@ | ||
+package io.papermc.paper.event.entity; | ||
+ | ||
+import org.bukkit.block.Block; | ||
+import org.bukkit.block.BlockFace; | ||
+import org.bukkit.entity.Entity; | ||
+import org.bukkit.entity.Player; | ||
+import org.bukkit.inventory.ItemStack; | ||
+import org.jetbrains.annotations.ApiStatus; | ||
+import org.jetbrains.annotations.NotNull; | ||
+import org.jetbrains.annotations.Nullable; | ||
+ | ||
+/** | ||
+ * Triggered when an entity is created in the world by "placing" an item | ||
+ * on a block from a player or dispenser. | ||
+ * <br> | ||
+ * Note that this event is currently only fired for these specific placements: | ||
+ * armor stands, boats, minecarts, end crystals, mob buckets, and tnt (dispenser only). | ||
+ * @see org.bukkit.event.hanging.HangingPlaceEvent for paintings, item frames, and leashes. | ||
+ * @see org.bukkit.event.entity.EntityPlaceEvent for a player-only version with more context | ||
+ * @see BlockPlaceEntityEvent for a dispener-only version with more context | ||
+ */ | ||
+public abstract class PlaceEntityEvent extends ItemSpawnEntityEvent { | ||
+ | ||
+ @ApiStatus.Internal | ||
+ protected PlaceEntityEvent(final @NotNull Entity entity, final @Nullable Player player, final @NotNull Block block, final @NotNull BlockFace blockFace, final @NotNull ItemStack spawningStack) { | ||
+ super(entity, player, block, blockFace, spawningStack); | ||
+ } | ||
+} | ||
diff --git a/src/main/java/org/bukkit/event/entity/EntityPlaceEvent.java b/src/main/java/org/bukkit/event/entity/EntityPlaceEvent.java | ||
index 71d664dd89995f088c47d17b38547d530319470c..eefac72e6d89567d021ae63359a7dbc1d1f3e794 100644 | ||
--- a/src/main/java/org/bukkit/event/entity/EntityPlaceEvent.java | ||
+++ b/src/main/java/org/bukkit/event/entity/EntityPlaceEvent.java | ||
@@ -14,61 +14,32 @@ import org.jetbrains.annotations.Nullable; | ||
* Triggered when an entity is created in the world by a player "placing" an item | ||
* on a block. | ||
* <br> | ||
- * Note that this event is currently only fired for four specific placements: | ||
- * armor stands, boats, minecarts, and end crystals. | ||
+ * Note that this event is currently only fired for these specific placements: | ||
+ * armor stands, boats, minecarts, end crystals, and mob buckets. | ||
+ * @see org.bukkit.event.hanging.HangingPlaceEvent for paintings, item frames, and leashes. | ||
*/ | ||
-public class EntityPlaceEvent extends EntityEvent implements Cancellable { | ||
+public class EntityPlaceEvent extends io.papermc.paper.event.entity.PlaceEntityEvent implements Cancellable { // Paper - move to superclass | ||
|
||
- private static final HandlerList handlers = new HandlerList(); | ||
- private boolean cancelled; | ||
- private final Player player; | ||
- private final Block block; | ||
- private final BlockFace blockFace; | ||
+ // Paper - move to superclass | ||
private final EquipmentSlot hand; | ||
|
||
- public EntityPlaceEvent(@NotNull final Entity entity, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace, @NotNull final EquipmentSlot hand) { | ||
- super(entity); | ||
- this.player = player; | ||
- this.block = block; | ||
- this.blockFace = blockFace; | ||
- this.hand = hand; | ||
- } | ||
- | ||
+ // Paper start - move event to superclass | ||
@Deprecated | ||
public EntityPlaceEvent(@NotNull final Entity entity, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace) { | ||
this(entity, player, block, blockFace, EquipmentSlot.HAND); | ||
} | ||
|
||
- /** | ||
- * Returns the player placing the entity | ||
- * | ||
- * @return the player placing the entity | ||
- */ | ||
- @Nullable | ||
- public Player getPlayer() { | ||
- return player; | ||
- } | ||
- | ||
- /** | ||
- * Returns the block that the entity was placed on | ||
- * | ||
- * @return the block that the entity was placed on | ||
- */ | ||
- @NotNull | ||
- public Block getBlock() { | ||
- return block; | ||
+ @Deprecated | ||
+ public EntityPlaceEvent(@NotNull final Entity entity, @Nullable final Player player, @NotNull final Block block, @NotNull final BlockFace blockFace, @NotNull final EquipmentSlot hand) { | ||
+ this(entity, player, block, blockFace, hand, org.bukkit.inventory.ItemStack.empty()); | ||
} | ||
|
||
- /** | ||
- * Returns the face of the block that the entity was placed on | ||
- * | ||
- * @return the face of the block that the entity was placed on | ||
- */ | ||
- @NotNull | ||
- public BlockFace getBlockFace() { | ||
- return blockFace; | ||
+ @org.jetbrains.annotations.ApiStatus.Internal | ||
+ public EntityPlaceEvent(final @NotNull Entity entity, final @Nullable Player player, final @NotNull Block block, final @NotNull BlockFace blockFace, final @NotNull EquipmentSlot hand, final @NotNull org.bukkit.inventory.ItemStack spawningStack) { | ||
+ super(entity, player, block, blockFace, spawningStack); | ||
+ this.hand = hand; | ||
} | ||
- | ||
+ // Paper end | ||
/** | ||
* Get the hand used to place the entity. | ||
* | ||
@@ -79,24 +50,5 @@ public class EntityPlaceEvent extends EntityEvent implements Cancellable { | ||
return hand; | ||
} | ||
|
||
- @Override | ||
- public boolean isCancelled() { | ||
- return cancelled; | ||
- } | ||
- | ||
- @Override | ||
- public void setCancelled(boolean cancel) { | ||
- this.cancelled = cancel; | ||
- } | ||
- | ||
- @NotNull | ||
- @Override | ||
- public HandlerList getHandlers() { | ||
- return handlers; | ||
- } | ||
- | ||
- @NotNull | ||
- public static HandlerList getHandlerList() { | ||
- return handlers; | ||
- } | ||
+ // Paper - move to superclass | ||
} |
Oops, something went wrong.