Add environment variable to override cloud_allowunverified_expansions

This adds the environment variable PAPI_ALLOW_UNVERIFIED_EXPANSIONS.
It allows overriding the option set in the config.yml.
This commit is contained in:
Julian 2023-06-23 14:00:24 +02:00
parent f91b4e3752
commit 92a7d54664
No known key found for this signature in database
GPG Key ID: A0CA42F79DA926B1
1 changed files with 19 additions and 1 deletions

View File

@ -48,6 +48,24 @@ public final class CommandECloudDownload extends PlaceholderCommand {
.anyMatch(s -> s.equalsIgnoreCase(name));
}
private boolean areUnverifiedExpansionsAllowed(@NotNull final PlaceholderAPIPlugin plugin) {
String env = System.getenv("PAPI_ALLOW_UNVERIFIED_EXPANSIONS");
if (env != null) {
switch (env.toLowerCase()) {
case "true":
case "yes":
case "1":
return true;
case "false":
case "no":
case "0":
return false;
}
}
return plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions();
}
@Override
public void evaluate(@NotNull final PlaceholderAPIPlugin plugin,
@NotNull final CommandSender sender, @NotNull final String alias,
@ -72,7 +90,7 @@ public final class CommandECloudDownload extends PlaceholderCommand {
return;
}
if (!expansion.isVerified() && !plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()) {
if (!expansion.isVerified() && !this.areUnverifiedExpansionsAllowed(plugin)) {
Msg.msg(sender, "&cThe expansion '&f" + params.get(0) + "&c' is not verified and can only be downloaded manually from &fhttps://placeholderapi.com/ecloud");
return;
}