[SPIGOT-4766] Setting Villager profession doesn't persist Created: 26/Apr/19  Updated: 28/Jul/23  Resolved: 05/May/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Intelli Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: 1.14

Attachments: File VillagerSpawnExample.jar     Zip Archive VillagerSpawnExample.zip    
Issue Links:
Duplicate
is duplicated by SPIGOT-7421 spawn a villager and setProfession, P... Resolved
Relates
relates to SPIGOT-4834 Add way to get/set Villager levels Resolved
Version: This server is running CraftBukkit version git-Spigot-766dab2-e2bbf62 (MC: 1.14) (Implementing API version 1.14-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

 When setting the villager profession, the new profession is applied for a tick or so, and then resets back to the default profession.

For example:

Entity entity = location.getWorld().spawnEntity(location, EntityType.VILLAGER);
Villager villager = (Villager) entity;
System.out.println("Spawned Villager. Current Profession: " + villager.getProfession().name());
                
villager.setProfession(Profession.BUTCHER);
System.out.println("Modified Villager. Current Profession: " + villager.getProfession().name());
                
 final Villager villagerFinal = villager;
 getServer().getScheduler().scheduleSyncDelayedTask(instance, new Runnable() {
  @Override
  public void run() {
    try {
      System.out.println("1 Second Wait. Current Profession: " + villagerFinal.getProfession().name());
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}, 20);

Console Output:

[23:23:14] [Server thread/INFO]: Spawned Villager. Current Profession: NONE
[23:23:14] [Server thread/INFO]: Modified Villager. Current Profession: BUTCHER
[23:23:15] [Server thread/INFO]: 1 Second Wait. Current Profession: NONE

Expected Output: (CraftBukkit version git-Spigot-e5e5c7c-c24abab (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT))

[23:30:14 INFO]: Spawned Villager. Current Profession: LIBRARIAN
[23:30:14 INFO]: Modified Villager. Current Profession: BUTCHER
[23:30:15 INFO]: 1 Second Wait. Current Profession: BUTCHER



 Comments   
Comment by Intelli [ 01/May/19 ]

I’ve created a new ticket here specific to getting/setting villager levels: https://hub.spigotmc.org/jira/browse/SPIGOT-4834

Comment by Linus Närkling [ 30/Apr/19 ]

I wrote about `getLevel()` and `setLevel()` in a suggestion ticket here: https://hub.spigotmc.org/jira/browse/SPIGOT-4820#

I also made a suggestion for a potential implementation but not really sure if it helps.

Comment by Intelli [ 27/Apr/19 ]

Should I close this and open a new ticket regarding a way to get/set villager levels?

Comment by md_5 [ 26/Apr/19 ]

Gonna leave this open for now, but

 

<~md_5> Intelli your bug isnt really a bug
<~md_5> kind of
<~md_5> the problem is you didnt set the villager's level
<Intelli> Oh?
<~md_5> so cause their level is too low for your selected profession
<~md_5> they devolve into no profession
<Intelli> ahhh
<Intelli> How do I set the level?
<~md_5> well uh
<~md_5> dont know if you can
<DiamondDagger590> There isnt a way rn
<DiamondDagger590> I'm working on that
<Intelli> :(
<DiamondDagger590> :D
<Intelli> Alright <3
<DiamondDagger590> Well you "can" via nbt tag I believe
<DiamondDagger590> but as of now there is now method for doing it in the Villager class
<~md_5> basically if their experience == 0 and their level <=1 and theyre not a nitwit, they get reset
<Intelli> Makes sense 
Generated at Tue Apr 22 03:00:30 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.