Merge pull request #18 from Silent-Client/TEST2

Update Cosmetics.java
This commit is contained in:
kirillsaint 2023-08-06 00:19:40 +06:00 committed by GitHub
commit f29247075e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,10 +12,12 @@ import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
import net.silentclient.client.mods.settings.CosmeticsMod; import net.silentclient.client.mods.settings.CosmeticsMod;
import net.silentclient.client.utils.Players; import net.silentclient.client.utils.Players;
import net.silentclient.client.utils.Requests; import net.silentclient.client.utils.Requests;
import net.silentclient.client.utils.types.CosmeticsResponse;
import net.silentclient.client.utils.types.PlayerResponse; import net.silentclient.client.utils.types.PlayerResponse;
import net.silentclient.client.utils.types.PlayerResponse.Account.Cosmetics.CosmeticItem; import net.silentclient.client.utils.types.PlayerResponse.Account.Cosmetics.CosmeticItem;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -58,13 +60,13 @@ public class Cosmetics {
Client.logger.info("STARTING > cosmeitcs > default_icon"); Client.logger.info("STARTING > cosmeitcs > default_icon");
defaultIcon = new StaticResourceLocation("silentclient/icons/player_icon.png"); defaultIcon = new StaticResourceLocation("silentclient/icons/player_icon.png");
if(!Client.getInstance().isDebug()) { if(!Client.getInstance().isDebug()) {
CosmeticsResponse allCosmetics = getAllCosmetics(); PlayerResponse.Account.Cosmetics allCosmetics = getAllCosmetics();
Client.logger.info("STARTING > cosmeitcs > capes"); Client.logger.info("STARTING > cosmeitcs > capes");
capes.clear(); capes.clear();
capesShoulders.clear(); capesShoulders.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getCapes() != null) { if(allCosmetics != null && allCosmetics.getCapes() != null) {
allCosmetics.getCosmetics().getCapes().forEach((cape) -> { allCosmetics.getCapes().forEach((cape) -> {
capes.put(cape.getId(), new AnimatedResourceLocation("silentclient/cosmetics/capes/"+cape.getId(), cape.getFrames(), cape.getFrameDelay(), false, cape.getId() == Client.getInstance().getAccount().getSelectedCape())); capes.put(cape.getId(), new AnimatedResourceLocation("silentclient/cosmetics/capes/"+cape.getId(), cape.getFrames(), cape.getFrameDelay(), false, cape.getId() == Client.getInstance().getAccount().getSelectedCape()));
capesShoulders.put(cape.getId(), new StaticResourceLocation("silentclient/cosmetics/capes/"+cape.getId()+"/shoulders.png")); capesShoulders.put(cape.getId(), new StaticResourceLocation("silentclient/cosmetics/capes/"+cape.getId()+"/shoulders.png"));
}); });
@ -72,24 +74,24 @@ public class Cosmetics {
Client.logger.info("STARTING > cosmeitcs > wings"); Client.logger.info("STARTING > cosmeitcs > wings");
wings.clear(); wings.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getWings() != null) { if(allCosmetics != null && allCosmetics.getWings() != null) {
allCosmetics.getCosmetics().getWings().forEach((wing) -> { allCosmetics.getWings().forEach((wing) -> {
wings.put(wing.getId(), new AnimatedResourceLocation("silentclient/cosmetics/wings/"+ wing.getId(), wing.getFrames(), wing.getFrameDelay(), false, wing.getId() == Client.getInstance().getAccount().getSelectedWings())); wings.put(wing.getId(), new AnimatedResourceLocation("silentclient/cosmetics/wings/"+ wing.getId(), wing.getFrames(), wing.getFrameDelay(), false, wing.getId() == Client.getInstance().getAccount().getSelectedWings()));
}); });
} }
Client.logger.info("STARTING > cosmeitcs > bandanas"); Client.logger.info("STARTING > cosmeitcs > bandanas");
bandanas.clear(); bandanas.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getBandanas() != null) { if(allCosmetics != null && allCosmetics.getBandanas() != null) {
allCosmetics.getCosmetics().getBandanas().forEach((bandana) -> { allCosmetics.getBandanas().forEach((bandana) -> {
bandanas.put(bandana.getId(), new AnimatedResourceLocation("silentclient/cosmetics/bandanas/"+bandana.getId(), bandana.getFrames(), bandana.getFrameDelay(), false, bandana.getId() == Client.getInstance().getAccount().getSelectedBandana())); bandanas.put(bandana.getId(), new AnimatedResourceLocation("silentclient/cosmetics/bandanas/"+bandana.getId(), bandana.getFrames(), bandana.getFrameDelay(), false, bandana.getId() == Client.getInstance().getAccount().getSelectedBandana()));
}); });
} }
Client.logger.info("STARTING > cosmeitcs > hats"); Client.logger.info("STARTING > cosmeitcs > hats");
hats.clear(); hats.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getHats() != null) { if(allCosmetics != null && allCosmetics.getHats() != null) {
allCosmetics.getCosmetics().getHats().forEach((hat) -> { allCosmetics.getHats().forEach((hat) -> {
hats.put(hat.getId(), new HatData(new AnimatedResourceLocation("silentclient/cosmetics/hats/"+hat.getId(), hat.getFrames(), hat.getFrameDelay(), false, hat.getId() == Client.getInstance().getAccount().getSelectedHat()), hat.getModel())); hats.put(hat.getId(), new HatData(new AnimatedResourceLocation("silentclient/cosmetics/hats/"+hat.getId(), hat.getFrames(), hat.getFrameDelay(), false, hat.getId() == Client.getInstance().getAccount().getSelectedHat()), hat.getModel()));
if(!hatModels.containsKey(hat.getModel())) { if(!hatModels.containsKey(hat.getModel())) {
try { try {
@ -106,8 +108,8 @@ public class Cosmetics {
} }
Client.logger.info("STARTING > cosmeitcs > shields"); Client.logger.info("STARTING > cosmeitcs > shields");
shields.clear(); shields.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getShields() != null) { if(allCosmetics != null && allCosmetics.getShields() != null) {
allCosmetics.getCosmetics().getShields().forEach((shield) -> { allCosmetics.getShields().forEach((shield) -> {
shields.put(shield.getId(), new ShieldData(new AnimatedResourceLocation("silentclient/cosmetics/shields/"+shield.getId(), shield.getFrames(), shield.getFrameDelay(), false, shield.getId() == Client.getInstance().getAccount().getSelectedShield()), shield.getModel())); shields.put(shield.getId(), new ShieldData(new AnimatedResourceLocation("silentclient/cosmetics/shields/"+shield.getId(), shield.getFrames(), shield.getFrameDelay(), false, shield.getId() == Client.getInstance().getAccount().getSelectedShield()), shield.getModel()));
if(!hatModels.containsKey(shield.getModel())) { if(!hatModels.containsKey(shield.getModel())) {
try { try {
@ -125,8 +127,8 @@ public class Cosmetics {
Client.logger.info("STARTING > cosmeitcs > icons"); Client.logger.info("STARTING > cosmeitcs > icons");
icons.clear(); icons.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getIcons() != null) { if(allCosmetics != null && allCosmetics.getIcons() != null) {
allCosmetics.getCosmetics().getIcons().forEach((icon) -> { allCosmetics.getIcons().forEach((icon) -> {
icons.put(icon.getId(), new StaticResourceLocation("silentclient/cosmetics/icons/"+ icon.getId() + "/0.png")); icons.put(icon.getId(), new StaticResourceLocation("silentclient/cosmetics/icons/"+ icon.getId() + "/0.png"));
}); });
} }
@ -222,16 +224,23 @@ public class Cosmetics {
return myShields; return myShields;
} }
public static CosmeticsResponse getAllCosmetics() { public static PlayerResponse.Account.Cosmetics getAllCosmetics() {
try { try {
String content = Requests.get("https://api.silentclient.net/_next/get_cosmetics"); InputStream in = Client.getInstance().getClass().getResourceAsStream("/assets/minecraft/silentclient/cosmetics.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer content = new StringBuffer();
String inputLine;
while ((inputLine = reader.readLine()) != null) {
content.append(inputLine);
}
GsonBuilder builder = new GsonBuilder(); GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create(); Gson gson = builder.create();
CosmeticsResponse response = gson.fromJson(content.toString(), CosmeticsResponse.class); in.close();
return response;
} catch (Exception e) { return gson.fromJson(content.toString(), PlayerResponse.Account.Cosmetics.class);
e.printStackTrace(); } catch (Exception e1) {
Client.logger.catching(e1);
return null; return null;
} }
} }