Interface Villager
- All Superinterfaces:
AbstractVillager, Ageable, Attributable, Audience, Breedable, CommandSender, Creature, Damageable, DataComponentView, Entity, Frictional, HoverEventSource<HoverEvent.ShowEntity>, InventoryHolder, Leashable, LivingEntity, Lootable, Merchant, Metadatable, Mob, Nameable, NPC, Permissible, PersistentDataHolder, PersistentDataViewHolder, Pointered, ProjectileSource, ServerOperator, Sound.Emitter
Represents a villager NPC
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents the various different Villager professions there may be.static interfaceRepresents Villager type, usually corresponding to what biome they spawn in.Nested classes/interfaces inherited from interface Entity
Entity.Spigot -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddTrades(int amount) Gives to this villager some potential new trades based to its profession and level.voidClear all reputations from this villager.Gets the current profession of this villager.getReputation(@NotNull UUID uniqueId) Get thereputationfor a specific player byUUID.Get allreputationsfor all players mapped by theirunique IDs.intGets the amount of times a villager has restocked their trades todayintGets the trading experience of this villager.intGets the level of this villager.Gets the current type of this villager.booleanincreaseLevel(int amount) Increases the level of this villager.voidrestock()Resets uses of all offers for the Villager.voidsetProfession(@NotNull Villager.Profession profession) Sets the new profession of this villager.voidsetReputation(@NotNull UUID uniqueId, Reputation reputation) Set thereputationfor a specific player byUUID.voidsetReputations(@NotNull Map<UUID, Reputation> reputations) Set allreputationsfor all players mapped by theirunique IDs.voidsetRestocksToday(int restocksToday) Sets the amount of times a villager has restocked their trades todayvoidsetVillagerExperience(int experience) Sets the trading experience of this villager.voidsetVillagerLevel(int level) Sets the level of this villager.voidSets the new type of this villager.voidCauses this villager to shake his head.booleanAttempts to make this villager sleep at the given location.voidUpdates the demand for Villager offers.voidwakeup()Causes this villager to wake up if he's currently sleeping.zombify()Convert this Villager into a ZombieVillager as if it was killed by a Zombie.Methods inherited from interface AbstractVillager
getInventory, resetOffersMethods inherited from interface Ageable
getAge, getAgeLock, isAdult, setAdult, setAge, setAgeLock, setBabyMethods inherited from interface Attributable
getAttribute, registerAttributeMethods inherited from interface Audience
clearResourcePacks, clearTitle, closeDialog, deleteMessage, deleteMessage, filterAudience, forEachAudience, hideBossBar, openBook, openBook, playSound, playSound, playSound, removeResourcePacks, removeResourcePacks, removeResourcePacks, removeResourcePacks, removeResourcePacks, resetTitle, sendActionBar, sendActionBar, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeader, sendPlayerListHeaderAndFooter, sendPlayerListHeaderAndFooter, sendResourcePacks, sendResourcePacks, sendResourcePacks, sendTitlePart, showBossBar, showDialog, showTitle, stopSound, stopSoundMethods inherited from interface CommandSender
getName, name, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendPlainMessage, sendRichMessage, sendRichMessageMethods inherited from interface Damageable
damage, damage, damage, getAbsorptionAmount, getHealth, getMaxHealth, heal, heal, resetMaxHealth, setAbsorptionAmount, setHealth, setMaxHealthMethods inherited from interface DataComponentView
getData, getDataOrDefault, hasDataMethods inherited from interface Entity
addPassenger, addScoreboardTag, asHoverEvent, broadcastHurtAnimation, collidesAt, copy, copy, createSnapshot, eject, fromMobSpawner, getAsString, getBoundingBox, getChunk, getEntityId, getEntitySpawnReason, getFacing, getFallDistance, getFireTicks, getFreezeTicks, getHeight, getLastDamageCause, getLocation, getLocation, getMaxFireTicks, getMaxFreezeTicks, getNearbyEntities, getOrigin, getPassenger, getPassengers, getPickItemStack, getPistonMoveReaction, getPitch, getPortalCooldown, getPose, getScheduler, getScoreboardEntryName, getScoreboardTags, getServer, getSpawnCategory, getSwimHighSpeedSplashSound, getSwimSound, getSwimSplashSound, getTicksLived, getTrackedBy, getTrackedPlayers, getType, getUniqueId, getVehicle, getVelocity, getVisualFire, getWidth, getWorld, getX, getY, getYaw, getZ, hasFixedPose, hasGravity, hasNoPhysics, isCustomNameVisible, isDead, isEmpty, isFreezeTickingLocked, isFrozen, isGlowing, isInBubbleColumn, isInLava, isInPowderedSnow, isInRain, isInsideVehicle, isInvisible, isInvulnerable, isInWater, isInWaterOrBubbleColumn, isInWaterOrRain, isInWaterOrRainOrBubbleColumn, isInWorld, isOnGround, isPersistent, isSilent, isSneaking, isTicking, isTrackedBy, isUnderWater, isValid, isVisibleByDefault, isVisualFire, leaveVehicle, lockFreezeTicks, lookAt, lookAt, playEffect, remove, removePassenger, removeScoreboardTag, setCustomNameVisible, setFallDistance, setFireTicks, setFreezeTicks, setGlowing, setGravity, setInvisible, setInvulnerable, setLastDamageCause, setNoPhysics, setPassenger, setPersistent, setPortalCooldown, setPose, setPose, setRotation, setSilent, setSneaking, setTicksLived, setVelocity, setVisibleByDefault, setVisualFire, setVisualFire, spawnAt, spawnAt, spigot, teamDisplayName, teleport, teleport, teleport, teleport, teleport, teleport, teleportAsync, teleportAsync, teleportAsync, teleportAsync, wouldCollideUsingMethods inherited from interface Frictional
getFrictionState, setFrictionStateMethods inherited from interface HoverEventSource
asHoverEventMethods inherited from interface Leashable
getLeashHolder, isLeashed, setLeashHolderMethods inherited from interface LivingEntity
addPotionEffect, addPotionEffect, addPotionEffects, attack, broadcastSlotBreak, broadcastSlotBreak, canBreatheUnderwater, canUseEquipmentSlot, clearActiveItem, clearActivePotionEffects, completeUsingActiveItem, damageItemStack, damageItemStack, getActiveItem, getActiveItemHand, getActiveItemRemainingTime, getActiveItemUsedTime, getActivePotionEffects, getArrowCooldown, getArrowsInBody, getArrowsStuck, getBeeStingerCooldown, getBeeStingersInBody, getBodyYaw, getCanPickupItems, getCategory, getCollidableExemptions, getCombatTracker, getDeathSound, getDrinkingSound, getEatingSound, getEyeHeight, getEyeHeight, getEyeLocation, getFallDamageSound, getFallDamageSoundBig, getFallDamageSoundSmall, getForwardsMovement, getHandRaised, getHandRaisedTime, getHurtDirection, getHurtSound, getItemInUse, getItemInUseTicks, getItemUseRemainingTime, getKiller, getLastDamage, getLastTwoTargetBlocks, getLeashHolder, getLineOfSight, getMaximumAir, getMaximumNoDamageTicks, getMemory, getNextArrowRemoval, getNextBeeStingerRemoval, getNoActionTicks, getNoDamageTicks, getPotionEffect, getRemainingAir, getRemoveWhenFarAway, getShieldBlockingDelay, getSidewaysMovement, getTargetBlock, getTargetBlock, getTargetBlock, getTargetBlockExact, getTargetBlockExact, getTargetBlockFace, getTargetBlockFace, getTargetBlockFace, getTargetBlockInfo, getTargetBlockInfo, getTargetEntity, getTargetEntity, getTargetEntityInfo, getTargetEntityInfo, getUpwardsMovement, getWaypointColor, getWaypointStyle, hasActiveItem, hasAI, hasLineOfSight, hasLineOfSight, hasPotionEffect, isClimbing, isCollidable, isGliding, isHandRaised, isJumping, isLeashed, isRiptiding, isSleeping, isSwimming, knockback, playHurtAnimation, playPickupItemAnimation, playPickupItemAnimation, rayTraceBlocks, rayTraceBlocks, rayTraceEntities, rayTraceEntities, removePotionEffect, setActiveItemRemainingTime, setAI, setArrowCooldown, setArrowsInBody, setArrowsInBody, setArrowsStuck, setBeeStingerCooldown, setBeeStingersInBody, setBodyYaw, setCanPickupItems, setCollidable, setGliding, setHurtDirection, setItemInUseTicks, setJumping, setKiller, setLastDamage, setLeashHolder, setMaximumAir, setMaximumNoDamageTicks, setMemory, setNextArrowRemoval, setNextBeeStingerRemoval, setNoActionTicks, setNoDamageTicks, setRemainingAir, setRemoveWhenFarAway, setRiptiding, setShieldBlockingDelay, setSwimming, setWaypointColor, setWaypointStyle, startUsingItem, swingHand, swingMainHand, swingOffHandMethods inherited from interface Lootable
clearLootTable, getLootTable, getSeed, hasLootTable, setLootTable, setSeedMethods inherited from interface Merchant
getRecipe, getRecipeCount, getRecipes, getTrader, isTrading, setRecipe, setRecipesMethods inherited from interface Metadatable
getMetadata, hasMetadata, removeMetadata, setMetadataMethods inherited from interface Mob
getAmbientSound, getDespawnInPeacefulOverride, getEquipment, getHeadRotationSpeed, getMaxHeadPitch, getPathfinder, getPossibleExperienceReward, getTarget, isAggressive, isAware, isInDaylight, isLeftHanded, lookAt, lookAt, lookAt, lookAt, lookAt, lookAt, setAggressive, setAware, setDespawnInPeacefulOverride, setLeftHanded, setLootTable, setTarget, shouldDespawnInPeacefulMethods inherited from interface Nameable
customName, customName, getCustomName, setCustomNameMethods inherited from interface Permissible
addAttachment, addAttachment, addAttachment, addAttachment, getEffectivePermissions, hasPermission, hasPermission, isPermissionSet, isPermissionSet, permissionValue, permissionValue, recalculatePermissions, removeAttachmentMethods inherited from interface PersistentDataHolder
getPersistentDataContainerMethods inherited from interface Pointered
get, getOrDefault, getOrDefaultFrom, pointersMethods inherited from interface ProjectileSource
launchProjectile, launchProjectile, launchProjectileMethods inherited from interface ServerOperator
isOp, setOp
-
Method Details
-
getProfession
Gets the current profession of this villager.- Returns:
- Current profession.
-
setProfession
Sets the new profession of this villager.- Parameters:
profession- New profession.
-
getVillagerType
Gets the current type of this villager.- Returns:
- Current type.
-
setVillagerType
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. This doesn't update the trades of this villager.- Parameters:
level- the new level- Throws:
IllegalArgumentException- if level not between [1, 5]- See Also:
-
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
-
increaseLevel
boolean increaseLevel(int amount) Increases the level of this villager. The villager will also unlock new recipes unlike the raw methodsetVillagerLevel(int).A villager with a level of 1 and no experience is liable to lose its profession.
A master villager has a level of 5 in its profession.
- Parameters:
amount- The amount of level- Returns:
- Whether level got increased
- Throws:
IllegalArgumentException- if the amount is not positive- See Also:
-
addTrades
boolean addTrades(int amount) Gives to this villager some potential new trades based to its profession and level.- Parameters:
amount- The amount of trades to give- Returns:
- Whether trades are added
- Throws:
IllegalArgumentException- if the amount isn't positive
-
getRestocksToday
int getRestocksToday()Gets the amount of times a villager has restocked their trades today- Returns:
- The amount of trade restocks.
-
setRestocksToday
void setRestocksToday(int restocksToday) Sets the amount of times a villager has restocked their trades today- Parameters:
restocksToday- new restock count
-
sleep
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
Convert this Villager into a ZombieVillager as if it was killed by a Zombie. Note: this will fire a EntityTransformEvent- Returns:
- the converted entity
ZombieVillageror null if the conversion its cancelled
-
getReputation
Get thereputationfor a specific player byUUID.- Parameters:
uniqueId- TheUUIDof the player to get the reputation of.- Returns:
- The player's copied reputation with this villager.
-
getReputations
Get allreputationsfor all players mapped by theirunique IDs.- Returns:
- All
reputationsfor all players in a copied map.
-
setReputation
Set thereputationfor a specific player byUUID.- Parameters:
uniqueId- TheUUIDof the player to set the reputation of.reputation- Thereputationto set.
-
setReputations
Set allreputationsfor all players mapped by theirunique IDs.- Parameters:
reputations- Allreputationsfor all players mapped by theirunique IDs.
-
clearReputations
void clearReputations()Clear all reputations from this villager. This removes every single reputation regardless of its impact and the player associated. -
updateDemand
void updateDemand()Updates the demand for Villager offers. Demand can rise and fall based on how often offers are traded. They can fall when an item is not traded for a while, or rise when the item is resupplied next. Demand is used to calculate the price of items in the Villager's offers.
Note: Demand is stored per item and not per Villager. -
restock
void restock()Resets uses of all offers for the Villager. This also internally callsupdateDemand(). Calling this will trigger aVillagerReplenishTradeEventfor each offer that is restocked. Demand is still updated even if all events are canceled.
-