From ab4d1a93ca1476b8524f3335c02baddf74ffc6da Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:25:58 +0200 Subject: [PATCH] Don't require a GameProfileFetcher implementation by default --- README.md | 1 + .../raphimc/vialegacy/ViaLegacyConfig.java | 2 +- .../Protocol1_7_2_5to1_6_4.java | 7 ++- .../Protocol1_7_6_10to1_7_2_5.java | 54 +++++++++---------- .../Protocol1_8to1_7_6_10.java | 7 --- .../providers/GameProfileFetcher.java | 6 +-- .../rewriter/ItemRewriter.java | 3 +- .../resources/assets/vialegacy/vialegacy.yml | 2 +- 8 files changed, 35 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index a25c731..63c2982 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ If your platform supports online mode authentication you also should not always #### GameProfileFetcher The game profile fetcher is used to fetch the game profile of a player if the server version is <= 1.7.10. This is required because the game profile or UUID of players is not sent by the server in <= 1.7.10. +The GameProfileFetcher is only used when ``legacy-skin-loading`` or ``legacy-skull-loading`` is set to ``true`` in the config. If you don't plan to use those options you don't need to implement this provider. Here is an example implementation using the [Steveice10 AuthLib](https://github.com/GeyserMC/MCAuthLib): ```java public class AuthLibGameProfileFetcher extends GameProfileFetcher { diff --git a/src/main/java/net/raphimc/vialegacy/ViaLegacyConfig.java b/src/main/java/net/raphimc/vialegacy/ViaLegacyConfig.java index fd5c418..611f690 100644 --- a/src/main/java/net/raphimc/vialegacy/ViaLegacyConfig.java +++ b/src/main/java/net/raphimc/vialegacy/ViaLegacyConfig.java @@ -50,7 +50,7 @@ public class ViaLegacyConfig extends Config implements net.raphimc.vialegacy.pla private void loadFields() { this.dynamicOnground = this.getBoolean("dynamic-onground", true); this.ignoreLongChannelNames = this.getBoolean("ignore-long-1_8-channel-names", true); - this.legacySkullLoading = this.getBoolean("legacy-skull-loading", true); + this.legacySkullLoading = this.getBoolean("legacy-skull-loading", false); this.legacySkinLoading = this.getBoolean("legacy-skin-loading", false); this.soundEmulation = this.getBoolean("sound-emulation", true); this.oldBiomes = this.getBoolean("old-biomes", true); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java index 6b8fbad..fe1b677 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_2_5to1_6_4/Protocol1_7_2_5to1_6_4.java @@ -58,6 +58,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.types.Type import net.raphimc.vialegacy.protocols.release.protocol1_7_6_10to1_7_2_5.ClientboundPackets1_7_2; import net.raphimc.vialegacy.protocols.release.protocol1_7_6_10to1_7_2_5.ServerboundPackets1_7_2; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.Protocol1_8to1_7_6_10; +import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameProfile; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.Chunk1_7_6Type; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.types.ChunkBulk1_7_6Type; @@ -384,8 +385,7 @@ public class Protocol1_7_2_5to1_6_4 extends AbstractProtocol { final String name = wrapper.read(Types1_6_4.STRING); // name - final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class); - wrapper.write(Type.STRING, (ViaLegacy.getConfig().isLegacySkinLoading() ? gameProfileFetcher.getMojangUUID(name) : gameProfileFetcher.getOfflineUUID(name)).toString().replace("-", "")); // uuid + wrapper.write(Type.STRING, (ViaLegacy.getConfig().isLegacySkinLoading() ? Via.getManager().getProviders().get(GameProfileFetcher.class).getMojangUUID(name) : new GameProfile(name).uuid).toString().replace("-", "")); // uuid wrapper.write(Type.STRING, name); }); map(Type.INT); // x @@ -924,9 +924,8 @@ public class Protocol1_7_2_5to1_6_4 extends AbstractProtocol> 2)); // protocol id wrapper.write(Types1_6_4.STRING, name); // user name diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java index c004d8a..4130372 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_7_6_10to1_7_2_5/Protocol1_7_6_10to1_7_2_5.java @@ -84,8 +84,6 @@ public class Protocol1_7_6_10to1_7_2_5 extends AbstractProtocol { - final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class); - final Position pos = wrapper.get(Types1_7_6.POSITION_SHORT, 0); final short type = wrapper.get(Type.UNSIGNED_BYTE, 0); final CompoundTag tag = wrapper.get(Types1_7_6.COMPRESSED_NBT, 0); @@ -95,38 +93,40 @@ public class Protocol1_7_6_10to1_7_2_5 extends AbstractProtocol { final GameProfile skullProfile = gameProfileFetcher.getGameProfile(uuid); if (skullProfile == null || skullProfile.isOffline()) return; newTag.put("Owner", writeGameProfileToTag(skullProfile)); - wrapper.set(Types1_7_6.COMPRESSED_NBT, 0, newTag); - return; - } + try { + final PacketWrapper updateSkull = PacketWrapper.create(ClientboundPackets1_7_2.BLOCK_ENTITY_DATA, wrapper.user()); + updateSkull.write(Types1_7_6.POSITION_SHORT, pos); + updateSkull.write(Type.UNSIGNED_BYTE, type); + updateSkull.write(Types1_7_6.COMPRESSED_NBT, newTag); + updateSkull.send(Protocol1_7_6_10to1_7_2_5.class); + } catch (Throwable e) { + e.printStackTrace(); + } + }); } - - gameProfileFetcher.getMojangUUIDAsync(skullName).thenAccept(uuid -> { - final GameProfile skullProfile = gameProfileFetcher.getGameProfile(uuid); - if (skullProfile == null || skullProfile.isOffline()) return; - - newTag.put("Owner", writeGameProfileToTag(skullProfile)); - try { - final PacketWrapper updateSkull = PacketWrapper.create(ClientboundPackets1_7_2.BLOCK_ENTITY_DATA, wrapper.user()); - updateSkull.write(Types1_7_6.POSITION_SHORT, pos); - updateSkull.write(Type.UNSIGNED_BYTE, type); - updateSkull.write(Types1_7_6.COMPRESSED_NBT, newTag); - updateSkull.send(Protocol1_7_6_10to1_7_2_5.class); - } catch (Throwable e) { - e.printStackTrace(); - } - }); }); } }); diff --git a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java index f278a10..bf9e42d 100644 --- a/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java +++ b/src/main/java/net/raphimc/vialegacy/protocols/release/protocol1_8to1_7_6_10/Protocol1_8to1_7_6_10.java @@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_10Types; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; @@ -60,7 +59,6 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameP import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.MapData; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.MapIcon; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.TabListEntry; -import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.ChatItemRewriter; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.ItemRewriter; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.rewriter.TranslationRewriter; @@ -1574,11 +1572,6 @@ public class Protocol1_8to1_7_6_10 extends AbstractProtocol { } } - if (skullOwnerName != null) { + if (skullOwnerName != null && ViaLegacy.getConfig().isLegacySkullLoading()) { final GameProfileFetcher gameProfileFetcher = Via.getManager().getProviders().get(GameProfileFetcher.class); - if (!ViaLegacy.getConfig().isLegacySkullLoading()) return item; if (gameProfileFetcher.isUUIDLoaded(skullOwnerName)) { final UUID uuid = gameProfileFetcher.getMojangUUID(skullOwnerName); diff --git a/src/main/resources/assets/vialegacy/vialegacy.yml b/src/main/resources/assets/vialegacy/vialegacy.yml index 2fcd892..1cd6afd 100644 --- a/src/main/resources/assets/vialegacy/vialegacy.yml +++ b/src/main/resources/assets/vialegacy/vialegacy.yml @@ -7,7 +7,7 @@ dynamic-onground: true ignore-long-1_8-channel-names: true # # Load <= 1.7.2 player skull skins -legacy-skull-loading: true +legacy-skull-loading: false # # Load <= 1.6.4 skins. (Adds max 500ms delay to player spawn packets) legacy-skin-loading: false