[SPIGOT-7565] Can no longer spawn entity using implementation class Created: 09/Jan/24 Updated: 25/Dec/24 Resolved: 25/Apr/24 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | tastybento | Assignee: | Marvin Rieple |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Attachments: |
|
| Version: | This server is running CraftBukkit version 4012-Spigot-864e4ac-76931e8 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) |
| Guidelines Read: | Yes |
| Description |
|
When trying to spawn an entity using World#spawn I get a console error. This was working on previous versions of the server, but appears to have stopped recently. Minimal plugin public class TestPlugin extends JavaPlugin implements Listener { @Override public void onEnable() { getLogger().info("Test plugin loaded"); Bukkit.getPluginManager().registerEvents(this, this); } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onCreatureSpawn(final CreatureSpawnEvent e) { e.setCancelled(true); e.getLocation().getWorld().spawn(e.getLocation(), e.getEntity().getClass()); // Delaying spawn by waiting a tick also doesn't work and causes an error. } } This is just the minimal way to cause the error. The actual method I usually use is World#spawn(location, entity class, function), where the function runs some clean up before the creature spawns, but I found that even without this, the error still occurs. The error when trying to make a golem is: [12:30:23] [Server thread/ERROR]: Could not pass event CreatureSpawnEvent to TestPlugin v1.0 org.bukkit.event.EventException: null at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?] at org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory.callCreatureSpawnEvent(CraftEventFactory.java:748) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory.doEntityAddEventCalling(CraftEventFactory.java:667) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.level.WorldServer.addEntity(WorldServer.java:1097) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.level.WorldServer.addFreshEntity(WorldServer.java:1034) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.world.level.block.BlockPumpkinCarved.a(BlockPumpkinCarved.java:96) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.world.level.block.BlockPumpkinCarved.a(BlockPumpkinCarved.java:85) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.world.level.block.BlockPumpkinCarved.b(BlockPumpkinCarved.java:60) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.world.item.ItemStack.a(ItemStack.java:425) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.level.PlayerInteractManager.a(PlayerInteractManager.java:559) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.network.PlayerConnection.a(PlayerConnection.java:1580) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.network.protocol.game.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.network.protocol.game.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.network.protocol.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:33) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.TickTask.run(SourceFile:18) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.util.thread.IAsyncTaskHandler.d(SourceFile:156) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.util.thread.IAsyncTaskHandlerReentrant.d(SourceFile:23) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1191) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:1) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.util.thread.IAsyncTaskHandler.x(SourceFile:130) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.MinecraftServer.bl(MinecraftServer.java:1170) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1163) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.util.thread.IAsyncTaskHandler.c(SourceFile:139) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.MinecraftServer.w_(MinecraftServer.java:1147) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1060) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:304) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at java.lang.Thread.run(Thread.java:840) ~[?:?] Caused by: java.lang.IllegalArgumentException: Cannot spawn an entity for org.bukkit.craftbukkit.v1_20_R3.entity.CraftIronGolem at org.bukkit.craftbukkit.v1_20_R3.CraftRegionAccessor.createEntity(CraftRegionAccessor.java:489) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at org.bukkit.craftbukkit.v1_20_R3.CraftRegionAccessor.spawn(CraftRegionAccessor.java:407) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at org.bukkit.craftbukkit.v1_20_R3.CraftRegionAccessor.spawn(CraftRegionAccessor.java:403) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at org.bukkit.craftbukkit.v1_20_R3.CraftRegionAccessor.spawn(CraftRegionAccessor.java:389) ~[spigot-1.20.4-R0.1-SNAPSHOT.jar:4012-Spigot-864e4ac-76931e8] at us.tastybento.test.TestPlugin.onCreatureSpawn(TestPlugin.java:33) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-api-1.20.4-R0.1-SNAPSHOT.jar:?] ... 29 more [ The same error coincidentally popped up when Phantoms were trying to spawn. |
| Comments |
| Comment by Marvin Rieple [ 25/Apr/24 ] |
|
The error messages was changed to make it more clear that this is not supported. |
| Comment by Marvin Rieple [ 16/Feb/24 ] |
|
Made a PR for this: craftbukkit#1356, which ads a more descriptive error message. You can test it with BuildTools: java -jar BuildTools.jar --rev 4046 --compile spigot --pr craftbukkit:1356 |
| Comment by md_5 [ 10/Jan/24 ] |
|
I think you can, good pickup! |
| Comment by Shane Bee [ 10/Jan/24 ] |
|
Correct me if Im wrong, but I believe you could do: entity.getType().getEntityClass() |
| Comment by md_5 [ 09/Jan/24 ] |
|
getClass() returns CraftIronGolem.class not IronGolem.class |
| Comment by tastybento [ 09/Jan/24 ] |
|
Yes, it does. I must have made a mistake. But this code doesn't:
public void onCreatureSpawn(final CreatureSpawnEvent e) {
if (e.getSpawnReason().equals(SpawnReason.BUILD_IRONGOLEM)) {
e.setCancelled(true);
if (e.getEntity() instanceof IronGolem ig) {
e.getLocation().getWorld().spawn(e.getLocation(), ig.getClass());
}
}
}
I guess it's because the class provided by e.getEntity() is a LivingEntity and not a "true" IronGolem. I can work around this (and I have) so it's not a major issue, but I don't why the classes aren't compatible. Anyway, I have worked around this by checking the build type and then specifying it exactly, but this is a weird one! |
| Comment by md_5 [ 09/Jan/24 ] |
|
> e.getLocation().getWorld().spawn(e.getLocation(), IronGolem.class); This code works completely fine, are you sure you tested correctly? |
| Comment by tastybento [ 09/Jan/24 ] |
|
Oh, I suspect you meant I should use: e.getLocation().getWorld().spawnEntity(e.getLocation(), EntityType.IRON_GOLEM); I think I can, but I was using spawn because it has the optional prespawn operation, e.g.: e.getLocation().getWorld().spawn(e.getLocation(), IronGolem.class, entity -> preSpawn(entity)); |
| Comment by tastybento [ 09/Jan/24 ] |
|
I'm sorry, I don't understand what an API interface would be in this instance or how I would use EntityType here. Could you give me a code example? I was working from the JavaDoc] where it says "clazz - the class of the Entity to spawn". Trying: `e.getLocation().getWorld().spawn(e.getLocation(), IronGolem.class);` doesn't work. I'm not sure how else to specify an IronGolem.
|
| Comment by md_5 [ 09/Jan/24 ] |
|
Sorry the issue is your code. You are passing an implementation class to spawnEntity rather than an API interface. Suggest using EntityType instead. This is a change in implementation but I'm not sure your code is necessarily consistent with the API specification. |
| Comment by tastybento [ 09/Jan/24 ] |
|
I just tried with some spawn eggs, and it seems to affect all entites that I tried, e.g. bee, chicken, etc. |
| Comment by md_5 [ 09/Jan/24 ] |
|
This is likely specific to iron golems and/or phantoms and not all entities. |