Settings rework and encapsulation (#1330)

* Settings rework and encapsulation

* Settings overhaul 3

Move everything in the new system to a new API package

Require rules using the new system to specify descriptions in their translation files

Implement temporary system on top of current translations to allow that to work properly

* Fix getRules fallback

* Final touches to settings refactor

* Mention that set shouldn't throw and remove comment

* Change translation keys to unify with translation PR

* Deprecate printAllRulesToLog to allow using any PrintStream

* Remove restriction of CarpetRules being Comparable

And fix overreaction in a deprecation message

* Bring back user input to rule observers

* Make Validator deprecation warning not spam on use

* Remove unneeded abstract methods in CarpetRule already inherited from CarpetRule

They literally do nothing, don't even force them to be implemented, and may be confusing as to why they're there or as if they are needed to be implemented

* Fix legacy SettingsManager field not being assigned correctly

* Finish fixing conflicts from future merge

* Actually fix remaining conflicts from future merge (missing imports)

* Import the newer rule in SettingsManager

* Refactor Validators

* Don't spam deprecation warnings on custom managers

* Get out the var

* Fix missing warning in old rule observers

* Update src/main/java/carpet/api/settings/Rule.java

* Remove `@ApiStatus.Experimental` annotations

* Fix incorrect `@deprecated` javadoc tags

By removing them given the class is deprecated anyway and else there's too much noise

* Add missing static import

* Remove TypedField and use a regular field

I liked that class tbh, but it's true that it wasn't really needed

* Move `field` assignment out of for removal

* Fix not following contract of `type()` returning boxed value

Previously handled by TypedField

* Fix few incorrect translation keys

* Remove resaving of comments when saving config files

Comments ignoring is still a thing when reading, so `locked` configs for example will keep comments

* Condense rule load messages in one

* Only print loaded settings message when at least one setting was changed

* Fix legacy validator detector

* Tweak and add more context to response to invalid values

* Fix strict validator not actually erroring on invalid input
This commit is contained in:
altrisi authored and GitHub committed 2022-06-27 13:12:15 +02:00
1 parent f5a92ebb8e
commit 0a972d6c56
44 files changed
+2687 -1616

No files matched your search

+19 -6
View File
@@ -1,13 +1,14 @@
package carpet;
import carpet.script.CarpetExpression;
import carpet.settings.SettingsManager;
import carpet.api.settings.SettingsManager;
import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import java.util.Collections;
import java.util.Map;
public interface CarpetExtension
@@ -69,7 +70,11 @@ public interface CarpetExtension
registerCommands(dispatcher);
}
/**
* @deprecated Implement {@link #extensionSettingsManager()} instead
*/
@Deprecated(forRemoval = true)
default carpet.settings.SettingsManager customSettingsManager() {return null;}
/**
* Provide your own custom settings manager managed in the same way as base /carpet
@@ -78,7 +83,15 @@ public interface CarpetExtension
* @return Your custom {@link SettingsManager} instance to be managed by Carpet
*
*/
default SettingsManager customSettingsManager() {return null;}
default SettingsManager extensionSettingsManager() {
// Warn extensions overriding the other (deprecated) method, go ahead and override this if you want to provide a custom SettingsManager
SettingsManager deprecatedManager = customSettingsManager();
if (deprecatedManager != null) {
// Extension is providing a manager via the old method (and also hasn't overriden this)
CarpetServer.warnOutdatedManager(this);
}
return customSettingsManager();
}
/**
* Event that gets called when a player logs in
@@ -134,10 +147,10 @@ public interface CarpetExtension
*
* @param lang A {@link String} being the language id selected by the user
* @return A {@link Map<String, String>} containing the string key with it's
* respective translation {@link String} or {@link null} if not available
* respective translation {@link String} or an empty map if not available
*
*/
default Map<String, String> canHasTranslations(String lang) { return null;}
default Map<String, String> canHasTranslations(String lang) { return Collections.emptyMap();}
/**
* Handles each call that creates / parses the scarpet expression.