From 3afe77bf34eb7045359bd82665dda95e65536c9f Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 9 Jun 2024 16:21:25 +0700 Subject: [PATCH] [FEATURE][EXPERIMENTAL] New API: TextureUploadExtension --- .../launcher/base/profiles/ClientProfile.java | 16 +++++++++++++++ .../base/profiles/optional/OptionalFile.java | 13 +++++++++++- .../core/api/features/ProfileFeatureAPI.java | 5 +++++ .../api/features/TextureUploadFeatureAPI.java | 20 +++++++++++++++++++ .../{ => backend}/LauncherBackendAPI.java | 10 +++++++++- .../core/backend/extensions/Extension.java | 4 ++++ .../extensions/TextureUploadExtension.java | 11 ++++++++++ 7 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/TextureUploadFeatureAPI.java rename LauncherCore/src/main/java/pro/gravit/launcher/core/{ => backend}/LauncherBackendAPI.java (89%) create mode 100644 LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/Extension.java create mode 100644 LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/TextureUploadExtension.java diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java index 04dcc2f7..137cd961 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java @@ -15,6 +15,7 @@ import java.net.InetSocketAddress; import java.nio.file.Path; import java.util.*; +import java.util.stream.Collectors; public final class ClientProfile implements Comparable, ProfileFeatureAPI.ClientProfile { private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( @@ -287,10 +288,25 @@ public String toString() { return String.format("%s (%s)", title, uuid); } + @Override + public String getName() { + return title; + } + public UUID getUUID() { return uuid; } + @Override + public String getDescription() { + return info; + } + + @Override + public List getOptionalMods() { + return updateOptional.stream().collect(Collectors.toUnmodifiableList()); + } + public boolean hasFlag(CompatibilityFlags flag) { return flags.contains(flag); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalFile.java index 4d49cf23..bf8e261c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalFile.java @@ -2,11 +2,12 @@ import pro.gravit.launcher.core.LauncherNetworkAPI; import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.core.api.features.ProfileFeatureAPI; import java.util.List; import java.util.Objects; -public class OptionalFile { +public class OptionalFile implements ProfileFeatureAPI.OptionalMod { @LauncherNetworkAPI public List actions; @LauncherNetworkAPI @@ -57,6 +58,16 @@ public String getName() { return name; } + @Override + public String getDescription() { + return info; + } + + @Override + public String getCategory() { + return category; + } + public boolean isVisible() { return visible; } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/ProfileFeatureAPI.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/ProfileFeatureAPI.java index b751de40..a030d5da 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/ProfileFeatureAPI.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/ProfileFeatureAPI.java @@ -3,6 +3,7 @@ import pro.gravit.launcher.core.hasher.HashedDir; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -15,12 +16,16 @@ interface UpdateInfo {} interface ClientProfile { String getName(); UUID getUUID(); + String getDescription(); List getOptionalMods(); + String getProperty(String name); + Map getProperties(); } interface OptionalMod { String getName(); String getDescription(); String getCategory(); + boolean isVisible(); } } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/TextureUploadFeatureAPI.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/TextureUploadFeatureAPI.java new file mode 100644 index 00000000..cba41c1a --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/api/features/TextureUploadFeatureAPI.java @@ -0,0 +1,20 @@ +package pro.gravit.launcher.core.api.features; + +import pro.gravit.launcher.core.api.model.Texture; + +import java.util.Set; +import java.util.concurrent.CompletableFuture; + +public interface TextureUploadFeatureAPI { + CompletableFuture fetchInfo(); + CompletableFuture upload(String name, byte[] bytes, UploadSettings settings); + + interface TextureUploadInfo { + Set getAvailable(); + boolean isRequireManualSlimSkinSelect(); + } + + record UploadSettings(boolean slim) { + + } +} diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherBackendAPI.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/LauncherBackendAPI.java similarity index 89% rename from LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherBackendAPI.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/backend/LauncherBackendAPI.java index f41dbab0..ef0fd817 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherBackendAPI.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/LauncherBackendAPI.java @@ -1,10 +1,12 @@ -package pro.gravit.launcher.core; +package pro.gravit.launcher.core.backend; import pro.gravit.launcher.core.api.features.ProfileFeatureAPI; import pro.gravit.launcher.core.api.method.AuthMethod; import pro.gravit.launcher.core.api.method.AuthMethodPassword; import pro.gravit.launcher.core.api.model.SelfUser; import pro.gravit.launcher.core.api.model.Texture; +import pro.gravit.launcher.core.api.model.UserPermissions; +import pro.gravit.launcher.core.backend.extensions.Extension; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -20,6 +22,12 @@ public interface LauncherBackendAPI { CompletableFuture downloadProfile(ProfileFeatureAPI.ClientProfile profile, ClientProfileSettings settings, DownloadCallback callback); // Tools CompletableFuture fetchTexture(Texture texture); + // Status + UserPermissions getPermissions(); + boolean hasPermission(String permission); + String getUsername(); + // Extensions + T getExtension(Class clazz); record LauncherInitData(List methods) {} diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/Extension.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/Extension.java new file mode 100644 index 00000000..7597c51a --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/Extension.java @@ -0,0 +1,4 @@ +package pro.gravit.launcher.core.backend.extensions; + +public interface Extension { +} diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/TextureUploadExtension.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/TextureUploadExtension.java new file mode 100644 index 00000000..bab90ae7 --- /dev/null +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/backend/extensions/TextureUploadExtension.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.core.backend.extensions; + +import pro.gravit.launcher.core.api.features.TextureUploadFeatureAPI; +import pro.gravit.launcher.core.api.model.Texture; + +import java.util.concurrent.CompletableFuture; + +public interface TextureUploadExtension extends Extension { + CompletableFuture fetchTextureUploadInfo(); + CompletableFuture uploadTexture(String name, byte[] bytes, TextureUploadFeatureAPI.UploadSettings settings); +}