11package xyz .theprogramsrc .supercoreapi .spigot .utils .skintexture ;
22
3+ import com .google .gson .JsonArray ;
4+ import com .google .gson .JsonElement ;
35import com .google .gson .JsonObject ;
46import com .google .gson .JsonParser ;
57import com .mojang .authlib .GameProfile ;
@@ -58,6 +60,7 @@ public static SkinTexture fromPlayer(Player player) {
5860 * @return the skin
5961 */
6062 public static SkinTexture fromMojang (String playerName ) {
63+ if (isMojangDown ()) return null ;
6164 String response = Utils .readWithInputStream ("https://api.mojang.com/users/profiles/minecraft/" + playerName );
6265 if (response == null )
6366 return null ;
@@ -72,6 +75,7 @@ public static SkinTexture fromMojang(String playerName) {
7275 * @return the skin
7376 */
7477 public static SkinTexture fromMojang (UUID uuid ) {
78+ if (isMojangDown ()) return null ;
7579 String response = Utils .readWithInputStream ("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid .toString ().replace ("-" , "" ) + "?unsigned=false" );
7680 if (response == null )
7781 return null ;
@@ -94,4 +98,35 @@ private static String base64ToUrl(String base64) {
9498 JsonObject json = new JsonParser ().parse (content ).getAsJsonObject ().get ("textures" ).getAsJsonObject ().get ("SKIN" ).getAsJsonObject ();
9599 return json != null ? json .get ("url" ).getAsString () : null ;
96100 }
101+
102+ private static long lastCheck ;
103+ private static boolean working ;
104+
105+ private static boolean isMojangDown (){
106+ long current = System .currentTimeMillis ();
107+ if (lastCheck == 0L ){
108+ lastCheck = current ;
109+ }else {
110+ if (current - lastCheck >= 25000L ){
111+ lastCheck = current ;
112+ try {
113+ String url = "http://status.mojang.com/check" ;
114+ String content = Utils .readWithInputStream (url );
115+ if (content != null ){
116+ JsonArray array = new JsonParser ().parse (content ).getAsJsonArray ();
117+ for (JsonElement el : array ){
118+ JsonObject json = el .getAsJsonObject ();
119+ if (json .has ("sessionserver.mojang.com" )){
120+ working = json .get ("sessionserver.mojang.com" ).getAsString ().equals ("green" );
121+ }
122+ }
123+ }
124+ }catch (Exception e ){
125+ working = false ;
126+ }
127+ }
128+ }
129+
130+ return working ;
131+ }
97132}
0 commit comments