DenizenScript / Denizen

NPC and general Spigot scripting, using the Denizen Scripting Language!
https://denizenscript.com/
MIT License
207 stars 104 forks source link

Interfaceification fixes #2635

Closed tal5 closed 2 months ago

tal5 commented 2 months ago

Changes

Additions

[!NOTE] Used an Optional for LegacyNamingHelper#requireType, since it just seemed like a good place to use it and have slightly cleaner & maybe faster code using it, with the alternatives being

if (mechanism.matches("profession") && LegacyNamingHelper.matches(Villager.Profession.class, mechanism.getValue().asString())) {
    setProfession(LegacyNamingHelper.convet(Villager.Profession.class, mechanism.getValue().asString()));
}

or

if (mechanism.matches("profession")) {
    Villager.Profession profession = LegacyNamingHelper.requireType(mechanism, Villager.Profession.class);
    if (profession != null) {
        setProfession(profession);
    }
}

Which are messier, especially when there's a bunch, I.e. in EntityColor (and since this is a temporary thing till 1.21 is the min version anyway) - let me know if you'd still prefer one of the other approaches though.

[!NOTE] Some of these technically have registries on all supported versions, but can't really cleanly make them use these as it'd still involve method calls on interfaces that are enums in older versions - can have a separate set of utils for handling registry stuff in mechs/tags which'll probably be needed anyway as more stuff move to registries, but that's for a different PR.