mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Add MonsterEggSpawnEvent
This commit is contained in:
86
patches/api/0025-Add-MonsterEggSpawnEvent.patch
Normal file
86
patches/api/0025-Add-MonsterEggSpawnEvent.patch
Normal file
@@ -0,0 +1,86 @@
|
||||
From d166142389e29ff7cf64e82fc41a7312efbbeb7a Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
||||
Date: Sat, 19 Oct 2019 03:20:49 -0500
|
||||
Subject: [PATCH] Add MonsterEggSpawnEvent
|
||||
|
||||
---
|
||||
.../event/entity/MonsterEggSpawnEvent.java | 67 +++++++++++++++++++
|
||||
1 file changed, 67 insertions(+)
|
||||
create mode 100644 src/main/java/net/pl3x/purpur/event/entity/MonsterEggSpawnEvent.java
|
||||
|
||||
diff --git a/src/main/java/net/pl3x/purpur/event/entity/MonsterEggSpawnEvent.java b/src/main/java/net/pl3x/purpur/event/entity/MonsterEggSpawnEvent.java
|
||||
new file mode 100644
|
||||
index 000000000..983d67234
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/event/entity/MonsterEggSpawnEvent.java
|
||||
@@ -0,0 +1,67 @@
|
||||
+package net.pl3x.purpur.event.entity;
|
||||
+
|
||||
+import org.bukkit.entity.HumanEntity;
|
||||
+import org.bukkit.entity.LivingEntity;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.Event;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.inventory.ItemStack;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+public class MonsterEggSpawnEvent extends Event implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+ private boolean canceled;
|
||||
+
|
||||
+ private final Player player;
|
||||
+ private LivingEntity entity;
|
||||
+ private final ItemStack item;
|
||||
+
|
||||
+ public MonsterEggSpawnEvent(@Nullable HumanEntity player, @NotNull LivingEntity entity, @NotNull ItemStack item) {
|
||||
+ this.player = (Player) player;
|
||||
+ this.entity = entity;
|
||||
+ this.item = item;
|
||||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ public Player getPlayer() {
|
||||
+ return player;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public LivingEntity getEntity() {
|
||||
+ return entity;
|
||||
+ }
|
||||
+
|
||||
+ public void setEntity(@Nullable LivingEntity entity) {
|
||||
+ if (entity == null) {
|
||||
+ canceled = true;
|
||||
+ return;
|
||||
+ }
|
||||
+ this.entity = entity;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public ItemStack getItem() {
|
||||
+ return item;
|
||||
+ }
|
||||
+
|
||||
+ public boolean isCancelled() {
|
||||
+ return canceled;
|
||||
+ }
|
||||
+
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ canceled = cancel;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+}
|
||||
--
|
||||
2.23.0.rc1
|
||||
|
||||
63
patches/server/0080-Add-MonsterEggSpawnEvent.patch
Normal file
63
patches/server/0080-Add-MonsterEggSpawnEvent.patch
Normal file
@@ -0,0 +1,63 @@
|
||||
From 316d6ac894cef9c6043e2d15c32d5f302bec7697 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <blake.galbreath@gmail.com>
|
||||
Date: Sat, 19 Oct 2019 03:20:59 -0500
|
||||
Subject: [PATCH] Add MonsterEggSpawnEvent
|
||||
|
||||
---
|
||||
.../net/minecraft/server/EntityTypes.java | 28 ++++++++++++++++++-
|
||||
1 file changed, 27 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityTypes.java b/src/main/java/net/minecraft/server/EntityTypes.java
|
||||
index f8600cc07f..9d7b7cad38 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityTypes.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityTypes.java
|
||||
@@ -162,19 +162,45 @@ public class EntityTypes<T extends Entity> {
|
||||
|
||||
@Nullable
|
||||
public Entity spawnCreature(World world, @Nullable ItemStack itemstack, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) {
|
||||
- return this.spawnCreature(world, itemstack == null ? null : itemstack.getTag(), itemstack != null && itemstack.hasName() ? itemstack.getName() : null, entityhuman, blockposition, enummobspawn, flag, flag1);
|
||||
+ return this.spawnCreature(world, itemstack, itemstack == null ? null : itemstack.getTag(), itemstack != null && itemstack.hasName() ? itemstack.getName() : null, entityhuman, blockposition, enummobspawn, flag, flag1); // Purpur
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T spawnCreature(World world, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) {
|
||||
+ // Purpur start
|
||||
+ return spawnCreature(world, null, nbttagcompound, ichatbasecomponent, entityhuman, blockposition, enummobspawn, flag, flag1);
|
||||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ public T spawnCreature(World world, @Nullable ItemStack itemstack, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) {
|
||||
+ // Purpur end
|
||||
// CraftBukkit start
|
||||
return this.spawnCreature(world, nbttagcompound, ichatbasecomponent, entityhuman, blockposition, enummobspawn, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public T spawnCreature(World world, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||
+ // Purpur start
|
||||
+ return spawnCreature(world, null, nbttagcompound, ichatbasecomponent, entityhuman, blockposition, enummobspawn, flag, flag1, spawnReason);
|
||||
+ }
|
||||
+ @Nullable
|
||||
+ public T spawnCreature(World world, @Nullable ItemStack itemstack, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {
|
||||
+ // Purpur end
|
||||
T t0 = this.b(world, nbttagcompound, ichatbasecomponent, entityhuman, blockposition, enummobspawn, flag, flag1);
|
||||
|
||||
+ // Purpur start
|
||||
+ if (spawnReason == org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG && itemstack != null && t0 != null) {
|
||||
+ final net.pl3x.purpur.event.entity.MonsterEggSpawnEvent event = new net.pl3x.purpur.event.entity.MonsterEggSpawnEvent(entityhuman != null ? entityhuman.getBukkitEntity() : null, (org.bukkit.entity.LivingEntity) t0.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(itemstack));
|
||||
+ if (!event.callEvent()) {
|
||||
+ ((WorldServer) world).removeEntity(t0);
|
||||
+ return null;
|
||||
+ }
|
||||
+ if (event.getEntity().getEntityId() != t0.getId()) {
|
||||
+ return (T) ((org.bukkit.craftbukkit.entity.CraftEntity) event.getEntity()).getHandle();
|
||||
+ }
|
||||
+ }
|
||||
+ // Purpur end
|
||||
+
|
||||
return world.addEntity(t0, spawnReason) ? t0 : null; // Don't return an entity when CreatureSpawnEvent is canceled
|
||||
// CraftBukkit end
|
||||
}
|
||||
--
|
||||
2.23.0.rc1
|
||||
|
||||
Reference in New Issue
Block a user