55import com .mojang .authlib .GameProfile ;
66import com .mojang .authlib .properties .Property ;
77import org .apache .commons .codec .binary .Base64 ;
8- import org .apache .commons .io .IOUtils ;
98import org .bukkit .entity .Player ;
109import xyz .theprogramsrc .supercoreapi .global .utils .Utils ;
1110
12- import java .io .IOException ;
13- import java .net .URL ;
14- import java .nio .charset .Charset ;
1511import java .util .UUID ;
1612
1713@ SuppressWarnings ("ALL" )
@@ -62,10 +58,10 @@ public static SkinTexture fromPlayer(Player player) {
6258 * @return the skin
6359 */
6460 public static SkinTexture fromMojang (String playerName ) {
65- String response = getResponse ("https://api.mojang.com/users/profiles/minecraft/" + playerName );
61+ String response = Utils . readWithInputStream ("https://api.mojang.com/users/profiles/minecraft/" + playerName );
6662 if (response == null )
6763 return null ;
68- String uuid = (new JsonParser ()).parse (getResponse (response )).getAsJsonObject ().get ("id" ).getAsString ();
64+ String uuid = (new JsonParser ()).parse (Utils . readWithInputStream (response )).getAsJsonObject ().get ("id" ).getAsString ();
6965 String fullUUID = Utils .uuidToFullUUID (uuid );
7066 return fromMojang (UUID .fromString (fullUUID ));
7167 }
@@ -76,7 +72,7 @@ public static SkinTexture fromMojang(String playerName) {
7672 * @return the skin
7773 */
7874 public static SkinTexture fromMojang (UUID uuid ) {
79- String response = getResponse ("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid .toString ().replace ("-" , "" ) + "?unsigned=false" );
75+ String response = Utils . readWithInputStream ("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid .toString ().replace ("-" , "" ) + "?unsigned=false" );
8076 if (response == null )
8177 return null ;
8278 JsonObject properties = (new JsonParser ()).parse (response ).getAsJsonObject ().get ("properties" ).getAsJsonArray ().get (0 ).getAsJsonObject ();
@@ -93,16 +89,6 @@ public static SkinTexture fromURL(String url){
9389 return new SkinTexture (url );
9490 }
9591
96- private static String getResponse (String stringUrl ) {
97- try {
98- URL url = new URL (stringUrl );
99- return IOUtils .toString (url .openStream (), Charset .forName ("UTF-8" ));
100- } catch (IOException e ) {
101- e .printStackTrace ();
102- return null ;
103- }
104- }
105-
10692 private static String base64ToUrl (String base64 ) {
10793 String content = new String (Base64 .decodeBase64 (base64 .getBytes ()));
10894 JsonObject json = new JsonParser ().parse (content ).getAsJsonObject ().get ("textures" ).getAsJsonObject ().get ("SKIN" ).getAsJsonObject ();
0 commit comments