mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 10:17:38 +01:00
SPIGOT-6186: Canceling a CreatureSpawnEvent results in a "Unable to summon entity due to duplicate UUIDs" error
By: md_5 <git@md-5.net>
This commit is contained in:
parent
889488ff73
commit
658c0a284a
@ -18,7 +18,7 @@
|
|||||||
return (EntityTypes) IRegistry.a((IRegistry) IRegistry.ENTITY_TYPE, s, (Object) entitytypes_builder.a(s));
|
return (EntityTypes) IRegistry.a((IRegistry) IRegistry.ENTITY_TYPE, s, (Object) entitytypes_builder.a(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,10 +169,17 @@
|
@@ -169,10 +169,18 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public T spawnCreature(WorldServer worldserver, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) {
|
public T spawnCreature(WorldServer worldserver, @Nullable NBTTagCompound nbttagcompound, @Nullable IChatBaseComponent ichatbasecomponent, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) {
|
||||||
@ -32,12 +32,13 @@
|
|||||||
|
|
||||||
if (t0 != null) {
|
if (t0 != null) {
|
||||||
- worldserver.addAllEntities(t0);
|
- worldserver.addAllEntities(t0);
|
||||||
+ return worldserver.addAllEntities(t0, spawnReason) ? t0 : null; // Don't return an entity when CreatureSpawnEvent is canceled
|
+ worldserver.addAllEntities(t0, spawnReason);
|
||||||
|
+ return !t0.dead ? t0 : null; // Don't return an entity when CreatureSpawnEvent is canceled
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
||||||
return t0;
|
return t0;
|
||||||
@@ -208,7 +215,7 @@
|
@@ -208,7 +216,7 @@
|
||||||
t0.setCustomName(ichatbasecomponent);
|
t0.setCustomName(ichatbasecomponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +47,7 @@
|
|||||||
return t0;
|
return t0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,7 +358,7 @@
|
@@ -351,7 +359,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
@ -55,7 +56,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<Entity> b(NBTTagCompound nbttagcompound, World world) {
|
private static Optional<Entity> b(NBTTagCompound nbttagcompound, World world) {
|
||||||
@@ -403,7 +410,7 @@
|
@@ -403,7 +411,7 @@
|
||||||
this.g = enumcreaturetype == EnumCreatureType.CREATURE || enumcreaturetype == EnumCreatureType.MISC;
|
this.g = enumcreaturetype == EnumCreatureType.CREATURE || enumcreaturetype == EnumCreatureType.MISC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
a(enumcreaturetype, worldserver, chunk, (entitytypes, blockposition, ichunkaccess) -> {
|
a(enumcreaturetype, worldserver, chunk, (entitytypes, blockposition, ichunkaccess) -> {
|
||||||
return spawnercreature_d.a(entitytypes, blockposition, ichunkaccess);
|
return spawnercreature_d.a(entitytypes, blockposition, ichunkaccess);
|
||||||
}, (entityinsentient, ichunkaccess) -> {
|
}, (entityinsentient, ichunkaccess) -> {
|
||||||
@@ -147,10 +191,13 @@
|
@@ -147,10 +191,14 @@
|
||||||
entityinsentient.setPositionRotation(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F);
|
entityinsentient.setPositionRotation(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F);
|
||||||
if (a(worldserver, entityinsentient, d2)) {
|
if (a(worldserver, entityinsentient, d2)) {
|
||||||
groupdataentity = entityinsentient.prepare(worldserver, worldserver.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null);
|
groupdataentity = entityinsentient.prepare(worldserver, worldserver.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null);
|
||||||
@ -81,7 +81,8 @@
|
|||||||
- worldserver.addAllEntities(entityinsentient);
|
- worldserver.addAllEntities(entityinsentient);
|
||||||
- spawnercreature_a.run(entityinsentient, ichunkaccess);
|
- spawnercreature_a.run(entityinsentient, ichunkaccess);
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (worldserver.addAllEntities(entityinsentient, SpawnReason.NATURAL)) {
|
+ worldserver.addAllEntities(entityinsentient, SpawnReason.NATURAL);
|
||||||
|
+ if (!entityinsentient.dead) {
|
||||||
+ ++j;
|
+ ++j;
|
||||||
+ ++k1;
|
+ ++k1;
|
||||||
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
|
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
|
||||||
@ -90,7 +91,7 @@
|
|||||||
if (j >= entityinsentient.getMaxSpawnGroup()) {
|
if (j >= entityinsentient.getMaxSpawnGroup()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -333,7 +380,7 @@
|
@@ -333,7 +381,7 @@
|
||||||
|
|
||||||
if (entityinsentient.a((GeneratorAccess) worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.a((IWorldReader) worldaccess)) {
|
if (entityinsentient.a((GeneratorAccess) worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.a((IWorldReader) worldaccess)) {
|
||||||
groupdataentity = entityinsentient.prepare(worldaccess, worldaccess.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity, (NBTTagCompound) null);
|
groupdataentity = entityinsentient.prepare(worldaccess, worldaccess.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity, (NBTTagCompound) null);
|
||||||
@ -99,7 +100,7 @@
|
|||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,8 +503,10 @@
|
@@ -456,8 +504,10 @@
|
||||||
return this.d;
|
return this.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
--- a/net/minecraft/server/WorldAccess.java
|
--- a/net/minecraft/server/WorldAccess.java
|
||||||
+++ b/net/minecraft/server/WorldAccess.java
|
+++ b/net/minecraft/server/WorldAccess.java
|
||||||
@@ -5,6 +5,13 @@
|
@@ -5,6 +5,12 @@
|
||||||
WorldServer getMinecraftWorld();
|
WorldServer getMinecraftWorld();
|
||||||
|
|
||||||
default void addAllEntities(Entity entity) {
|
default void addAllEntities(Entity entity) {
|
||||||
@ -9,9 +9,8 @@
|
|||||||
+ this.addAllEntities(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
|
+ this.addAllEntities(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT);
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+ default boolean addAllEntities(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
|
+ default void addAllEntities(Entity entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) {
|
||||||
+ entity.cp().forEach((e) -> this.addEntity(e, reason));
|
+ entity.cp().forEach((e) -> this.addEntity(e, reason));
|
||||||
+ return !entity.dead;
|
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -813,11 +954,16 @@
|
@@ -813,10 +954,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addAllEntitiesSafely(Entity entity) {
|
public boolean addAllEntitiesSafely(Entity entity) {
|
||||||
@ -409,12 +409,11 @@
|
|||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
- this.addAllEntities(entity);
|
- this.addAllEntities(entity);
|
||||||
- return true;
|
+ this.addAllEntities(entity, reason); // CraftBukkit
|
||||||
+ return this.addAllEntities(entity, reason); // CraftBukkit
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -867,10 +1014,17 @@
|
||||||
@@ -867,10 +1013,17 @@
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getScoreboard().a(entity);
|
this.getScoreboard().a(entity);
|
||||||
@ -432,7 +431,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerEntity(Entity entity) {
|
private void registerEntity(Entity entity) {
|
||||||
@@ -891,9 +1044,16 @@
|
@@ -891,9 +1045,16 @@
|
||||||
|
|
||||||
this.entitiesByUUID.put(entity.getUniqueID(), entity);
|
this.entitiesByUUID.put(entity.getUniqueID(), entity);
|
||||||
this.getChunkProvider().addEntity(entity);
|
this.getChunkProvider().addEntity(entity);
|
||||||
@ -449,7 +448,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -923,10 +1083,33 @@
|
@@ -923,10 +1084,33 @@
|
||||||
this.everyoneSleeping();
|
this.everyoneSleeping();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +482,7 @@
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
||||||
|
|
||||||
@@ -935,6 +1118,12 @@
|
@@ -935,6 +1119,12 @@
|
||||||
double d1 = (double) blockposition.getY() - entityplayer.locY();
|
double d1 = (double) blockposition.getY() - entityplayer.locY();
|
||||||
double d2 = (double) blockposition.getZ() - entityplayer.locZ();
|
double d2 = (double) blockposition.getZ() - entityplayer.locZ();
|
||||||
|
|
||||||
@ -496,7 +495,7 @@
|
|||||||
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
|
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
|
||||||
entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
|
entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
|
||||||
}
|
}
|
||||||
@@ -995,10 +1184,20 @@
|
@@ -995,10 +1185,20 @@
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Explosion createExplosion(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
|
public Explosion createExplosion(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, Explosion.Effect explosion_effect) {
|
||||||
@ -517,7 +516,7 @@
|
|||||||
if (explosion_effect == Explosion.Effect.NONE) {
|
if (explosion_effect == Explosion.Effect.NONE) {
|
||||||
explosion.clearBlocks();
|
explosion.clearBlocks();
|
||||||
}
|
}
|
||||||
@@ -1063,13 +1262,20 @@
|
@@ -1063,13 +1263,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
|
public <T extends ParticleParam> int a(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
|
||||||
@ -540,7 +539,7 @@
|
|||||||
++j;
|
++j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1111,7 +1317,7 @@
|
@@ -1111,7 +1318,7 @@
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public BlockPosition a(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) {
|
public BlockPosition a(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) {
|
||||||
@ -549,7 +548,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -1149,7 +1355,13 @@
|
@@ -1149,7 +1356,13 @@
|
||||||
@Override
|
@Override
|
||||||
public WorldMap a(String s) {
|
public WorldMap a(String s) {
|
||||||
return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().b(() -> {
|
return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().b(() -> {
|
||||||
@ -564,7 +563,7 @@
|
|||||||
}, s);
|
}, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1460,6 +1672,11 @@
|
@@ -1460,6 +1673,11 @@
|
||||||
@Override
|
@Override
|
||||||
public void update(BlockPosition blockposition, Block block) {
|
public void update(BlockPosition blockposition, Block block) {
|
||||||
if (!this.isDebugWorld()) {
|
if (!this.isDebugWorld()) {
|
||||||
@ -576,7 +575,7 @@
|
|||||||
this.applyPhysics(blockposition, block);
|
this.applyPhysics(blockposition, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1474,12 +1691,12 @@
|
@@ -1474,12 +1692,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFlatWorld() {
|
public boolean isFlatWorld() {
|
||||||
@ -591,7 +590,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -1499,9 +1716,9 @@
|
@@ -1499,9 +1717,9 @@
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public String F() {
|
public String F() {
|
||||||
@ -603,7 +602,7 @@
|
|||||||
return IRegistry.BLOCK_ENTITY_TYPE.getKey(tileentity.getTileType());
|
return IRegistry.BLOCK_ENTITY_TYPE.getKey(tileentity.getTileType());
|
||||||
}), this.getBlockTickList().a(), this.getFluidTickList().a(), this.P());
|
}), this.getBlockTickList().a(), this.getFluidTickList().a(), this.P());
|
||||||
}
|
}
|
||||||
@@ -1509,7 +1726,7 @@
|
@@ -1509,7 +1727,7 @@
|
||||||
private static <T> String a(Collection<T> collection, Function<T, MinecraftKey> function) {
|
private static <T> String a(Collection<T> collection, Function<T, MinecraftKey> function) {
|
||||||
try {
|
try {
|
||||||
Object2IntOpenHashMap<MinecraftKey> object2intopenhashmap = new Object2IntOpenHashMap();
|
Object2IntOpenHashMap<MinecraftKey> object2intopenhashmap = new Object2IntOpenHashMap();
|
||||||
@ -612,7 +611,7 @@
|
|||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
T t0 = iterator.next();
|
T t0 = iterator.next();
|
||||||
@@ -1518,7 +1735,8 @@
|
@@ -1518,7 +1736,8 @@
|
||||||
object2intopenhashmap.addTo(minecraftkey, 1);
|
object2intopenhashmap.addTo(minecraftkey, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,7 +621,7 @@
|
|||||||
return it_unimi_dsi_fastutil_objects_object2intmap_entry.getKey() + ":" + it_unimi_dsi_fastutil_objects_object2intmap_entry.getIntValue();
|
return it_unimi_dsi_fastutil_objects_object2intmap_entry.getKey() + ":" + it_unimi_dsi_fastutil_objects_object2intmap_entry.getIntValue();
|
||||||
}).collect(Collectors.joining(","));
|
}).collect(Collectors.joining(","));
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
@@ -1527,16 +1745,32 @@
|
@@ -1527,16 +1746,32 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void a(WorldServer worldserver) {
|
public static void a(WorldServer worldserver) {
|
||||||
|
Loading…
Reference in New Issue
Block a user