feat: do not cache skin reset

This commit is contained in:
aro 2023-01-19 20:08:10 +01:00
parent aba24384d5
commit 690aeadf67
7 changed files with 31 additions and 15 deletions

View file

@ -69,13 +69,17 @@ public class AppearanceManager {
final String defaultName = instance.getDataStore().getStoredName(player); final String defaultName = instance.getDataStore().getStoredName(player);
this.profile.setName(defaultName); this.profile.setName(defaultName);
this.profile.setSkin(defaultName); this.profile.setSkin(defaultName);
final ActionResult actionResult = updatePlayer(true); final ActionResult actionResult = resetPlayer();
this.profile.setSkin(null); this.profile.setSkin(null);
this.profile.setName(null); this.profile.setName(null);
return actionResult; return actionResult;
} }
public ActionResult resetPlayer() {
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, true, true);
}
public ActionResult updatePlayer(boolean skinChange) { public ActionResult updatePlayer(boolean skinChange) {
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange); return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange, false);
} }
} }

View file

@ -9,5 +9,5 @@ public interface Internals {
void updateOthers(Player player); void updateOthers(Player player);
ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange); ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset);
} }

View file

@ -46,6 +46,10 @@ public class MojangAPI {
return cache.get(uuid); return cache.get(uuid);
} }
public Optional<MojangSkin> getSkinWithoutCaching(String uuid) throws IOException {
return getSkinFromMojang(uuid);
}
public Optional<String> getUUID(String name) throws IOException { public Optional<String> getUUID(String name) throws IOException {
final String parametrizedUrl = URL_NAME.replace("{name}", name); final String parametrizedUrl = URL_NAME.replace("{name}", name);
final JsonObject object = getRequestToUrl(parametrizedUrl); final JsonObject object = getRequestToUrl(parametrizedUrl);

View file

@ -7,6 +7,7 @@ import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile; import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.ActionResult;
import net.artelnatif.nicko.i18n.I18NDict; import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangAPI;
import net.artelnatif.nicko.mojang.MojangSkin; import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
@ -82,7 +83,7 @@ public class v1_17_R1 implements Internals {
} }
@Override @Override
public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange) { public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) {
final CraftPlayer craftPlayer = (CraftPlayer) player; final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle(); final EntityPlayer entityPlayer = craftPlayer.getHandle();
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
@ -95,9 +96,10 @@ public class v1_17_R1 implements Internals {
if (skinChange || changeOnlyName) { if (skinChange || changeOnlyName) {
try { try {
final Optional<String> uuid = NickoBukkit.getInstance().getMojangAPI().getUUID(profile.getSkin()); final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI();
final Optional<String> uuid = mojang.getUUID(profile.getSkin());
if (uuid.isPresent()) { if (uuid.isPresent()) {
skin = NickoBukkit.getInstance().getMojangAPI().getSkin(uuid.get()); skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get()));
if (skin.isPresent()) { if (skin.isPresent()) {
final PropertyMap properties = gameProfile.getProperties(); final PropertyMap properties = gameProfile.getProperties();
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));

View file

@ -7,6 +7,7 @@ import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile; import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.ActionResult;
import net.artelnatif.nicko.i18n.I18NDict; import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangAPI;
import net.artelnatif.nicko.mojang.MojangSkin; import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
@ -84,7 +85,7 @@ public class v1_18_R1 implements Internals {
} }
@Override @Override
public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange) { public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) {
final CraftPlayer craftPlayer = (CraftPlayer) player; final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle(); final EntityPlayer entityPlayer = craftPlayer.getHandle();
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
@ -97,9 +98,10 @@ public class v1_18_R1 implements Internals {
if (skinChange || changeOnlyName) { if (skinChange || changeOnlyName) {
try { try {
final Optional<String> uuid = NickoBukkit.getInstance().getMojangAPI().getUUID(profile.getSkin()); final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI();
final Optional<String> uuid = mojang.getUUID(profile.getSkin());
if (uuid.isPresent()) { if (uuid.isPresent()) {
skin = NickoBukkit.getInstance().getMojangAPI().getSkin(uuid.get()); skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get()));
if (skin.isPresent()) { if (skin.isPresent()) {
final PropertyMap properties = gameProfile.getProperties(); final PropertyMap properties = gameProfile.getProperties();
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));

View file

@ -7,6 +7,7 @@ import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile; import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.ActionResult;
import net.artelnatif.nicko.i18n.I18NDict; import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangAPI;
import net.artelnatif.nicko.mojang.MojangSkin; import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatBaseComponent;
@ -84,7 +85,7 @@ public class v1_18_R2 implements Internals {
} }
@Override @Override
public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange) { public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) {
final CraftPlayer craftPlayer = (CraftPlayer) player; final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle(); final EntityPlayer entityPlayer = craftPlayer.getHandle();
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
@ -97,9 +98,10 @@ public class v1_18_R2 implements Internals {
if (skinChange || changeOnlyName) { if (skinChange || changeOnlyName) {
try { try {
final Optional<String> uuid = NickoBukkit.getInstance().getMojangAPI().getUUID(profile.getSkin()); final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI();
final Optional<String> uuid = mojang.getUUID(profile.getSkin());
if (uuid.isPresent()) { if (uuid.isPresent()) {
skin = NickoBukkit.getInstance().getMojangAPI().getSkin(uuid.get()); skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get()));
if (skin.isPresent()) { if (skin.isPresent()) {
final PropertyMap properties = gameProfile.getProperties(); final PropertyMap properties = gameProfile.getProperties();
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));

View file

@ -7,6 +7,7 @@ import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile; import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.ActionResult; import net.artelnatif.nicko.disguise.ActionResult;
import net.artelnatif.nicko.i18n.I18NDict; import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangAPI;
import net.artelnatif.nicko.mojang.MojangSkin; import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
@ -86,7 +87,7 @@ public class v1_19_R1 implements Internals {
} }
@Override @Override
public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange) { public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) {
final CraftPlayer craftPlayer = (CraftPlayer) player; final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle(); final EntityPlayer entityPlayer = craftPlayer.getHandle();
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName()); final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
@ -102,9 +103,10 @@ public class v1_19_R1 implements Internals {
if (skinChange || changeOnlyName) { if (skinChange || changeOnlyName) {
try { try {
final Optional<String> uuid = NickoBukkit.getInstance().getMojangAPI().getUUID(profile.getSkin()); final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI();
final Optional<String> uuid = mojang.getUUID(profile.getSkin());
if (uuid.isPresent()) { if (uuid.isPresent()) {
skin = NickoBukkit.getInstance().getMojangAPI().getSkin(uuid.get()); skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get()));
if (skin.isPresent()) { if (skin.isPresent()) {
final PropertyMap properties = gameProfile.getProperties(); final PropertyMap properties = gameProfile.getProperties();
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature())); properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));