feat: don't cache reset skin

This commit is contained in:
ineanto 2023-07-01 17:55:53 +02:00
parent c6f037a24d
commit 18d7322406

View file

@ -79,14 +79,14 @@ public class AppearanceManager {
public void setNameAndSkin(String name, String skin) { public void setNameAndSkin(String name, String skin) {
this.profile.setName(name); this.profile.setName(name);
this.profile.setSkin(skin); this.profile.setSkin(skin);
updatePlayer(true); updatePlayer(true, false);
} }
public ActionResult<Void> reset() { public ActionResult<Void> reset() {
final String defaultName = nameStore.getStoredName(player); final String defaultName = nameStore.getStoredName(player);
this.profile.setName(defaultName); this.profile.setName(defaultName);
this.profile.setSkin(defaultName); this.profile.setSkin(defaultName);
final ActionResult<Void> actionResult = updatePlayer(true); final ActionResult<Void> actionResult = updatePlayer(true, true);
if (!actionResult.isError()) { if (!actionResult.isError()) {
this.profile.setSkin(null); this.profile.setSkin(null);
this.profile.setName(null); this.profile.setName(null);
@ -94,11 +94,11 @@ public class AppearanceManager {
return actionResult; return actionResult;
} }
public ActionResult<Void> updatePlayer(boolean skinChange) { public ActionResult<Void> updatePlayer(boolean skinChange, boolean reset) {
final String displayName = profile.getName() == null ? player.getName() : profile.getName(); final String displayName = profile.getName() == null ? player.getName() : profile.getName();
final WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player).withName(displayName); final WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player).withName(displayName);
final ActionResult<Void> result = updateGameProfileSkin(gameProfile, skinChange); final ActionResult<Void> result = updateGameProfileSkin(gameProfile, skinChange, reset);
final boolean wasFlying = player.isFlying(); final boolean wasFlying = player.isFlying();
if (!result.isError()) { if (!result.isError()) {
updateMetadata(); updateMetadata();
@ -126,7 +126,7 @@ public class AppearanceManager {
} }
private ActionResult<Void> updateGameProfileSkin(WrappedGameProfile gameProfile, boolean skinChange) { private ActionResult<Void> updateGameProfileSkin(WrappedGameProfile gameProfile, boolean skinChange, boolean reset) {
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
if (skinChange || changeOnlyName) { if (skinChange || changeOnlyName) {
@ -135,7 +135,7 @@ public class AppearanceManager {
final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI(); final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI();
final Optional<String> uuid = mojang.getUUID(profile.getSkin()); final Optional<String> uuid = mojang.getUUID(profile.getSkin());
if (uuid.isPresent()) { if (uuid.isPresent()) {
skin = mojang.getSkin(uuid.get()); skin = reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get());
if (skin.isPresent()) { if (skin.isPresent()) {
final MojangSkin skinResult = skin.get(); final MojangSkin skinResult = skin.get();
final Multimap<String, WrappedSignedProperty> properties = gameProfile.getProperties(); final Multimap<String, WrappedSignedProperty> properties = gameProfile.getProperties();