SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class

This commit is contained in:
DerFrZocker 2024-02-17 14:04:58 +11:00 committed by md_5
parent 76d95fe7ed
commit 5bf12cb89d
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -479,14 +479,20 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
} else if (clazz == SplashPotion.class) { } else if (clazz == SplashPotion.class) {
clazz = ThrownPotion.class; clazz = ThrownPotion.class;
} else if (clazz == TippedArrow.class) { } else if (clazz == TippedArrow.class) {
clazz = Arrow.class; clazz = Arrow.class;
runOld = other -> ((Arrow) other.getBukkitEntity()).setBasePotionType(PotionType.WATER); runOld = other -> ((Arrow) other.getBukkitEntity()).setBasePotionType(PotionType.WATER);
} }
CraftEntityTypes.EntityTypeData<?, ?> entityTypeData = CraftEntityTypes.getEntityTypeData(clazz); CraftEntityTypes.EntityTypeData<?, ?> entityTypeData = CraftEntityTypes.getEntityTypeData(clazz);
if (entityTypeData == null || entityTypeData.spawnFunction() == null) { if (entityTypeData == null || entityTypeData.spawnFunction() == null) {
throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName()); if (CraftEntity.class.isAssignableFrom(clazz)) {
// SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
throw new IllegalArgumentException(String.format("Cannot spawn an entity from its CraftBukkit implementation class '%s' use the Bukkit class instead. "
+ "You can get the Bukkit representation via Entity#getType()#getEntityClass()", clazz.getName()));
} else {
throw new IllegalArgumentException("Cannot spawn an entity for " + clazz.getName());
}
} }
if (!entityTypeData.entityType().isEnabledByFeature(getHandle().getMinecraftWorld().getWorld())) { if (!entityTypeData.entityType().isEnabledByFeature(getHandle().getMinecraftWorld().getWorld())) {