Provider
This commit is contained in:
@@ -6,7 +6,7 @@ import java.util.List;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.saturnclient.client.player.SaturnPlayer;
|
import org.saturnclient.client.player.SaturnPlayer;
|
||||||
import org.saturnclient.common.bindings.SaturnClientBindings;
|
import org.saturnclient.common.provider.Providers;
|
||||||
|
|
||||||
import dev.selimaj.session.Session;
|
import dev.selimaj.session.Session;
|
||||||
|
|
||||||
@@ -27,30 +27,30 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean authenticate() {
|
public static boolean authenticate() {
|
||||||
SaturnClientBindings.platform().onClientStopping(() -> {
|
Providers.saturn.onClientStopping(() -> {
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
try {
|
try {
|
||||||
session.close();
|
session.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Unable to close Saturn session", e);
|
Providers.saturn.logError("Unable to close Saturn session", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String accessToken = SaturnClientBindings.platform().getAccessToken();
|
String accessToken = Providers.saturn.getAccessToken();
|
||||||
uuid = SaturnClientBindings.platform().getUuid();
|
uuid = Providers.saturn.getUuid();
|
||||||
String username = SaturnClientBindings.platform().getUsername();
|
String username = Providers.saturn.getUsername();
|
||||||
|
|
||||||
if (accessToken == null || uuid == null || username == null) {
|
if (accessToken == null || uuid == null || username == null) {
|
||||||
SaturnClientBindings.platform().logError("No active Minecraft session found");
|
Providers.saturn.logError("No active Minecraft session found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaturnClientBindings.platform().logInfo("Authenticating with UUID: " + uuid);
|
Providers.saturn.logInfo("Authenticating with UUID: " + uuid);
|
||||||
|
|
||||||
if (!connectTimeout()) {
|
if (!connectTimeout()) {
|
||||||
SaturnClientBindings.platform().logError("Unable to authenticate: Session Server Timeout");
|
Providers.saturn.logError("Unable to authenticate: Session Server Timeout");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class ServiceClient {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Authentication failed", e);
|
Providers.saturn.logError("Authentication failed", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Failed to set cloak (service): ", e);
|
Providers.saturn.logError("Failed to set cloak (service): ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Failed to set hat (service): ", e);
|
Providers.saturn.logError("Failed to set hat (service): ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Failed to buy cloak (service): ", e);
|
Providers.saturn.logError("Failed to buy cloak (service): ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Failed to buy hat (service): ", e);
|
Providers.saturn.logError("Failed to buy hat (service): ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Failed to emote (service): ", e);
|
Providers.saturn.logError("Failed to emote (service): ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,9 +169,9 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.emote() != null && !data.emote().isEmpty()) {
|
if (data.emote() != null && !data.emote().isEmpty()) {
|
||||||
SaturnClientBindings.emotes().setEmote(from, data.emote());
|
Providers.saturn.playEmote(from, data.emote());
|
||||||
} else {
|
} else {
|
||||||
SaturnClientBindings.emotes().setEmote(from, null);
|
Providers.saturn.playEmote(from, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClientBindings.platform().logError("Failed to get player", e);
|
Providers.saturn.logError("Failed to get player", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.saturnclient.common.bindings.SaturnClientBindings;
|
import org.saturnclient.client.ServiceClient;
|
||||||
|
|
||||||
public class SaturnPlayer {
|
public class SaturnPlayer {
|
||||||
private static Map<UUID, SaturnPlayer> PLAYERS = new HashMap<>();
|
private static Map<UUID, SaturnPlayer> PLAYERS = new HashMap<>();
|
||||||
@@ -23,11 +23,10 @@ public class SaturnPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static SaturnPlayer get() {
|
public static SaturnPlayer get() {
|
||||||
UUID self = SaturnClientBindings.platform().getUuid();
|
if (ServiceClient.uuid == null) {
|
||||||
if (self == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return PLAYERS.get(self);
|
return PLAYERS.get(ServiceClient.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SaturnPlayer get(UUID uuid) {
|
public static SaturnPlayer get(UUID uuid) {
|
||||||
@@ -47,8 +46,8 @@ public class SaturnPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getExternalUUIDAsString() {
|
public static String[] getExternalUUIDAsString() {
|
||||||
UUID self = SaturnClientBindings.platform().getUuid();
|
return PLAYERS.keySet().stream().filter(id -> ServiceClient.uuid == null || !id.equals(ServiceClient.uuid))
|
||||||
return PLAYERS.keySet().stream().filter(id -> self == null || !id.equals(self)).map(UUID::toString)
|
.map(UUID::toString)
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
package org.saturnclient.common.bindings;
|
|
||||||
|
|
||||||
public final class SaturnClientBindings {
|
|
||||||
private static SaturnPlatformBindings platform;
|
|
||||||
private static SaturnEmoteBindings emotes;
|
|
||||||
|
|
||||||
private SaturnClientBindings() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setPlatform(SaturnPlatformBindings bindings) {
|
|
||||||
platform = bindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SaturnPlatformBindings platform() {
|
|
||||||
if (platform == null) {
|
|
||||||
throw new IllegalStateException("SaturnPlatformBindings not initialized");
|
|
||||||
}
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setEmotes(SaturnEmoteBindings bindings) {
|
|
||||||
emotes = bindings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SaturnEmoteBindings emotes() {
|
|
||||||
if (emotes == null) {
|
|
||||||
throw new IllegalStateException("SaturnEmoteBindings not initialized");
|
|
||||||
}
|
|
||||||
return emotes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package org.saturnclient.common.bindings;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface SaturnEmoteBindings {
|
|
||||||
void setEmote(UUID fromPlayerUuid, String emoteIdOrNull);
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package org.saturnclient.common.bindings;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface SaturnPlatformBindings {
|
|
||||||
String getAccessToken();
|
|
||||||
|
|
||||||
UUID getUuid();
|
|
||||||
|
|
||||||
String getUsername();
|
|
||||||
|
|
||||||
void onClientStopping(Runnable handler);
|
|
||||||
|
|
||||||
void logInfo(String message);
|
|
||||||
|
|
||||||
void logError(String message);
|
|
||||||
|
|
||||||
void logError(String message, Throwable throwable);
|
|
||||||
}
|
|
||||||
@@ -4,11 +4,28 @@ import org.saturnclient.common.ref.asset.IdentifierRef;
|
|||||||
import org.saturnclient.common.ref.game.MinecraftClientRef;
|
import org.saturnclient.common.ref.game.MinecraftClientRef;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface SaturnProvider {
|
public interface SaturnProvider {
|
||||||
public abstract MinecraftClientRef getClient();
|
public MinecraftClientRef getClient();
|
||||||
|
|
||||||
public abstract void registerBufferedImageTexture(IdentifierRef i, BufferedImage bi);
|
public void playEmote(UUID fromPlayerUuid, String emoteIdOrNull);
|
||||||
|
|
||||||
public abstract void stop();
|
public String getAccessToken();
|
||||||
|
|
||||||
|
public UUID getUuid();
|
||||||
|
|
||||||
|
public String getUsername();
|
||||||
|
|
||||||
|
public void onClientStopping(Runnable handler);
|
||||||
|
|
||||||
|
public void logInfo(String message);
|
||||||
|
|
||||||
|
public void logError(String message);
|
||||||
|
|
||||||
|
public void logError(String message, Throwable throwable);
|
||||||
|
|
||||||
|
public void stop();
|
||||||
|
|
||||||
|
public void registerBufferedImageTexture(IdentifierRef i, BufferedImage bi);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.saturnclient.ui.screens;
|
|||||||
|
|
||||||
import org.saturnclient.cosmetics.Emotes;
|
import org.saturnclient.cosmetics.Emotes;
|
||||||
import org.saturnclient.client.ServiceClient;
|
import org.saturnclient.client.ServiceClient;
|
||||||
import org.saturnclient.common.bindings.SaturnClientBindings;
|
import org.saturnclient.common.provider.Providers;
|
||||||
import org.saturnclient.config.AnimationConfig;
|
import org.saturnclient.config.AnimationConfig;
|
||||||
import org.saturnclient.config.Config;
|
import org.saturnclient.config.Config;
|
||||||
import org.saturnclient.ui.SaturnScreen;
|
import org.saturnclient.ui.SaturnScreen;
|
||||||
@@ -82,9 +82,7 @@ public class EmoteWheel extends SaturnScreen {
|
|||||||
|
|
||||||
emoteStagger.draw(
|
emoteStagger.draw(
|
||||||
new TextureButton(Textures.getEmotePreview(emote), () -> {
|
new TextureButton(Textures.getEmotePreview(emote), () -> {
|
||||||
if (emote != null)
|
Providers.saturn.playEmote(ServiceClient.uuid, emote);
|
||||||
SaturnClientBindings.emotes().setEmote(ServiceClient.uuid, emote);
|
|
||||||
|
|
||||||
provider.close();
|
provider.close();
|
||||||
})
|
})
|
||||||
.dimensions(70, 70)
|
.dimensions(70, 70)
|
||||||
|
|||||||
Reference in New Issue
Block a user