Commits

DerFrZocker authored and md_5 committed 1851857b78b
SPIGOT-3071, #969: Add entity spawn method with spawn reason
No tags

src/main/java/org/bukkit/World.java

Modified
14 14 import org.bukkit.boss.DragonBattle;
15 15 import org.bukkit.entity.AbstractArrow;
16 16 import org.bukkit.entity.Arrow;
17 17 import org.bukkit.entity.Entity;
18 18 import org.bukkit.entity.FallingBlock;
19 19 import org.bukkit.entity.Item;
20 20 import org.bukkit.entity.LightningStrike;
21 21 import org.bukkit.entity.LivingEntity;
22 22 import org.bukkit.entity.Player;
23 23 import org.bukkit.entity.SpawnCategory;
24 +import org.bukkit.event.entity.CreatureSpawnEvent;
24 25 import org.bukkit.generator.BiomeProvider;
25 26 import org.bukkit.generator.BlockPopulator;
26 27 import org.bukkit.generator.ChunkGenerator;
27 28 import org.bukkit.generator.WorldInfo;
28 29 import org.bukkit.generator.structure.Structure;
29 30 import org.bukkit.generator.structure.StructureType;
30 31 import org.bukkit.inventory.ItemStack;
31 32 import org.bukkit.material.MaterialData;
32 33 import org.bukkit.metadata.Metadatable;
33 34 import org.bukkit.persistence.PersistentDataHolder;
1171 1172 public void save();
1172 1173
1173 1174 /**
1174 1175 * Gets a list of all applied {@link BlockPopulator}s for this World
1175 1176 *
1176 1177 * @return List containing any or none BlockPopulators
1177 1178 */
1178 1179 @NotNull
1179 1180 public List<BlockPopulator> getPopulators();
1180 1181
1182 + /**
1183 + * Creates a new entity at the given {@link Location} with the supplied
1184 + * function run before the entity is added to the world.
1185 + * <br>
1186 + * Note that when the function is run, the entity will not be actually in
1187 + * the world. Any operation involving such as teleporting the entity is undefined
1188 + * until after this function returns.
1189 + * The passed function however is run after the potential entity's spawn
1190 + * randomization and hence already allows access to the values of the mob,
1191 + * whether or not those were randomized, such as attributes or the entity
1192 + * equipment.
1193 + *
1194 + * @param location the location at which the entity will be spawned.
1195 + * @param clazz the class of the {@link LivingEntity} that is to be spawned.
1196 + * @param <T> the generic type of the entity that is being created.
1197 + * @param spawnReason the reason provided during the {@link CreatureSpawnEvent} call.
1198 + * @param randomizeData whether or not the entity's data should be randomised
1199 + * before spawning. By default entities are randomised
1200 + * before spawning in regards to their equipment, age,
1201 + * attributes, etc.
1202 + * An example of this randomization would be the color of
1203 + * a sheep, random enchantments on the equipment of mobs
1204 + * or even a zombie becoming a chicken jockey.
1205 + * If set to false, the entity will not be randomised
1206 + * before spawning, meaning all their data will remain
1207 + * in their default state and not further modifications
1208 + * to the entity will be made.
1209 + * Notably only entities that extend the
1210 + * {@link org.bukkit.entity.Mob} interface provide
1211 + * randomisation logic for their spawn.
1212 + * This parameter is hence useless for any other type
1213 + * of entity.
1214 + * @param function the function to be run before the entity is spawned.
1215 + * @return the spawned entity instance.
1216 + * @throws IllegalArgumentException if either the world or clazz parameter are null.
1217 + */
1218 + @NotNull
1219 + public <T extends LivingEntity> T spawn(@NotNull Location location, @NotNull Class<T> clazz, @NotNull CreatureSpawnEvent.SpawnReason spawnReason, boolean randomizeData, @Nullable Consumer<? super T> function) throws IllegalArgumentException;
1220 +
1181 1221 /**
1182 1222 * Spawn a {@link FallingBlock} entity at the given {@link Location} of
1183 1223 * the specified {@link MaterialData}. The MaterialData dictates what is falling.
1184 1224 * When the FallingBlock hits the ground, it will place that block.
1185 1225 * <p>
1186 1226 * The Material must be a block type, check with {@link Material#isBlock()
1187 1227 * data.getItemType().isBlock()}. The Material may not be air.
1188 1228 *
1189 1229 * @param location The {@link Location} to spawn the FallingBlock
1190 1230 * @param data The block data

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut