Carpet

Carpet

2M Downloads

quasiConnectivity cannot accept any value above 1 when reloading from carpet.conf

axialeaa opened this issue ยท 2 comments

commented

Observed Behaviour

Using /carpet setDefault to change the quasiConnectivity rule to something above 1 throws an InvalidRuleValueException upon server restart, despite the validator theoretically accepting any number from 0 to the world height. The value will then set itself back to 1, the default.

Hypothesis

This is most likely to do with maxRange not reassigning properly inside the validator. Perhaps while the server command source is not null, the world cannot be found?

private static class QuasiConnectivityValidator extends Validator<Integer> {

    @Override
    public Integer validate(ServerCommandSource source, CarpetRule<Integer> changingRule, Integer newValue, String userInput) {
        int minRange = 0;
        int maxRange = 1;

        if (source == null) {
            maxRange = Integer.MAX_VALUE;
        } else {
            for (World level : source.getServer().getWorlds()) {
                maxRange = Math.max(maxRange, level.getHeight() - 1);
            }
        }

        return (newValue >= minRange && newValue <= maxRange) ? newValue : null;
    }
}

To Reproduce:

  1. Enter a singleplayer world and run /carpet setDefault quasiConnectivity 10
  2. Exit the world
  3. Rejoin the world, monitoring the game log as it loads, observing the InvalidRuleValueException being thrown for "10"
  4. Run /carpet quasiConnectivity, and observe the rule having been set to 1 instead of 10
commented

Yes, looks like when we load the rules the list of worlds isn't ready yet so it was staying at one.

commented

Interesting. Thanks for the fast response!