fix: mojangapi returns

This commit is contained in:
ineanto 2023-07-01 18:30:24 +02:00
parent 4fa7082bf5
commit c8c55611a0
5 changed files with 29 additions and 15 deletions

View file

@ -1,7 +1,9 @@
package xyz.atnrch.nicko.command.sub;
import xyz.atnrch.nicko.NickoBukkit;
import xyz.atnrch.nicko.disguise.ActionResult;
import xyz.atnrch.nicko.disguise.AppearanceManager;
import xyz.atnrch.nicko.i18n.I18N;
import xyz.atnrch.nicko.mojang.MojangUtils;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
@ -35,14 +37,25 @@ public class NickoDebugSubCmd {
}
}
final AppearanceManager appearanceManager = AppearanceManager.get(target.getPlayer());
if (MojangUtils.isUsernameInvalid(name) || MojangUtils.isUsernameInvalid(skin)) {
if (MojangUtils.isUsernameInvalid(name)) {
sender.sendMessage(prefix + "§cSpecified username is invalid.");
return;
}
if (MojangUtils.isUsernameInvalid(skin)) {
sender.sendMessage(prefix + "§cSpecified skin is invalid.");
return;
}
final AppearanceManager appearanceManager = AppearanceManager.get(target.getPlayer());
appearanceManager.setNameAndSkin(name, skin);
final ActionResult result = appearanceManager.updatePlayer(true, false);
if (!result.isError()) {
target.sendMessage(prefix + "§aWhoosh!");
target.playSound(target.getLocation(), Sound.ENTITY_ITEM_FRAME_PLACE, 1, 1);
} else {
final I18N i18n = new I18N(target);
target.sendMessage(prefix + "§cWhoops. Something happened: " + i18n.translateWithoutPrefix(result.getErrorKey()));
}
}
}

View file

@ -79,7 +79,6 @@ public class AppearanceManager {
public void setNameAndSkin(String name, String skin) {
this.profile.setName(name);
this.profile.setSkin(skin);
updatePlayer(true, false);
}
public ActionResult reset() {
@ -105,11 +104,11 @@ public class AppearanceManager {
updateTabList(gameProfile, displayName);
respawnPlayer();
updateOthers();
}
player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
player.setFlying(wasFlying);
player.updateInventory();
return ActionResult.ok();
}
return result;
}
public void updateOthers() {
@ -144,6 +143,8 @@ public class AppearanceManager {
} else {
return ActionResult.error(I18NDict.Error.MOJANG_SKIN);
}
} else {
return ActionResult.error(I18NDict.Error.MOJANG_NAME);
}
return ActionResult.ok();
} catch (ExecutionException e) {

View file

@ -62,7 +62,7 @@ public class MojangAPI {
final MojangSkin skin = MojangSkin.buildFromJson(object);
return Optional.of(skin);
}
System.out.println("got empty optional !!!");
return Optional.empty();
}

View file

@ -1,8 +1,8 @@
error:
generic: "Unknown error"
invalid_username: "§cThis is not a valid Minecraft username."
mojang_name: "Unable to get username from Mojang."
mojang_skin: "Unable to get skin from Mojang."
mojang_name: "There is no Minecraft account with this name."
mojang_skin: "This Minecraft account has no skin."
offline: "§c{0} §fis offline!"
cache: "Unable to get skin from the cache."
sql: "SQL Error"

View file

@ -1,8 +1,8 @@
error:
generic: Erreur inconnue"
invalid_username: "§cLe pseudo n''est pas un pseudo Minecraft valide."
mojang_name: "Impossible de récupérer le nom d''utilisateur depuis Mojang."
mojang_skin: "Impossible de récupérer le skin depuis Mojang."
mojang_name: "Un compte Minecraft avec ce nom n'existe pas."
mojang_skin: "Ce compte Minecraft n'a pas de skin."
offline: "§c{0} §fest hors-ligne!"
cache: "Impossible de récupérer le skin depuis le cache."
sql: "Erreur SQL"