1717import xyz .xenondevs .inventoryaccess .util .ReflectionRegistry ;
1818import xyz .xenondevs .inventoryaccess .util .ReflectionUtils ;
1919import xyz .xenondevs .invui .util .MojangApiUtils ;
20+ import xyz .xenondevs .invui .util .MojangApiUtils .MojangApiException ;
2021
22+ import java .io .IOException ;
2123import java .io .Serializable ;
2224import java .util .UUID ;
2325import java .util .concurrent .ExecutionException ;
@@ -31,17 +33,21 @@ public final class SkullBuilder extends AbstractItemBuilder<SkullBuilder> {
3133 * Create a {@link SkullBuilder} of a {@link Player Player's} {@link UUID}.
3234 *
3335 * @param uuid The {@link UUID} of the skull owner.
36+ * @throws MojangApiException If the Mojang API returns an error.
37+ * @throws IOException If an I/O error occurs.
3438 */
35- public SkullBuilder (@ NotNull UUID uuid ) {
39+ public SkullBuilder (@ NotNull UUID uuid ) throws MojangApiException , IOException {
3640 this (HeadTexture .of (uuid ));
3741 }
3842
3943 /**
4044 * Create a {@link SkullBuilder} with the {@link Player Player's} username.
4145 *
4246 * @param username The username of the skull owner.
47+ * @throws MojangApiException If the Mojang API returns an error.
48+ * @throws IOException If an I/O error occurs.
4349 */
44- public SkullBuilder (@ NotNull String username ) {
50+ public SkullBuilder (@ NotNull String username ) throws MojangApiException , IOException {
4551 this (HeadTexture .of (username ));
4652 }
4753
@@ -128,9 +134,11 @@ public HeadTexture(@NotNull String textureValue) {
128134 *
129135 * @param offlinePlayer The skull owner.
130136 * @return The {@link HeadTexture} of that player.
137+ * @throws MojangApiException If the Mojang API returns an error.
138+ * @throws IOException If an I/O error occurs.
131139 * @see HeadTexture#of(UUID)
132140 */
133- public static HeadTexture of (@ NotNull OfflinePlayer offlinePlayer ) {
141+ public static @ NotNull HeadTexture of (@ NotNull OfflinePlayer offlinePlayer ) throws MojangApiException , IOException {
134142 return of (offlinePlayer .getUniqueId ());
135143 }
136144
@@ -144,20 +152,28 @@ public static HeadTexture of(@NotNull OfflinePlayer offlinePlayer) {
144152 *
145153 * @param playerName The username of the player.
146154 * @return The {@link HeadTexture} of that player.
155+ * @throws MojangApiException If the Mojang API returns an error.
156+ * @throws IOException If an I/O error occurs.
147157 * @see HeadTexture#of(UUID)
148158 */
149159 @ SuppressWarnings ("deprecation" )
150- public static HeadTexture of (@ NotNull String playerName ) {
160+ public static @ NotNull HeadTexture of (@ NotNull String playerName ) throws MojangApiException , IOException {
151161 if (Bukkit .getServer ().getOnlineMode ()) {
152162 // if the server is in online mode, the Minecraft UUID cache (usercache.json) can be used
153163 return of (Bukkit .getOfflinePlayer (playerName ).getUniqueId ());
154164 } else {
155165 // the server isn't in online mode - the UUID has to be retrieved from the Mojang API
156166 try {
157- return of (uuidCache .get (playerName , () -> MojangApiUtils .getCurrentUUID (playerName )));
167+ return of (uuidCache .get (playerName , () -> MojangApiUtils .getCurrentUuid (playerName )));
158168 } catch (ExecutionException e ) {
159- e .printStackTrace ();
160- return null ;
169+ Throwable cause = e .getCause ();
170+ if (cause instanceof MojangApiException ) {
171+ throw (MojangApiException ) cause ;
172+ } else if (cause instanceof IOException ) {
173+ throw (IOException ) cause ;
174+ } else {
175+ throw new RuntimeException (cause );
176+ }
161177 }
162178 }
163179 }
@@ -169,13 +185,21 @@ public static HeadTexture of(@NotNull String playerName) {
169185 *
170186 * @param uuid The {@link UUID} of the skull owner.
171187 * @return The {@link HeadTexture} of that player.
188+ * @throws MojangApiException If the Mojang API returns an error.
189+ * @throws IOException If an I/O error occurs.
172190 */
173- public static HeadTexture of (@ NotNull UUID uuid ) {
191+ public static @ NotNull HeadTexture of (@ NotNull UUID uuid ) throws MojangApiException , IOException {
174192 try {
175193 return new HeadTexture (textureCache .get (uuid , () -> MojangApiUtils .getSkinData (uuid , false )[0 ]));
176194 } catch (ExecutionException e ) {
177- e .printStackTrace ();
178- return null ;
195+ Throwable cause = e .getCause ();
196+ if (cause instanceof MojangApiException ) {
197+ throw (MojangApiException ) cause ;
198+ } else if (cause instanceof IOException ) {
199+ throw (IOException ) cause ;
200+ } else {
201+ throw new RuntimeException (cause );
202+ }
179203 }
180204 }
181205
0 commit comments