mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-22 10:57:43 +01:00
PlayerFeedAnimalEvent
This commit is contained in:
82
patches/api/0003-PlayerFeedAnimalEvent.patch
Normal file
82
patches/api/0003-PlayerFeedAnimalEvent.patch
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
From a9c7ccafda0a5fa8c590bd072fc980e707664479 Mon Sep 17 00:00:00 2001
|
||||||
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
||||||
|
Date: Fri, 3 May 2019 23:39:28 -0500
|
||||||
|
Subject: [PATCH] PlayerFeedAnimalEvent
|
||||||
|
|
||||||
|
---
|
||||||
|
.../purpur/event/PlayerFeedAnimalEvent.java | 63 +++++++++++++++++++
|
||||||
|
1 file changed, 63 insertions(+)
|
||||||
|
create mode 100644 src/main/java/net/pl3x/purpur/event/PlayerFeedAnimalEvent.java
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/pl3x/purpur/event/PlayerFeedAnimalEvent.java b/src/main/java/net/pl3x/purpur/event/PlayerFeedAnimalEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..e2bb0694
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/net/pl3x/purpur/event/PlayerFeedAnimalEvent.java
|
||||||
|
@@ -0,0 +1,63 @@
|
||||||
|
+package net.pl3x.purpur.event;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.Animals;
|
||||||
|
+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;
|
||||||
|
+
|
||||||
|
+public class PlayerFeedAnimalEvent extends EntityEvent implements Cancellable {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+ private final Player player;
|
||||||
|
+ private final ItemStack itemStack;
|
||||||
|
+ private boolean cancel;
|
||||||
|
+
|
||||||
|
+ public PlayerFeedAnimalEvent(Animals entity, Player player, ItemStack food) {
|
||||||
|
+ super(entity);
|
||||||
|
+ this.player = player;
|
||||||
|
+ this.itemStack = food;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public Animals getEntity() {
|
||||||
|
+ return (Animals) entity;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Returns the player involved in this event
|
||||||
|
+ *
|
||||||
|
+ * @return Player who is involved in this event
|
||||||
|
+ */
|
||||||
|
+ public Player getPlayer() {
|
||||||
|
+ return player;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the ItemStack being fed to this animal
|
||||||
|
+ *
|
||||||
|
+ * @return ItemStack being fed
|
||||||
|
+ */
|
||||||
|
+ public ItemStack getItemStack() {
|
||||||
|
+ return itemStack;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public boolean isCancelled() {
|
||||||
|
+ return cancel;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void setCancelled(boolean cancel) {
|
||||||
|
+ this.cancel = cancel;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
||||||
33
patches/server/0003-PlayerFeedAnimalEvent.patch
Normal file
33
patches/server/0003-PlayerFeedAnimalEvent.patch
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
From efc21635e384f64394f2b9c50b73bd235f200f1c Mon Sep 17 00:00:00 2001
|
||||||
|
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
||||||
|
Date: Fri, 3 May 2019 23:39:38 -0500
|
||||||
|
Subject: [PATCH] PlayerFeedAnimalEvent
|
||||||
|
|
||||||
|
---
|
||||||
|
src/main/java/net/minecraft/server/EntityAnimal.java | 3 ++-
|
||||||
|
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/server/EntityAnimal.java b/src/main/java/net/minecraft/server/EntityAnimal.java
|
||||||
|
index 31ca1f80..26c43ac6 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/EntityAnimal.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/EntityAnimal.java
|
||||||
|
@@ -99,6 +99,7 @@ public abstract class EntityAnimal extends EntityAgeable implements IAnimal {
|
||||||
|
return 1 + this.world.random.nextInt(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ public boolean isBreedingItem(ItemStack itemstack) { return f(itemstack); } // Purpur - OBFHELPER
|
||||||
|
public boolean f(ItemStack itemstack) {
|
||||||
|
return itemstack.getItem() == Items.WHEAT;
|
||||||
|
}
|
||||||
|
@@ -106,7 +107,7 @@ public abstract class EntityAnimal extends EntityAgeable implements IAnimal {
|
||||||
|
public boolean a(EntityHuman entityhuman, EnumHand enumhand) {
|
||||||
|
ItemStack itemstack = entityhuman.b(enumhand);
|
||||||
|
|
||||||
|
- if (this.f(itemstack)) {
|
||||||
|
+ if (this.isBreedingItem(itemstack) && new net.pl3x.purpur.event.PlayerFeedAnimalEvent((org.bukkit.entity.Animals) getBukkitEntity(), (org.bukkit.entity.Player) entityhuman.getBukkitEntity(), itemstack.asBukkitCopy()).callEvent()) { // Purpur
|
||||||
|
if (this.getAge() == 0 && this.dD()) {
|
||||||
|
this.a(entityhuman, itemstack);
|
||||||
|
this.f(entityhuman);
|
||||||
|
--
|
||||||
|
2.20.1
|
||||||
|
|
||||||
Reference in New Issue
Block a user