mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 19:12:22 +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
4 changed files with 30 additions and 30 deletions
|
@ -18,7 +18,7 @@
|
|||
return (EntityTypes) IRegistry.a((IRegistry) IRegistry.ENTITY_TYPE, s, (Object) entitytypes_builder.a(s));
|
||||
}
|
||||
|
||||
@@ -169,10 +169,17 @@
|
||||
@@ -169,10 +169,18 @@
|
||||
|
||||
@Nullable
|
||||
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) {
|
||||
- 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
|
||||
}
|
||||
|
||||
return t0;
|
||||
@@ -208,7 +215,7 @@
|
||||
@@ -208,7 +216,7 @@
|
||||
t0.setCustomName(ichatbasecomponent);
|
||||
}
|
||||
|
||||
|
@ -46,7 +47,7 @@
|
|||
return t0;
|
||||
}
|
||||
}
|
||||
@@ -351,7 +358,7 @@
|
||||
@@ -351,7 +359,7 @@
|
||||
}
|
||||
|
||||
return entity;
|
||||
|
@ -55,7 +56,7 @@
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
a(enumcreaturetype, worldserver, chunk, (entitytypes, blockposition, ichunkaccess) -> {
|
||||
return spawnercreature_d.a(entitytypes, blockposition, ichunkaccess);
|
||||
}, (entityinsentient, ichunkaccess) -> {
|
||||
@@ -147,10 +191,13 @@
|
||||
@@ -147,10 +191,14 @@
|
||||
entityinsentient.setPositionRotation(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F);
|
||||
if (a(worldserver, entityinsentient, d2)) {
|
||||
groupdataentity = entityinsentient.prepare(worldserver, worldserver.getDamageScaler(entityinsentient.getChunkCoordinates()), EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null);
|
||||
|
@ -81,7 +81,8 @@
|
|||
- worldserver.addAllEntities(entityinsentient);
|
||||
- spawnercreature_a.run(entityinsentient, ichunkaccess);
|
||||
+ // CraftBukkit start
|
||||
+ if (worldserver.addAllEntities(entityinsentient, SpawnReason.NATURAL)) {
|
||||
+ worldserver.addAllEntities(entityinsentient, SpawnReason.NATURAL);
|
||||
+ if (!entityinsentient.dead) {
|
||||
+ ++j;
|
||||
+ ++k1;
|
||||
+ spawnercreature_a.run(entityinsentient, ichunkaccess);
|
||||
|
@ -90,7 +91,7 @@
|
|||
if (j >= entityinsentient.getMaxSpawnGroup()) {
|
||||
return;
|
||||
}
|
||||
@@ -333,7 +380,7 @@
|
||||
@@ -333,7 +381,7 @@
|
||||
|
||||
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);
|
||||
|
@ -99,7 +100,7 @@
|
|||
flag = true;
|
||||
}
|
||||
}
|
||||
@@ -456,8 +503,10 @@
|
||||
@@ -456,8 +504,10 @@
|
||||
return this.d;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
--- a/net/minecraft/server/WorldAccess.java
|
||||
+++ b/net/minecraft/server/WorldAccess.java
|
||||
@@ -5,6 +5,13 @@
|
||||
@@ -5,6 +5,12 @@
|
||||
WorldServer getMinecraftWorld();
|
||||
|
||||
default void addAllEntities(Entity entity) {
|
||||
|
@ -9,9 +9,8 @@
|
|||
+ 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));
|
||||
+ return !entity.dead;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
|
|
@ -395,7 +395,7 @@
|
|||
return true;
|
||||
}
|
||||
}
|
||||
@@ -813,11 +954,16 @@
|
||||
@@ -813,10 +954,16 @@
|
||||
}
|
||||
|
||||
public boolean addAllEntitiesSafely(Entity entity) {
|
||||
|
@ -409,12 +409,11 @@
|
|||
return false;
|
||||
} else {
|
||||
- this.addAllEntities(entity);
|
||||
- return true;
|
||||
+ return this.addAllEntities(entity, reason); // CraftBukkit
|
||||
+ this.addAllEntities(entity, reason); // CraftBukkit
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -867,10 +1013,17 @@
|
||||
@@ -867,10 +1014,17 @@
|
||||
}
|
||||
|
||||
this.getScoreboard().a(entity);
|
||||
|
@ -432,7 +431,7 @@
|
|||
}
|
||||
|
||||
private void registerEntity(Entity entity) {
|
||||
@@ -891,9 +1044,16 @@
|
||||
@@ -891,9 +1045,16 @@
|
||||
|
||||
this.entitiesByUUID.put(entity.getUniqueID(), entity);
|
||||
this.getChunkProvider().addEntity(entity);
|
||||
|
@ -449,7 +448,7 @@
|
|||
}
|
||||
|
||||
}
|
||||
@@ -923,10 +1083,33 @@
|
||||
@@ -923,10 +1084,33 @@
|
||||
this.everyoneSleeping();
|
||||
}
|
||||
|
||||
|
@ -483,7 +482,7 @@
|
|||
while (iterator.hasNext()) {
|
||||
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
||||
|
||||
@@ -935,6 +1118,12 @@
|
||||
@@ -935,6 +1119,12 @@
|
||||
double d1 = (double) blockposition.getY() - entityplayer.locY();
|
||||
double d2 = (double) blockposition.getZ() - entityplayer.locZ();
|
||||
|
||||
|
@ -496,7 +495,7 @@
|
|||
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
|
||||
entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockBreakAnimation(i, blockposition, j));
|
||||
}
|
||||
@@ -995,10 +1184,20 @@
|
||||
@@ -995,10 +1185,20 @@
|
||||
|
||||
@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) {
|
||||
|
@ -517,7 +516,7 @@
|
|||
if (explosion_effect == Explosion.Effect.NONE) {
|
||||
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) {
|
||||
|
@ -540,7 +539,7 @@
|
|||
++j;
|
||||
}
|
||||
}
|
||||
@@ -1111,7 +1317,7 @@
|
||||
@@ -1111,7 +1318,7 @@
|
||||
|
||||
@Nullable
|
||||
public BlockPosition a(StructureGenerator<?> structuregenerator, BlockPosition blockposition, int i, boolean flag) {
|
||||
|
@ -549,7 +548,7 @@
|
|||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1149,7 +1355,13 @@
|
||||
@@ -1149,7 +1356,13 @@
|
||||
@Override
|
||||
public WorldMap a(String s) {
|
||||
return (WorldMap) this.getMinecraftServer().E().getWorldPersistentData().b(() -> {
|
||||
|
@ -564,7 +563,7 @@
|
|||
}, s);
|
||||
}
|
||||
|
||||
@@ -1460,6 +1672,11 @@
|
||||
@@ -1460,6 +1673,11 @@
|
||||
@Override
|
||||
public void update(BlockPosition blockposition, Block block) {
|
||||
if (!this.isDebugWorld()) {
|
||||
|
@ -576,7 +575,7 @@
|
|||
this.applyPhysics(blockposition, block);
|
||||
}
|
||||
|
||||
@@ -1474,12 +1691,12 @@
|
||||
@@ -1474,12 +1692,12 @@
|
||||
}
|
||||
|
||||
public boolean isFlatWorld() {
|
||||
|
@ -591,7 +590,7 @@
|
|||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1499,9 +1716,9 @@
|
||||
@@ -1499,9 +1717,9 @@
|
||||
|
||||
@VisibleForTesting
|
||||
public String F() {
|
||||
|
@ -603,7 +602,7 @@
|
|||
return IRegistry.BLOCK_ENTITY_TYPE.getKey(tileentity.getTileType());
|
||||
}), 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) {
|
||||
try {
|
||||
Object2IntOpenHashMap<MinecraftKey> object2intopenhashmap = new Object2IntOpenHashMap();
|
||||
|
@ -612,7 +611,7 @@
|
|||
|
||||
while (iterator.hasNext()) {
|
||||
T t0 = iterator.next();
|
||||
@@ -1518,7 +1735,8 @@
|
||||
@@ -1518,7 +1736,8 @@
|
||||
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();
|
||||
}).collect(Collectors.joining(","));
|
||||
} catch (Exception exception) {
|
||||
@@ -1527,16 +1745,32 @@
|
||||
@@ -1527,16 +1746,32 @@
|
||||
}
|
||||
|
||||
public static void a(WorldServer worldserver) {
|
||||
|
|
Loading…
Reference in a new issue