Paper/Spigot-API-Patches/0190-Add-ThrownEggHatchEvent.patch
Aikar e4d10a6d67
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
122289ff Add FaceAttachable interface to handle Grindstone facing in common with Switches
a6db750e SPIGOT-5647: ZombieVillager entity should have getVillagerType()

CraftBukkit Changes:
bbe3d58e SPIGOT-5650: Lectern.setPage(int) causes a NullPointerException
3075579f Add FaceAttachable interface to handle Grindstone facing in common with Switches
95bd4238 SPIGOT-5647: ZombieVillager entity should have getVillagerType()
4d975ac3 SPIGOT-5617: setBlockData does not work when NotPlayEvent is called by redstone current
2020-04-02 17:09:17 -04:00

133 lines
3.9 KiB
Diff

From 846303604626907a77c402f34b60da5e1e19ace1 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sun, 9 Feb 2020 00:19:08 -0600
Subject: [PATCH] Add ThrownEggHatchEvent
Adds a new event similar to PlayerEggThrowEvent, but without the Player requirement
(dispensers can throw eggs to hatch them, too).
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/ThrownEggHatchEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/ThrownEggHatchEvent.java
new file mode 100644
index 000000000..085d77dde
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/ThrownEggHatchEvent.java
@@ -0,0 +1,115 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Egg;
+import org.bukkit.entity.EntityType;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a thrown egg might hatch.
+ * <p>
+ * This event fires for all thrown eggs that may hatch, players, dispensers, etc.
+ */
+public class ThrownEggHatchEvent extends Event {
+ private static final HandlerList handlers = new HandlerList();
+ private final Egg egg;
+ private boolean hatching;
+ private EntityType hatchType;
+ private byte numHatches;
+
+ public ThrownEggHatchEvent(@NotNull final Egg egg, final boolean hatching, final byte numHatches, @NotNull final EntityType hatchingType) {
+ this.egg = egg;
+ this.hatching = hatching;
+ this.numHatches = numHatches;
+ this.hatchType = hatchingType;
+ }
+
+ /**
+ * Gets the egg involved in this event.
+ *
+ * @return the egg involved in this event
+ */
+ @NotNull
+ public Egg getEgg() {
+ return egg;
+ }
+
+ /**
+ * Gets whether the egg is hatching or not. Will be what the server
+ * would've done without interaction.
+ *
+ * @return boolean Whether the egg is going to hatch or not
+ */
+ public boolean isHatching() {
+ return hatching;
+ }
+
+ /**
+ * Sets whether the egg will hatch or not.
+ *
+ * @param hatching true if you want the egg to hatch, false if you want it
+ * not to
+ */
+ public void setHatching(boolean hatching) {
+ this.hatching = hatching;
+ }
+
+ /**
+ * Get the type of the mob being hatched (EntityType.CHICKEN by default)
+ *
+ * @return The type of the mob being hatched by the egg
+ */
+ @NotNull
+ public EntityType getHatchingType() {
+ return hatchType;
+ }
+
+ /**
+ * Change the type of mob being hatched by the egg
+ *
+ * @param hatchType The type of the mob being hatched by the egg
+ */
+ public void setHatchingType(@NotNull EntityType hatchType) {
+ if (!hatchType.isSpawnable()) throw new IllegalArgumentException("Can't spawn that entity type from an egg!");
+ this.hatchType = hatchType;
+ }
+
+ /**
+ * Get the number of mob hatches from the egg. By default the number will
+ * be the number the server would've done
+ * <ul>
+ * <li>7/8 chance of being 0
+ * <li>31/256 ~= 1/8 chance to be 1
+ * <li>1/256 chance to be 4
+ * </ul>
+ *
+ * @return The number of mobs going to be hatched by the egg
+ */
+ public byte getNumHatches() {
+ return numHatches;
+ }
+
+ /**
+ * Change the number of mobs coming out of the hatched egg
+ * <p>
+ * The boolean hatching will override this number. Ie. If hatching =
+ * false, this number will not matter
+ *
+ * @param numHatches The number of mobs coming out of the egg
+ */
+ public void setNumHatches(byte numHatches) {
+ this.numHatches = numHatches;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}
--
2.25.1