Skip to content

Commit 3429871

Browse files
author
TheProgramSrc
committed
Changelog:
+ Now the API check if the MojangAPI (https://sessionserver.mojang.com) is down.
1 parent deb6c52 commit 3429871

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v4.2.1 Changelog:
2+
```
3+
+ Now the API check if the MojangAPI (https://sessionserver.mojang.com) is down.
4+
```
5+
16
## v4.2.0 Changelog:
27
```
38
* Code Improvement

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>xyz.theprogramsrc</groupId>
88
<artifactId>SuperCoreAPI</artifactId>
9-
<version>4.2.0</version>
9+
<version>4.2.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SuperCoreAPI</name>

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/skintexture/SkinTexture.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package xyz.theprogramsrc.supercoreapi.spigot.utils.skintexture;
22

3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonElement;
35
import com.google.gson.JsonObject;
46
import com.google.gson.JsonParser;
57
import 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

Comments
 (0)