Interface Villager

All Superinterfaces:
AbstractVillager, Ageable, Attributable, Breedable, CommandSender, Creature, Damageable, Entity, InventoryHolder, LivingEntity, Lootable, Merchant, Metadatable, Mob, Nameable, NPC, Permissible, PersistentDataHolder, ProjectileSource, ServerOperator

public interface Villager extends AbstractVillager
Represents a villager NPC
  • Method Details

    • getProfession

      @NotNull Villager.Profession getProfession()
      Gets the current profession of this villager.
      Returns:
      Current profession.
    • setProfession

      void setProfession(@NotNull Villager.Profession profession)
      Sets the new profession of this villager.
      Parameters:
      profession - New profession.
    • getVillagerType

      @NotNull Villager.Type getVillagerType()
      Gets the current type of this villager.
      Returns:
      Current type.
    • setVillagerType

      void setVillagerType(@NotNull Villager.Type type)
      Sets the new type of this villager.
      Parameters:
      type - New type.
    • getVillagerLevel

      int getVillagerLevel()
      Gets the level of this villager. A villager with a level of 1 and no experience is liable to lose its profession.
      Returns:
      this villager's level
    • setVillagerLevel

      void setVillagerLevel(int level)
      Sets the level of this villager. A villager with a level of 1 and no experience is liable to lose its profession.
      Parameters:
      level - the new level
      Throws:
      IllegalArgumentException - if level not between [1, 5]
    • getVillagerExperience

      int getVillagerExperience()
      Gets the trading experience of this villager.
      Returns:
      trading experience
    • setVillagerExperience

      void setVillagerExperience(int experience)
      Sets the trading experience of this villager.
      Parameters:
      experience - new experience
      Throws:
      IllegalArgumentException - if experience < 0
    • sleep

      boolean sleep(@NotNull Location location)
      Attempts to make this villager sleep at the given location.
      The location must be in the current world and have a bed placed at the location. The villager will put its head on the specified block while sleeping.
      Parameters:
      location - the location of the bed
      Returns:
      whether the sleep was successful
    • wakeup

      void wakeup()
      Causes this villager to wake up if he's currently sleeping.
      Throws:
      IllegalStateException - if not sleeping
    • shakeHead

      void shakeHead()
      Causes this villager to shake his head.
    • zombify

      @Nullable ZombieVillager zombify()
      Convert this Villager into a ZombieVillager as if it was killed by a Zombie. Note: this will fire a EntityTransformEvent
      Returns:
      the converted entity ZombieVillager or null if the conversion its cancelled
    • getReputation

      int getReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType)
      Gets the reputation of an entity for a given type.
      Parameters:
      uuid - the UUID of the entity whose reputation is being checked
      reputationType - reputation type to be retrieved
      Returns:
      current reputation for the given reputation type
    • getWeightedReputation

      int getWeightedReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType)
      Gets the weighted reputation of an entity for a given type.

      The total reputation of an entity is a sum of its weighted reputations of each type, where the reputation is multiplied by weight assigned to its type.

      Parameters:
      uuid - the UUID of the entity whose reputation is being checked
      reputationType - reputation type to be retrieved
      Returns:
      current reputation for the given reputation type
      See Also:
    • getReputation

      int getReputation(@NotNull UUID uuid)
      Gets the reputation of an entity.
      Parameters:
      uuid - the UUID of the entity whose reputation is being checked
      Returns:
      current reputation for the given reputation type
    • addReputation

      void addReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType, int amount)
      Add reputation of a given type towards a given entity.

      The final value will be clamped to the maximum value supported by the provided reputation type. If the final value is below the reputation discard threshold, gossip associated with this reputation type will be removed.

      Note: this will fire a VillagerReputationChangeEvent.

      Parameters:
      uuid - the UUID of the entity for whom the reputation is being added
      reputationType - reputation type to be modified
      amount - amount of reputation to add
    • addReputation

      void addReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType, int amount, @NotNull Villager.ReputationEvent changeReason)
      Add reputation of a given type towards a given entity, with a specific change reason.

      The final value will be clamped to the maximum value supported by the provided reputation type. If the final value is below the reputation discard threshold, gossip associated with this reputation type will be removed.

      Note: this will fire a VillagerReputationChangeEvent.

      Parameters:
      uuid - the UUID of the entity for whom the reputation is being added
      reputationType - reputation type to be modified
      amount - amount of reputation to add
      changeReason - reputation change reason
    • removeReputation

      void removeReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType, int amount)
      Remove reputation of a given type towards a given entity.

      The final value will be clamped to the maximum value supported by the provided reputation type. If the final value is below the reputation discard threshold, gossip associated with this reputation type will be removed.

      Note: this will fire a VillagerReputationChangeEvent.

      Parameters:
      uuid - the UUID of the entity for whom the reputation is being removed
      reputationType - reputation type to be modified
      amount - amount of reputation to remove
    • removeReputation

      void removeReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType, int amount, @NotNull Villager.ReputationEvent changeReason)
      Remove reputation of a given type towards a given entity, with a specific change reason.

      The final value will be clamped to the maximum value supported by the provided reputation type. If the final value is below the reputation discard threshold, gossip associated with this reputation type will be removed.

      Note: this will fire a VillagerReputationChangeEvent.

      Parameters:
      uuid - the UUID of the entity for whom the reputation is being removed
      reputationType - reputation type to be modified
      amount - amount of reputation to remove
      changeReason - reputation change reason
    • setReputation

      void setReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType, int amount)
      Set reputation of a given type towards a given entity.

      The final value will be clamped to the maximum value supported by the provided reputation type. If the final value is below the reputation discard threshold, gossip associated with this reputation type will be removed.

      Note: this will fire a VillagerReputationChangeEvent.

      Parameters:
      uuid - the UUID of the entity for whom the reputation is being added
      reputationType - reputation type to be modified
      amount - amount of reputation to add
    • setReputation

      void setReputation(@NotNull UUID uuid, @NotNull Villager.ReputationType reputationType, int amount, @NotNull Villager.ReputationEvent changeReason)
      Set reputation of a given type towards a given entity, with a specific change reason.

      The final value will be clamped to the maximum value supported by the provided reputation type. If the final value is below the reputation discard threshold, gossip associated with this reputation type will be removed.

      Note: this will fire a VillagerReputationChangeEvent.

      Parameters:
      uuid - the UUID of the entity for whom the reputation is being added
      reputationType - reputation type to be modified
      amount - amount of reputation to add
      changeReason - reputation change reason
    • setGossipDecayTime

      void setGossipDecayTime(long ticks)
      Sets the reputation decay time for this villager.

      Defaults to 24000 (1 daylight cycle).

      Parameters:
      ticks - amount of ticks until the villager's reputation decays
    • getGossipDecayTime

      long getGossipDecayTime()
      Gets the reputation decay time for this villager.

      Defaults to 24000 (1 daylight cycle).

      Returns:
      amount of ticks until the villager's reputation decays