001 package org.bukkit.entity; 002 003 import java.util.Collection; 004 import java.util.HashSet; 005 import java.util.List; 006 007 import org.bukkit.Location; 008 import org.bukkit.block.Block; 009 import org.bukkit.inventory.EntityEquipment; 010 import org.bukkit.potion.PotionEffect; 011 import org.bukkit.potion.PotionEffectType; 012 import org.bukkit.projectiles.ProjectileSource; 013 014 /** 015 * Represents a living entity, such as a monster or player 016 */ 017 public interface LivingEntity extends Entity, Damageable, ProjectileSource { 018 019 /** 020 * Gets the height of the living entity's eyes above its Location. 021 * 022 * @return height of the living entity's eyes above its location 023 */ 024 public double getEyeHeight(); 025 026 /** 027 * Gets the height of the living entity's eyes above its Location. 028 * 029 * @param ignoreSneaking if set to true, the effects of sneaking will be 030 * ignored 031 * @return height of the living entity's eyes above its location 032 */ 033 public double getEyeHeight(boolean ignoreSneaking); 034 035 /** 036 * Get a Location detailing the current eye position of the living entity. 037 * 038 * @return a location at the eyes of the living entity 039 */ 040 public Location getEyeLocation(); 041 042 /** 043 * Gets all blocks along the living entity's line of sight. 044 * <p> 045 * This list contains all blocks from the living entity's eye position to 046 * target inclusive. 047 * 048 * @param transparent HashSet containing all transparent block IDs (set to 049 * null for only air) 050 * @param maxDistance this is the maximum distance to scan (may be limited 051 * by server by at least 100 blocks, no less) 052 * @return list containing all blocks along the living entity's line of 053 * sight 054 * @deprecated Magic value 055 */ 056 @Deprecated 057 public List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance); 058 059 /** 060 * Gets the block that the living entity has targeted. 061 * 062 * @param transparent HashSet containing all transparent block IDs (set to 063 * null for only air) 064 * @param maxDistance this is the maximum distance to scan (may be limited 065 * by server by at least 100 blocks, no less) 066 * @return block that the living entity has targeted 067 * @deprecated Magic value 068 */ 069 @Deprecated 070 public Block getTargetBlock(HashSet<Byte> transparent, int maxDistance); 071 072 /** 073 * Gets the last two blocks along the living entity's line of sight. 074 * <p> 075 * The target block will be the last block in the list. 076 * 077 * @param transparent HashSet containing all transparent block IDs (set to 078 * null for only air) 079 * @param maxDistance this is the maximum distance to scan. This may be 080 * further limited by the server, but never to less than 100 blocks 081 * @return list containing the last 2 blocks along the living entity's 082 * line of sight 083 * @deprecated Magic value 084 */ 085 @Deprecated 086 public List<Block> getLastTwoTargetBlocks(HashSet<Byte> transparent, int maxDistance); 087 088 /** 089 * Throws an egg from the living entity. 090 * 091 * @deprecated use launchProjectile(Egg.class) instead 092 * @return the egg thrown 093 */ 094 @Deprecated 095 public Egg throwEgg(); 096 097 /** 098 * Throws a snowball from the living entity. 099 * 100 * @deprecated use launchProjectile(Snowball.class) instead 101 * @return the snowball thrown 102 */ 103 @Deprecated 104 public Snowball throwSnowball(); 105 106 /** 107 * Shoots an arrow from the living entity. 108 * 109 * @deprecated use launchProjectile(Arrow.class) instead 110 * @return the arrow shot 111 */ 112 @Deprecated 113 public Arrow shootArrow(); 114 115 /** 116 * Returns the amount of air that the living entity has remaining, in 117 * ticks. 118 * 119 * @return amount of air remaining 120 */ 121 public int getRemainingAir(); 122 123 /** 124 * Sets the amount of air that the living entity has remaining, in ticks. 125 * 126 * @param ticks amount of air remaining 127 */ 128 public void setRemainingAir(int ticks); 129 130 /** 131 * Returns the maximum amount of air the living entity can have, in ticks. 132 * 133 * @return maximum amount of air 134 */ 135 public int getMaximumAir(); 136 137 /** 138 * Sets the maximum amount of air the living entity can have, in ticks. 139 * 140 * @param ticks maximum amount of air 141 */ 142 public void setMaximumAir(int ticks); 143 144 /** 145 * Returns the living entity's current maximum no damage ticks. 146 * <p> 147 * This is the maximum duration in which the living entity will not take 148 * damage. 149 * 150 * @return maximum no damage ticks 151 */ 152 public int getMaximumNoDamageTicks(); 153 154 /** 155 * Sets the living entity's current maximum no damage ticks. 156 * 157 * @param ticks maximum amount of no damage ticks 158 */ 159 public void setMaximumNoDamageTicks(int ticks); 160 161 /** 162 * Returns the living entity's last damage taken in the current no damage 163 * ticks time. 164 * <p> 165 * Only damage higher than this amount will further damage the living 166 * entity. 167 * 168 * @return damage taken since the last no damage ticks time period 169 */ 170 public double getLastDamage(); 171 172 /** 173 * This method exists for legacy reasons to provide backwards 174 * compatibility. It will not exist at runtime and should not be used 175 * under any circumstances. 176 */ 177 @Deprecated 178 public int _INVALID_getLastDamage(); 179 180 /** 181 * Sets the damage dealt within the current no damage ticks time period. 182 * 183 * @param damage amount of damage 184 */ 185 public void setLastDamage(double damage); 186 187 /** 188 * This method exists for legacy reasons to provide backwards 189 * compatibility. It will not exist at runtime and should not be used 190 * under any circumstances. 191 */ 192 @Deprecated 193 public void _INVALID_setLastDamage(int damage); 194 195 /** 196 * Returns the living entity's current no damage ticks. 197 * 198 * @return amount of no damage ticks 199 */ 200 public int getNoDamageTicks(); 201 202 /** 203 * Sets the living entity's current no damage ticks. 204 * 205 * @param ticks amount of no damage ticks 206 */ 207 public void setNoDamageTicks(int ticks); 208 209 /** 210 * Gets the player identified as the killer of the living entity. 211 * <p> 212 * May be null. 213 * 214 * @return killer player, or null if none found 215 */ 216 public Player getKiller(); 217 218 /** 219 * Adds the given {@link PotionEffect} to the living entity. 220 * <p> 221 * Only one potion effect can be present for a given {@link 222 * PotionEffectType}. 223 * 224 * @param effect PotionEffect to be added 225 * @return whether the effect could be added 226 */ 227 public boolean addPotionEffect(PotionEffect effect); 228 229 /** 230 * Adds the given {@link PotionEffect} to the living entity. 231 * <p> 232 * Only one potion effect can be present for a given {@link 233 * PotionEffectType}. 234 * 235 * @param effect PotionEffect to be added 236 * @param force whether conflicting effects should be removed 237 * @return whether the effect could be added 238 */ 239 public boolean addPotionEffect(PotionEffect effect, boolean force); 240 241 /** 242 * Attempts to add all of the given {@link PotionEffect} to the living 243 * entity. 244 * 245 * @param effects the effects to add 246 * @return whether all of the effects could be added 247 */ 248 public boolean addPotionEffects(Collection<PotionEffect> effects); 249 250 /** 251 * Returns whether the living entity already has an existing effect of 252 * the given {@link PotionEffectType} applied to it. 253 * 254 * @param type the potion type to check 255 * @return whether the living entity has this potion effect active on them 256 */ 257 public boolean hasPotionEffect(PotionEffectType type); 258 259 /** 260 * Removes any effects present of the given {@link PotionEffectType}. 261 * 262 * @param type the potion type to remove 263 */ 264 public void removePotionEffect(PotionEffectType type); 265 266 /** 267 * Returns all currently active {@link PotionEffect}s on the living 268 * entity. 269 * 270 * @return a collection of {@link PotionEffect}s 271 */ 272 public Collection<PotionEffect> getActivePotionEffects(); 273 274 /** 275 * Checks whether the living entity has block line of sight to another. 276 * <p> 277 * This uses the same algorithm that hostile mobs use to find the closest 278 * player. 279 * 280 * @param other the entity to determine line of sight to 281 * @return true if there is a line of sight, false if not 282 */ 283 public boolean hasLineOfSight(Entity other); 284 285 /** 286 * Returns if the living entity despawns when away from players or not. 287 * <p> 288 * By default, animals are not removed while other mobs are. 289 * 290 * @return true if the living entity is removed when away from players 291 */ 292 public boolean getRemoveWhenFarAway(); 293 294 /** 295 * Sets whether or not the living entity despawns when away from players 296 * or not. 297 * 298 * @param remove the removal status 299 */ 300 public void setRemoveWhenFarAway(boolean remove); 301 302 /** 303 * Gets the inventory with the equipment worn by the living entity. 304 * 305 * @return the living entity's inventory 306 */ 307 public EntityEquipment getEquipment(); 308 309 /** 310 * Sets whether or not the living entity can pick up items. 311 * 312 * @param pickup whether or not the living entity can pick up items 313 */ 314 public void setCanPickupItems(boolean pickup); 315 316 /** 317 * Gets if the living entity can pick up items. 318 * 319 * @return whether or not the living entity can pick up items 320 */ 321 public boolean getCanPickupItems(); 322 323 /** 324 * Sets a custom name on a mob. This name will be used in death messages 325 * and can be sent to the client as a nameplate over the mob. 326 * <p> 327 * Setting the name to null or an empty string will clear it. 328 * <p> 329 * This value has no effect on players, they will always use their real 330 * name. 331 * 332 * @param name the name to set 333 */ 334 public void setCustomName(String name); 335 336 /** 337 * Gets the custom name on a mob. If there is no name this method will 338 * return null. 339 * <p> 340 * This value has no effect on players, they will always use their real 341 * name. 342 * 343 * @return name of the mob or null 344 */ 345 public String getCustomName(); 346 347 /** 348 * Sets whether or not to display the mob's custom name client side. The 349 * name will be displayed above the mob similarly to a player. 350 * <p> 351 * This value has no effect on players, they will always display their 352 * name. 353 * 354 * @param flag custom name or not 355 */ 356 public void setCustomNameVisible(boolean flag); 357 358 /** 359 * Gets whether or not the mob's custom name is displayed client side. 360 * <p> 361 * This value has no effect on players, they will always display their 362 * name. 363 * 364 * @return if the custom name is displayed 365 */ 366 public boolean isCustomNameVisible(); 367 368 /** 369 * Returns whether the entity is currently leashed. 370 * 371 * @return whether the entity is leashed 372 */ 373 public boolean isLeashed(); 374 375 /** 376 * Gets the entity that is currently leading this entity. 377 * 378 * @return the entity holding the leash 379 * @throws IllegalStateException if not currently leashed 380 */ 381 public Entity getLeashHolder() throws IllegalStateException; 382 383 /** 384 * Sets the leash on this entity to be held by the supplied entity. 385 * <p> 386 * This method has no effect on EnderDragons, Withers, Players, or Bats. 387 * Non-living entities excluding leashes will not persist as leash 388 * holders. 389 * 390 * @param holder the entity to leash this entity to 391 * @return whether the operation was successful 392 */ 393 public boolean setLeashHolder(Entity holder); 394 }