refactor: much cleaner internals
This commit is contained in:
parent
a72b67be06
commit
c7d6c57320
7 changed files with 110 additions and 169 deletions
|
@ -6,8 +6,6 @@ import com.mojang.authlib.properties.PropertyMap;
|
|||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
import net.artelnatif.nicko.mojang.MojangAPI;
|
||||
import net.artelnatif.nicko.mojang.MojangSkin;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.RemoteChatSession;
|
||||
|
@ -25,10 +23,8 @@ import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class v1_19_R2 implements Internals {
|
||||
@Override
|
||||
|
@ -73,37 +69,21 @@ public class v1_19_R2 implements Internals {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) {
|
||||
public ActionResult<Void> updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset) {
|
||||
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
|
||||
final String profileName = profile.getName() == null ? player.getName() : profile.getName();
|
||||
Optional<MojangSkin> skin;
|
||||
|
||||
final ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
final GameProfile gameProfile = new GameProfile(player.getUniqueId(), profileName);
|
||||
|
||||
final ClientboundPlayerInfoRemovePacket remove = new ClientboundPlayerInfoRemovePacket(List.of(player.getUniqueId()));
|
||||
|
||||
if (skinChange || changeOnlyName) {
|
||||
try {
|
||||
final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI();
|
||||
final Optional<String> uuid = mojang.getUUID(profile.getSkin());
|
||||
if (uuid.isPresent()) {
|
||||
skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get()));
|
||||
if (skin.isPresent()) {
|
||||
final PropertyMap properties = gameProfile.getProperties();
|
||||
properties.removeAll("textures");
|
||||
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
|
||||
updateSelf(player);
|
||||
} else {
|
||||
return new ActionResult(I18NDict.Error.SKIN_FAIL_MOJANG);
|
||||
}
|
||||
} else {
|
||||
return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG);
|
||||
}
|
||||
} catch (ExecutionException e) {
|
||||
return new ActionResult(I18NDict.Error.SKIN_FAIL_CACHE);
|
||||
} catch (IOException e) {
|
||||
return new ActionResult(I18NDict.Error.NAME_FAIL_MOJANG);
|
||||
final ActionResult<MojangSkin> skinFetch = fetchSkinTextures(profile, reset);
|
||||
if (!skinFetch.isError()) {
|
||||
final MojangSkin skin = skinFetch.getResult();
|
||||
final PropertyMap properties = gameProfile.getProperties();
|
||||
properties.removeAll("textures");
|
||||
properties.put("textures", new Property("textures", skin.value(), skin.signature()));
|
||||
updateSelf(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,6 +93,7 @@ public class v1_19_R2 implements Internals {
|
|||
ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY,
|
||||
ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LISTED),
|
||||
Collections.singletonList(serverPlayer));
|
||||
final ClientboundPlayerInfoRemovePacket remove = new ClientboundPlayerInfoRemovePacket(List.of(player.getUniqueId()));
|
||||
|
||||
if (serverPlayer.getChatSession() == null) {
|
||||
NickoBukkit.getInstance().getLogger().warning("Chat Session of " + serverPlayer.displayName + " is undefined." +
|
||||
|
@ -142,7 +123,7 @@ public class v1_19_R2 implements Internals {
|
|||
onlinePlayer.connection.send(init);
|
||||
});
|
||||
updateOthers(player);
|
||||
return new ActionResult();
|
||||
return new ActionResult<>();
|
||||
}
|
||||
|
||||
private void spoofPlayerInfoPacket(Object object, Object newValue) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue