Skip to content
Merged
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
19 changes: 15 additions & 4 deletions paper-api/src/main/java/org/bukkit/entity/EntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public String getTranslationKey() {

// Paper start
/**
* @throws IllegalArgumentException if the entity does not have a translation key (is probably a custom entity)
* @throws IllegalArgumentException if the entity does not have a translation key
*/
@Override
public @NotNull String translationKey() {
Expand All @@ -344,7 +344,18 @@ public String getTranslationKey() {
}

/**
* Checks if the entity has default attributes.
* Gets the spawn category of this entity type.
*
* @return the spawn category
* @throws IllegalArgumentException if the entity does not have a spawn category
*/
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 type has default attributes.
*
* @return true if it has default attributes
*/
Expand All @@ -356,10 +367,10 @@ public boolean hasDefaultAttributes() {
}

/**
* Gets the default attributes for the entity.
* Gets the default attributes for the entity type.
*
* @return an unmodifiable instance of Attributable for reading default attributes.
* @throws IllegalArgumentException if the entity does not exist of have default attributes (use {@link #hasDefaultAttributes()} first)
* @throws IllegalArgumentException if it doesn't have default attributes (use {@link #hasDefaultAttributes()} first)
*/
public @NotNull org.bukkit.attribute.Attributable getDefaultAttributes() {
Preconditions.checkArgument(this.hasDefaultAttributes(), this.key + " doesn't have 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 @@ -179,6 +181,11 @@ public String getTranslationKey(final EntityType entityType) {
return CraftEntityType.bukkitToMinecraft(entityType).getDescriptionId();
}

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

@Override
public VersionFetcher getVersionFetcher() {
return new PaperVersionFetcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public static long getDefaultTicksPerSpawn(SpawnCategory spawnCategory) {
};
}

public static SpawnCategory toBukkit(MobCategory enumCreatureType) {
return switch (enumCreatureType) {
public static SpawnCategory toBukkit(MobCategory category) {
return switch (category) {
case MONSTER -> SpawnCategory.MONSTER;
case CREATURE -> SpawnCategory.ANIMAL;
case AMBIENT -> SpawnCategory.AMBIENT;
Expand All @@ -53,7 +53,6 @@ public static SpawnCategory toBukkit(MobCategory enumCreatureType) {
case WATER_AMBIENT -> SpawnCategory.WATER_AMBIENT;
case UNDERGROUND_WATER_CREATURE -> SpawnCategory.WATER_UNDERGROUND_CREATURE;
case MISC -> SpawnCategory.MISC;
default -> throw new UnsupportedOperationException("Unknown EnumCreatureType " + enumCreatureType + " for SpawnCategory");
};
}

Expand All @@ -67,7 +66,6 @@ public static MobCategory toNMS(SpawnCategory spawnCategory) {
case WATER_AMBIENT -> MobCategory.WATER_AMBIENT;
case WATER_UNDERGROUND_CREATURE -> MobCategory.UNDERGROUND_WATER_CREATURE;
case MISC -> MobCategory.MISC;
default -> throw new UnsupportedOperationException("Unknown SpawnCategory " + spawnCategory + " for EnumCreatureType");
};
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.bukkit.entity;

import net.minecraft.world.entity.MobCategory;
import org.bukkit.craftbukkit.util.CraftSpawnCategory;
import org.bukkit.support.environment.Normal;
import org.junit.jupiter.api.Test;
Expand All @@ -10,20 +9,12 @@ public class SpawnCategoryTest {

@Test
public void testMatch() {
for (MobCategory enumCreatureType : MobCategory.values()) {
// If it is missing a convert to Bukkit then throw a UnsupportedOperationException
SpawnCategory spawnCategory = CraftSpawnCategory.toBukkit(enumCreatureType);

if (CraftSpawnCategory.isValidForLimits(spawnCategory)) {
long defaultTicks = CraftSpawnCategory.getDefaultTicksPerSpawn(spawnCategory);
String nameConfigSpawnLimit = CraftSpawnCategory.getConfigNameSpawnLimit(spawnCategory);
String nameConfigTicksPerSpawn = CraftSpawnCategory.getConfigNameTicksPerSpawn(spawnCategory);
for (SpawnCategory category : SpawnCategory.values()) {
if (CraftSpawnCategory.isValidForLimits(category)) {
long defaultTicks = CraftSpawnCategory.getDefaultTicksPerSpawn(category);
String nameConfigSpawnLimit = CraftSpawnCategory.getConfigNameSpawnLimit(category);
String nameConfigTicksPerSpawn = CraftSpawnCategory.getConfigNameTicksPerSpawn(category);
}
}

for (SpawnCategory spawnCategory : SpawnCategory.values()) {
// If it is missing a convert to NMS then throw a UnsupportedOperationException
MobCategory enumCreatureType = CraftSpawnCategory.toNMS(spawnCategory);
}
}
}