Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with spawning villagers #174

Closed
TheBentoBox opened this issue Aug 23, 2016 · 3 comments
Closed

Error with spawning villagers #174

TheBentoBox opened this issue Aug 23, 2016 · 3 comments
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue.

Comments

@TheBentoBox
Copy link
Member

The spawn a villager effect will regularly give internal errors. This appears to be due to Skript trying to assign a random profession to villagers upon spawn; Zombies now also use that same profession enum in Spigot due to 1.9 zombie villagers having varying professions like non-zombie villagers. Because of this, there are two "villager professions" that are actually zombie types. Weird, I know, but that's how Spigot's done it. If it attempts to randomly assign one of the two zombie types as the villager's profession, it throws the error and stops execution. This will even occur with just the single simple inline effect command of spawn a villager.

I believe the issue is occurring in the VillagerData.java file, in the spawn function, here:

@Override
@Nullable
public Villager spawn(final Location loc) {
    final Villager v = super.spawn(loc);
    if (v == null)
        return null;
    if (profession == null)
        v.setProfession(CollectionUtils.getRandom(Profession.values()));
    return v;
}

Suggested fix is to generate a randomized profession, and continue re-randomizing while the randomly generated profession is one meant to be assigned to zombies only, which is available via the profession.isZombie() function.

@Override
@Nullable
public Villager spawn(final Location loc) {
    final Villager v = super.spawn(loc);
    if (v == null)
        return null;
    if (profession == null)
    {
        Profession newProf;
        do {
            newProf = CollectionUtils.getRandom(Profession.values());
        } while (newProf.isZombie());
        v.setProfession(newProf);
    }
    return v;
}
@bensku
Copy link
Member

bensku commented Aug 23, 2016

... and it seems that Spigot API is not as stable as you would think.

Need to fix this ASAP.

@bensku
Copy link
Member

bensku commented Aug 26, 2016

And I guess ASAP is not that soon. Next release fix this, but that doesn't come very soon - unless I get pull requests (for issues there are).

@bensku bensku added the bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. label Aug 26, 2016
@TheBentoBox
Copy link
Member Author

I've done a workaround in my own code for now using /summon; hopefully you're able to resolve the issues you're having!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue.
Projects
None yet
Development

No branches or pull requests

2 participants