fix: error when name/skin is null

This commit is contained in:
ineanto 2025-09-07 08:57:18 +02:00
parent 899a7e2f32
commit ff460eb0bc
Signed by: ineanto
GPG key ID: E511F9CAA2F9CE84
3 changed files with 19 additions and 13 deletions

View file

@ -65,7 +65,7 @@ public class FavoriteAddItem {
}, click -> {
final ClickType clickType = click.getClickType();
if (clickType.isShiftClick() && clickType.isLeftClick()) {
if (!profile.hasData()) {
if(profile.getName() == null && profile.getSkin() == null) {
click.getEvent().getView().close();
return false;
}

View file

@ -32,11 +32,18 @@ public class FavoriteAppearanceEntryItem extends AsyncItem {
}, (click -> true)).getItemProvider(),
() -> {
try {
// TODO (Ineanto, 08/06/2025): set a default skin if the entry contains only a name
final String name = (appearance.name() == null ? "N/A" : appearance.name());
final String skin = (appearance.skin() == null ? "N/A" : appearance.skin());
final SkullBuilder skull = new SkullBuilder(skin);
return playerLanguage.translateItem(skull, LanguageKey.GUI.Favorites.ENTRY, name, skin);
if (appearance.skin() == null && appearance.name() != null) {
// Skin is null, but the name is present
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Favorites.ENTRY, appearance.name(), "N/A");
} else if (appearance.skin() != null && appearance.name() == null) {
// Skin is present, but the name is null
final SkullBuilder skull = new SkullBuilder(SkullBuilder.HeadTexture.of(appearance.skin()));
return playerLanguage.translateItem(skull, LanguageKey.GUI.Favorites.ENTRY, "N/A", appearance.skin());
}
// Both skin and name are present
final SkullBuilder skull = new SkullBuilder(SkullBuilder.HeadTexture.of(appearance.skin()));
return playerLanguage.translateItem(skull, LanguageKey.GUI.Favorites.ENTRY, appearance.name(), appearance.skin());
} catch (Exception e) {
Nicko.getInstance().getLogger().warning("Unable to get Head texture for specified UUID (" + appearance.skin() + ")! (GUI/Favorites/Entry)");
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Favorites.ENTRY, "N/A", "N/A");
@ -60,7 +67,6 @@ public class FavoriteAppearanceEntryItem extends AsyncItem {
final ActionResult result = appearanceManager.update(true);
if (!result.isError()) {
player.sendMessage(playerLanguage.translateWithWhoosh(LanguageKey.Event.Appearance.Set.OK));
} else {
player.sendMessage(playerLanguage.translateWithOops(
LanguageKey.Event.Appearance.Set.ERROR,

View file

@ -60,7 +60,7 @@ public class MojangAPI {
return skinCache.get(uuid);
}
public Optional<MojangSkin> getSkinWithoutCaching(String uuid) throws IOException, ExecutionException, InterruptedException {
public Optional<MojangSkin> getSkinWithoutCaching(String uuid) throws ExecutionException, InterruptedException {
return getSkinFromMojang(uuid);
}
@ -71,7 +71,7 @@ public class MojangAPI {
private Optional<String> getUUIDFromMojang(String name) throws ExecutionException, InterruptedException {
final String parametrizedUrl = URL_NAME.replace("{name}", name);
final JsonObject object = getRequestToUrl(parametrizedUrl);
if (hasNoError(object)) {
if (!hasError(object)) {
final JsonElement idObject = object.get("id");
final String uuid = idObject.getAsString();
final Optional<String> uuidOptional = Optional.of(uuid);
@ -91,7 +91,7 @@ public class MojangAPI {
private Optional<MojangSkin> getSkinFromMojang(String uuid) throws ExecutionException, InterruptedException {
final String parametrizedUrl = URL_SKIN.replace("{uuid}", uuid);
final JsonObject object = getRequestToUrl(parametrizedUrl);
if (hasNoError(object)) {
if (!hasError(object)) {
final MojangSkin skin = MojangSkin.buildFromJson(object);
return Optional.of(skin);
}
@ -148,12 +148,12 @@ public class MojangAPI {
private JsonObject getErrorObject() {
final JsonObject errorObject = new JsonObject();
errorObject.addProperty("error", "An error occurred.");
errorObject.add("error", new JsonObject());
return errorObject;
}
private boolean hasNoError(JsonObject object) {
return object.get("error") == null;
private boolean hasError(JsonObject object) {
return object.get("error") != null;
}
public LoadingCache<String, Optional<MojangSkin>> getSkinCache() {