UI service auth refactored
This commit is contained in:
@@ -4,6 +4,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.saturnclient.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<>();
|
||||||
private static Map<String, UUID> PLAYER_NAMES = new HashMap<>();
|
private static Map<String, UUID> PLAYER_NAMES = new HashMap<>();
|
||||||
@@ -20,6 +22,10 @@ public class SaturnPlayer {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SaturnPlayer get() {
|
||||||
|
return PLAYERS.get(ServiceClient.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
public static SaturnPlayer get(UUID uuid) {
|
public static SaturnPlayer get(UUID uuid) {
|
||||||
return PLAYERS.get(uuid);
|
return PLAYERS.get(uuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ public class Hats {
|
|||||||
availableHats.add(0, "");
|
availableHats.add(0, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHat(UUID uuid, String hatName) {
|
public static void setHat(String hatName) {
|
||||||
setHatSilent(uuid, hatName);
|
if (availableHats.contains(hatName)) {
|
||||||
ServiceClient.setHat(hatName);
|
setHat(ServiceClient.uuid, hatName);
|
||||||
|
ServiceClient.setHat(hatName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHatSilent(UUID uuid, String hatName) {
|
public static void setHat(UUID uuid, String hatName) {
|
||||||
SaturnPlayer player = SaturnPlayer.get(uuid);
|
SaturnPlayer player = SaturnPlayer.get(uuid);
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
// Auth.players.put(uuid, new SaturnPlayer("", hatName));
|
// Auth.players.put(uuid, new SaturnPlayer("", hatName));
|
||||||
|
|||||||
@@ -55,25 +55,15 @@ public class Cloaks {
|
|||||||
availableCloaks.add(0, "");
|
availableCloaks.add(0, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles loading and caching of a new cloak texture.
|
|
||||||
*
|
|
||||||
* @param cloakName Name of the cloak file to load
|
|
||||||
*/
|
|
||||||
public static void setCloak(UUID uuid, String cloakName) {
|
|
||||||
setCloakSilent(uuid, cloakName);
|
|
||||||
SaturnClient.LOGGER.info("Cloak set to " + cloakName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets cloak of the current player
|
* Sets cloak of the current player
|
||||||
*
|
*
|
||||||
* @param cloakName Name of the cloak file to load
|
* @param cloakName Name of the cloak file to load
|
||||||
*/
|
*/
|
||||||
public static void setCloak(String cloakName) {
|
public static void setCloak(String cloakName) {
|
||||||
ServiceClient.setCloak(cloakName);
|
|
||||||
if (availableCloaks.contains(cloakName)) {
|
if (availableCloaks.contains(cloakName)) {
|
||||||
setCloak(ServiceClient.uuid, cloakName);
|
setCloak(ServiceClient.uuid, cloakName);
|
||||||
|
ServiceClient.setCloak(cloakName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +73,7 @@ public class Cloaks {
|
|||||||
*
|
*
|
||||||
* @param cloakName Name of the cloak file to load
|
* @param cloakName Name of the cloak file to load
|
||||||
*/
|
*/
|
||||||
public static void setCloakSilent(UUID uuid, String cloakName) {
|
public static void setCloak(UUID uuid, String cloakName) {
|
||||||
SaturnPlayer player = SaturnPlayer.get(uuid);
|
SaturnPlayer player = SaturnPlayer.get(uuid);
|
||||||
|
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import net.minecraft.client.util.InputUtil;
|
|||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||||
import org.saturnclient.saturnclient.auth.Auth;
|
|
||||||
import org.saturnclient.ui2.screens.EmoteWheel;
|
import org.saturnclient.ui2.screens.EmoteWheel;
|
||||||
import org.saturnclient.ui2.screens.ShiftMenu;
|
import org.saturnclient.ui2.screens.ShiftMenu;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.saturnclient.ui2.screens.cosmetics;
|
package org.saturnclient.ui2.screens.cosmetics;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.saturnclient.auth.Auth;
|
|
||||||
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
import org.saturnclient.ui2.resources.Textures;
|
import org.saturnclient.ui2.resources.Textures;
|
||||||
@@ -27,15 +26,15 @@ public class CloakMenu extends SaturnScreen {
|
|||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
SaturnPlayer player = Auth.players.get(Auth.uuid);
|
SaturnPlayer player = SaturnPlayer.get();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
for (String cloak : Cloaks.availableCloaks) {
|
for (String cloak : Cloaks.availableCloaks) {
|
||||||
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
|
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
|
||||||
Cloaks.setCloak(cloak);
|
Cloaks.setCloak(cloak);
|
||||||
}).position((50 + g) * col, (111 + g) * row));
|
}).position((50 + g) * col, (111 + g) * row));
|
||||||
|
|
||||||
if (col == 5) {
|
if (col == 5) {
|
||||||
col = 0;
|
col = 0;
|
||||||
row++;
|
row++;
|
||||||
@@ -46,18 +45,18 @@ public class CloakMenu extends SaturnScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int scrollWidth = 480 + 10 + (g * 2) + (p * 2);
|
int scrollWidth = 480 + 10 + (g * 2) + (p * 2);
|
||||||
|
|
||||||
draw(scroll.dimensions(scrollWidth, 350).center(width, height));
|
draw(scroll.dimensions(scrollWidth, 350).center(width, height));
|
||||||
|
|
||||||
draw(new SkinPreview(-30.0f, false).scale(3.5f).position(scroll.x + (scrollWidth - 220), scroll.y+40));
|
draw(new SkinPreview(-30.0f, false).scale(3.5f).position(scroll.x + (scrollWidth - 220), scroll.y + 40));
|
||||||
|
|
||||||
draw(new Sidebar(2, this::close).centerOffset(width, height, -(scrollWidth / 2 + 20), 0));
|
draw(new Sidebar(2, this::close).centerOffset(width, height, -(scrollWidth / 2 + 20), 0));
|
||||||
|
|
||||||
draw(new TabMenu(0,
|
draw(new TabMenu(0,
|
||||||
new TabMenuComponent(Textures.CLOAK, () -> {}),
|
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||||
new TabMenuComponent(Textures.HAT, () -> {
|
}),
|
||||||
SaturnClient.client.setScreen(new HatMenu());
|
new TabMenuComponent(Textures.HAT, () -> {
|
||||||
})
|
SaturnClient.client.setScreen(new HatMenu());
|
||||||
).centerOffset(width, height, 0, -195));
|
})).centerOffset(width, height, 0, -195));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.saturnclient.ui2.screens.cosmetics;
|
package org.saturnclient.ui2.screens.cosmetics;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.saturnclient.auth.Auth;
|
|
||||||
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
||||||
import org.saturnclient.saturnclient.cosmetics.Hats;
|
import org.saturnclient.saturnclient.cosmetics.Hats;
|
||||||
import org.saturnclient.ui2.resources.Textures;
|
import org.saturnclient.ui2.resources.Textures;
|
||||||
@@ -27,15 +26,15 @@ public class HatMenu extends SaturnScreen {
|
|||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
SaturnPlayer player = Auth.players.get(Auth.uuid);
|
SaturnPlayer player = SaturnPlayer.get();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
for (String hat : Hats.availableHats) {
|
for (String hat : Hats.availableHats) {
|
||||||
scroll.draw(new CosmeticPreview(hat == player.hat, Textures.getHatPreview(hat), () -> {
|
scroll.draw(new CosmeticPreview(hat == player.hat, Textures.getHatPreview(hat), () -> {
|
||||||
Hats.setHat(Auth.uuid, hat);
|
Hats.setHat(hat);
|
||||||
}).dimensions(50, 50).position((50 + g) * col, (50 + g) * row));
|
}).dimensions(50, 50).position((50 + g) * col, (50 + g) * row));
|
||||||
|
|
||||||
if (col == 5) {
|
if (col == 5) {
|
||||||
col = 0;
|
col = 0;
|
||||||
row++;
|
row++;
|
||||||
@@ -46,18 +45,18 @@ public class HatMenu extends SaturnScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int scrollWidth = 480 + 10 + (g * 2) + (p * 2);
|
int scrollWidth = 480 + 10 + (g * 2) + (p * 2);
|
||||||
|
|
||||||
draw(scroll.dimensions(scrollWidth, 350).center(width, height));
|
draw(scroll.dimensions(scrollWidth, 350).center(width, height));
|
||||||
|
|
||||||
draw(new SkinPreview(170f, true).scale(3.5f).position(scroll.x + (scrollWidth - 220), scroll.y+40));
|
draw(new SkinPreview(170f, true).scale(3.5f).position(scroll.x + (scrollWidth - 220), scroll.y + 40));
|
||||||
|
|
||||||
draw(new Sidebar(2, this::close).centerOffset(width, height, -(scrollWidth / 2 + 20), 0));
|
draw(new Sidebar(2, this::close).centerOffset(width, height, -(scrollWidth / 2 + 20), 0));
|
||||||
|
|
||||||
draw(new TabMenu(1,
|
draw(new TabMenu(1,
|
||||||
new TabMenuComponent(Textures.CLOAK, () -> {
|
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||||
SaturnClient.client.setScreen(new CloakMenu());
|
SaturnClient.client.setScreen(new CloakMenu());
|
||||||
}),
|
}),
|
||||||
new TabMenuComponent(Textures.HAT, () -> {})
|
new TabMenuComponent(Textures.HAT, () -> {
|
||||||
).centerOffset(width, height, 0, -195));
|
})).centerOffset(width, height, 0, -195));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.saturnclient.ui2.screens.store;
|
package org.saturnclient.ui2.screens.store;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.client.ServiceClient;
|
||||||
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.SaturnScreen;
|
||||||
@@ -41,7 +42,7 @@ public class CloakStore extends SaturnScreen {
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
SaturnPlayer player = Auth.players.get(Auth.uuid);
|
SaturnPlayer player = SaturnPlayer.get();
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
for (String cloak : Cloaks.ALL_CLOAKS) {
|
for (String cloak : Cloaks.ALL_CLOAKS) {
|
||||||
@@ -53,7 +54,7 @@ public class CloakStore extends SaturnScreen {
|
|||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (now - lastPurchaseTime >= 3000) {
|
if (now - lastPurchaseTime >= 3000) {
|
||||||
Utils.notify(NotificationKind.Info, "Purchase processing", "Please wait");
|
Utils.notify(NotificationKind.Info, "Purchase processing", "Please wait");
|
||||||
Auth.buyCloak(cloak);
|
ServiceClient.buyCloak(cloak);
|
||||||
lastPurchaseTime = now;
|
lastPurchaseTime = now;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user