Skip to content

Commit

Permalink
Support changes from PR1640
Browse files Browse the repository at this point in the history
* Will now support before and after GeyserMC/Geyser#1640 is implemented
  • Loading branch information
bundabrg committed Dec 9, 2020
1 parent fe53a9a commit 38bdb33
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.geysermc.connector.utils.ResourcePack;
import org.geysermc.connector.utils.ResourcePackManifest;

import java.lang.reflect.InvocationTargetException;
import java.util.UUID;

public class GeyserUpstreamPacketHandler extends UpstreamPacketHandler {
Expand Down Expand Up @@ -124,7 +125,24 @@ public boolean handle(LoginPacket loginPacket) {
ResourcePacksInfoPacket resourcePacksInfo = new ResourcePacksInfoPacket();
for (ResourcePack resourcePack : ResourcePack.PACKS.values()) {
ResourcePackManifest.Header header = resourcePack.getManifest().getHeader();
resourcePacksInfo.getResourcePackInfos().add(new ResourcePacksInfoPacket.Entry(header.getUuid().toString(), header.getVersionString(), resourcePack.getFile().length(), "", "", "", false));

// ResourcePacksInfoPacket.Entry has an additional and non backwards compatible parameter so we try both ways
ResourcePacksInfoPacket.Entry resourceEntry;

try {
resourceEntry = ResourcePacksInfoPacket.Entry.class.getConstructor(String.class, String.class, long.class, String.class, String.class, String.class, boolean.class, boolean.class)
.newInstance(header.getUuid().toString(), header.getVersionString(), resourcePack.getFile().length(), "", "", "", false, false);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {

try {
resourceEntry = ResourcePacksInfoPacket.Entry.class.getConstructor(String.class, String.class, long.class, String.class, String.class, String.class, boolean.class)
.newInstance(header.getUuid().toString(), header.getVersionString(), resourcePack.getFile().length(), "", "", "", false);
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e2) {
throw new RuntimeException(e2);
}
}

resourcePacksInfo.getResourcePackInfos().add(resourceEntry);
}
resourcePacksInfo.setForcedToAccept(GeyserConnector.getInstance().getConfig().isForceResourcePacks());
session.sendUpstreamPacket(resourcePacksInfo);
Expand Down

0 comments on commit 38bdb33

Please sign in to comment.