Working peer player
This commit is contained in:
@@ -58,7 +58,7 @@ public class ServiceClient {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceMethods.Types.AuthResponse response = session.request(ServiceMethods.Authenticate, accessToken)
|
ServiceMethods.Types.Player response = session.request(ServiceMethods.Authenticate, accessToken)
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
for (String availableCloak : response.cloaks()) {
|
for (String availableCloak : response.cloaks()) {
|
||||||
@@ -71,7 +71,7 @@ public class ServiceClient {
|
|||||||
|
|
||||||
eventHandlers();
|
eventHandlers();
|
||||||
|
|
||||||
SaturnPlayer.set(uuid, username, new SaturnPlayer(uuid, username, response.cloak(), response.hat()));
|
player(uuid, username);
|
||||||
|
|
||||||
Cloaks.loadCloak(uuid);
|
Cloaks.loadCloak(uuid);
|
||||||
|
|
||||||
@@ -168,4 +168,19 @@ public class ServiceClient {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void player(UUID uuid, String name) {
|
||||||
|
try {
|
||||||
|
session.request(ServiceMethods.Player, uuid.toString().replaceAll("-", ""))
|
||||||
|
.whenComplete((user, throwable) -> {
|
||||||
|
if (throwable != null) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
} else {
|
||||||
|
SaturnPlayer.set(user.toSaturnPlayer(uuid, name));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
SaturnClient.LOGGER.error("Failed to get player", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
package org.saturnclient.saturnclient.client;
|
package org.saturnclient.saturnclient.client;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
||||||
|
|
||||||
import dev.selimaj.session.types.Method;
|
import dev.selimaj.session.types.Method;
|
||||||
|
|
||||||
public class ServiceMethods {
|
public class ServiceMethods {
|
||||||
public class Types {
|
public class Types {
|
||||||
public record AuthResponse(String cloak, String hat, String[] cloaks, String[] hats) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public record EmoteRequest(String emote, String[] targets) {
|
public record EmoteRequest(String emote, String[] targets) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public record EmoteEvent(String emote, String from) {
|
public record EmoteEvent(String emote, String from) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public record Player(String cloak, String hat, String[] cloaks, String[] hats) {
|
||||||
|
public SaturnPlayer toSaturnPlayer(UUID uuid, String name) {
|
||||||
|
return new SaturnPlayer(uuid, name, cloak, hat);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Method<String, Types.AuthResponse, String> Authenticate = new Method<>("auth",
|
public static final Method<String, Types.Player, String> Authenticate = new Method<>("auth",
|
||||||
String.class, Types.AuthResponse.class, String.class);
|
String.class, Types.Player.class, String.class);
|
||||||
|
|
||||||
// Equip
|
// Equip
|
||||||
public static final Method<String, String, String> SetCloak = new Method<>("set_cloak",
|
public static final Method<String, String, String> SetCloak = new Method<>("set_cloak",
|
||||||
@@ -35,4 +42,7 @@ public class ServiceMethods {
|
|||||||
|
|
||||||
public static final Method<Types.EmoteEvent, String, String> EmoteEvent = new Method<>("emote_event",
|
public static final Method<Types.EmoteEvent, String, String> EmoteEvent = new Method<>("emote_event",
|
||||||
Types.EmoteEvent.class, String.class, String.class);
|
Types.EmoteEvent.class, String.class, String.class);
|
||||||
|
|
||||||
|
public static final Method<String, Types.Player, String> Player = new Method<>("player",
|
||||||
|
String.class, Types.Player.class, String.class);
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ package org.saturnclient.saturnclient.client.player;
|
|||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.client.ServiceClient;
|
||||||
|
|
||||||
import net.minecraft.client.network.PlayerListEntry;
|
import net.minecraft.client.network.PlayerListEntry;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
@@ -46,7 +47,6 @@ public class PlayerTracker {
|
|||||||
|
|
||||||
private static void onPlayerJoin(MinecraftClient client, PlayerListEntry player) {
|
private static void onPlayerJoin(MinecraftClient client, PlayerListEntry player) {
|
||||||
GameProfile profile = player.getProfile();
|
GameProfile profile = player.getProfile();
|
||||||
UUID uuid = profile.getId();
|
ServiceClient.player(profile.getId(), profile.getName());
|
||||||
SaturnPlayer.player(uuid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,19 +41,9 @@ public class SaturnPlayer {
|
|||||||
return PLAYERS.get(uuid);
|
return PLAYERS.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void set(UUID uuid, String name, SaturnPlayer player) {
|
public static void set(SaturnPlayer player) {
|
||||||
PLAYER_NAMES.put(name, uuid);
|
PLAYER_NAMES.put(player.name, player.uuid);
|
||||||
PLAYERS.put(uuid, player);
|
PLAYERS.put(player.uuid, player);
|
||||||
}
|
|
||||||
|
|
||||||
public static void player(UUID uuid) {
|
|
||||||
if (PLAYERS.containsKey(uuid)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If offline then leave
|
|
||||||
|
|
||||||
PLAYERS.put(uuid, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getExternalUUIDAsString() {
|
public static String[] getExternalUUIDAsString() {
|
||||||
|
|||||||
Reference in New Issue
Block a user