Move app store validator to CarpetSettings

This commit is contained in:
altrisi committed 2023-06-26 18:44:15 +02:00
1 parent 177179b70a
commit db2023f5b9
3 files changed
+33 -36

No files matched your search

-33
View File
@@ -5,7 +5,6 @@ import carpet.CarpetSettings;
import carpet.api.settings.CarpetRule;
import carpet.api.settings.RuleHelper;
import carpet.api.settings.SettingsManager;
import carpet.api.settings.Validator;
import carpet.fakes.MinecraftServerInterface;
import carpet.logging.HUDController;
import carpet.network.ServerNetworkHandler;
@@ -17,7 +16,6 @@ import carpet.script.CarpetScriptServer;
import carpet.script.Module;
import carpet.script.exception.InternalExpressionException;
import carpet.script.exception.LoadException;
import carpet.script.utils.AppStoreManager;
import carpet.script.value.MapValue;
import carpet.script.value.StringValue;
import carpet.utils.CarpetProfiler;
@@ -241,35 +239,4 @@ public class Carpet
};
SettingsManager.registerGlobalRuleObserver((source, changedRule, userInput) -> carpetRuleChanges.handleAny(changedRule, source));
}
public static class ScarpetAppStoreValidator extends Validator<String>
{
@Override
public String validate(@Nullable CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String stringInput)
{
if (newValue.equals(currentRule.value()))
{
// Don't refresh the local repo if it's the same (world change), helps preventing hitting rate limits from github when
// getting suggestions. Pending is a way to invalidate the cache when it gets old, and investigating api usage further
return newValue;
}
if (newValue.equalsIgnoreCase("none"))
{
AppStoreManager.setScarpetRepoLink(null);
return newValue;
}
if (newValue.endsWith("/"))
{
newValue = newValue.substring(0, newValue.length() - 1);
}
AppStoreManager.setScarpetRepoLink("https://api.github.com/repos/" + newValue + "/");
return newValue;
}
@Override
public String description()
{
return "Appstore link should point to a valid github repository";
}
}
}
@@ -58,6 +58,10 @@ public class AppStoreManager
scarpetRepoLink = link;
}
public static boolean enabled()
{
return scarpetRepoLink != null;
}
private record AppInfo(String name, String url, StoreNode source)
{
@@ -123,7 +127,7 @@ public class AppStoreManager
{
return;
}
if (scarpetRepoLink == null)
if (!enabled())
{
throw new IOException("Accessing scarpet app repo is disabled");
}