Change class level cap midgame?

Let's say I want to have a class that is capped at Lv. X until a specific plot point, at which case its cap becomes Lv. 99 like all other classes. Is there a way to change Class X's cap without having to change the unit to Class Y?
Paste the below into a text editor, save as a *.js file, include as a plugin:
Code:
Game_Actor.prototype.maxLevel = function() {
    if (this.actor().currentClass().id == X && !$gameSwitches.value(Y))
        return Z;
    return this.actor().maxLevel;
};

Where X is the ID of the class you're limiting, Y is the ID of a game switch that indicates your plot point, and Z is the level to limit it to. No leading zeros on the IDs.

The class will be limited until you turn switch Y ON.

Original thread: https://forums.rpgmakerweb.com/threads/change-class-level-cap-midgame.162906/