1717 */
1818package cn .xiaopangxie732 .mojang_api ;
1919
20- import java .awt .image .BufferedImage ;
2120import java .io .ByteArrayOutputStream ;
2221import java .io .File ;
2322import java .io .IOException ;
3534
3635import cn .xiaopangxie732 .mojang_api .util .Auth ;
3736
37+ /**
38+ * The class for operating the skin.
39+ * @author XiaoPangxie732
40+ * @since 0.0.5
41+ */
3842public class Skin {
3943 /**
4044 * To change skin.
41- * @param access_token The access token of UUID's account.
45+ * @param access_token The access token of UUID's account. can be get by using {@link Auth#getAccessToken(String, String)}
4246 * @param isSlim Skin is slim or not.
43- * @param uuid UUID of player. can be get be using {@link UserName#UUIDAtNow(String)}
47+ * @param uuid UUID of the player. can be get by using {@link UserName#UUIDAtNow(String)}
4448 * @param uri The skin image path. if it is a local file, it needs add a prefix "file:///" and replace "\\" to "/"(Windows).
49+ * @throws IllegalStateException Throw when change skin failed.
50+ * @since 0.0.5
4551 */
4652 public static void changeSkin (String access_token , boolean isSlim , String uuid , URI uri ) {
4753 try {
4854 String response = Auth .postConnection ("https://api.mojang.com/user/profile/" + uuid
4955 +"/skin" , "model=" + (isSlim ? "slim" : "" ) + "&url=" +
5056 URLEncoder .encode (uri .toURL ().toString (), "UTF-8" ), access_token );
5157 if (response != null )
52- throw new IllegalArgumentException ("Failed to change skin" );
58+ throw new IllegalStateException ("Failed to change skin" );
5359 } catch (UnsupportedEncodingException | MalformedURLException e ) {
5460 e .printStackTrace ();
5561 }
5662 }
57- public static void changeSkinAndUpload (String access_token , boolean isSlim , String uuid , URI uri ) {
63+ /**
64+ * To change skin and upload.
65+ * @param access_token The access token of UUID's account. can be get by using {@link Auth#getAccessToken(String, String)}
66+ * @param isSlim Skin is slim or not.
67+ * @param uuid UUID of the player. can be get be using {@link UserName#UUIDAtNow(String)}
68+ * @param uri The skin image path. if it is a local file, it needs add a prefix "file:///" and replace "\\" to "/"(Windows).
69+ * @throws IllegalStateException Throw when change skin failed.
70+ * @since 0.0.5
71+ */
72+ public static void changeSkinAndUpload (String access_token , boolean isSlim , String uuid , URI uri ) throws IllegalStateException {
5873 StringBuffer response = new StringBuffer ();
5974 HttpURLConnection connection = null ;
6075 try {
@@ -88,6 +103,8 @@ public static void changeSkinAndUpload(String access_token, boolean isSlim, Stri
88103 while ((i = in .read ())!= -1 ) {
89104 response .append ((char )i );
90105 }
106+ if (response != null )
107+ throw new IllegalStateException ("Failed to change skin" );
91108 } catch (IOException ioe ) {
92109 InputStream err = connection .getErrorStream ();
93110 int i ;
@@ -105,6 +122,13 @@ public static void changeSkinAndUpload(String access_token, boolean isSlim, Stri
105122 connection .disconnect ();
106123 }
107124 }
125+ /**
126+ * Reset the skin.
127+ * @param access_token The access token of UUID's account. can be get by using {@link Auth#getAccessToken(String, String)}
128+ * @param uuid UUID of the player. can be get be using {@link UserName#UUIDAtNow(String)}
129+ * @throws IllegalStateException Throw when change skin failed.
130+ * @since 0.0.5
131+ */
108132 public static void resetSkin (String access_token , String uuid ) {
109133 StringBuffer response = new StringBuffer ();
110134 HttpURLConnection connection = null ;
0 commit comments