From 6dc11b5d281d5d506449b8f88322fbd27f002de7 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 17 Feb 2024 14:04:58 +1100 Subject: [PATCH] SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class By: DerFrZocker --- .../org/bukkit/craftbukkit/CraftRegionAccessor.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index 96dce74c3e..2a5c17001e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -479,14 +479,20 @@ public abstract class CraftRegionAccessor implements RegionAccessor { } else if (clazz == SplashPotion.class) { clazz = ThrownPotion.class; } else if (clazz == TippedArrow.class) { - clazz = Arrow.class; - runOld = other -> ((Arrow) other.getBukkitEntity()).setBasePotionType(PotionType.WATER); + clazz = Arrow.class; + runOld = other -> ((Arrow) other.getBukkitEntity()).setBasePotionType(PotionType.WATER); } CraftEntityTypes.EntityTypeData entityTypeData = CraftEntityTypes.getEntityTypeData(clazz); 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())) {