Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Pose;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -97,6 +98,8 @@ class Holder {

String getTranslationKey(EntityType entityType);

SpawnCategory getSpawnCategory(EntityType entityType);

/*
* Called once by the version command on first use, then cached.
*/
Expand Down
11 changes: 11 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/EntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@ public String getTranslationKey() {
return InternalAPIBridge.get().getTranslationKey(this);
}

/**
* Gets the spawn category of this entity type.
*
* @return the spawn category
* @throws IllegalArgumentException if the entity does not have a spawn category (is probably a custom entity)
*/
public @NotNull SpawnCategory getSpawnCategory() {
Preconditions.checkArgument(this != UNKNOWN, "UNKNOWN entities do not have a spawn category");
return InternalAPIBridge.get().getSpawnCategory(this);
}

/**
* Checks if the entity has default attributes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.craftbukkit.util.CraftSpawnCategory;
import org.bukkit.damage.DamageEffect;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Pose;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -111,6 +113,11 @@ public CombatEntry createCombatEntry(
);
}

@Override
public SpawnCategory getSpawnCategory(EntityType entityType) {
return CraftSpawnCategory.toBukkit(CraftEntityType.bukkitToMinecraft(entityType).getCategory());
}

private CombatEntry createCombatEntry(
final net.minecraft.world.damagesource.DamageSource damageSource,
final float damage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public void testTranslationKey() {
}
}
}

@Test
void testGetSpawnCategory() {
for (EntityType type : EntityType.values()) {
if (type == EntityType.UNKNOWN) continue;
assertNotNull(type.getSpawnCategory(), "SpawnCategory should not be null for " + type);
}
}
}
Loading