diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java index c43c54b2..cebe9d6d 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/TexturePackSystem.java @@ -42,16 +42,16 @@ public class TexturePackSystem extends BasicListener { public TexturePackSystem() { // https://minecraft.wiki/w/Pack_format#List_of_resource_pack_formats // https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol_version_numbers - protocolVersionToPackVersion.put(759, 10); - protocolVersionToPackVersion.put(762, 12); - protocolVersionToPackVersion.put(763, 15); - protocolVersionToPackVersion.put(764, 18); - protocolVersionToPackVersion.put(765, 26); - protocolVersionToPackVersion.put(766, 41); - protocolVersionToPackVersion.put(767, 48); - protocolVersionToPackVersion.put(768, 57); - protocolVersionToPackVersion.put(769, 61); - protocolVersionToPackVersion.put(770, 71); + protocolVersionToPackVersion.put(759, 10); // 1.19 - 1.19.3 + protocolVersionToPackVersion.put(762, 12); // 1.19.4 + protocolVersionToPackVersion.put(763, 15); // 1.20 - 1.20.1 + protocolVersionToPackVersion.put(764, 18); // 1.20.2 + protocolVersionToPackVersion.put(765, 26); // 1.20.3 - 1.20.4 + protocolVersionToPackVersion.put(766, 41); // 1.20.5 - 1.20.6 + protocolVersionToPackVersion.put(767, 48); // 1.21 - 1.21.1 + protocolVersionToPackVersion.put(768, 57); // 1.21.2 - 1.21.3 + protocolVersionToPackVersion.put(769, 61); // 1.21.4 + protocolVersionToPackVersion.put(770, 71); // 1.21.5 } @Subscribe @@ -60,22 +60,23 @@ public class TexturePackSystem extends BasicListener { return; } VelocityCore.schedule(() -> { - int playerVersion = event.getPlayer().getProtocolVersion().getProtocol(); - File selectedPack = null; - while (selectedPack == null) { - Map.Entry pack = protocolVersionToPackVersion.floorEntry(playerVersion); - if (pack == null) return; - - for (File file : PACKS_DIR.listFiles()) { - if (file.getName().startsWith(pack.getValue() + "_")) { - selectedPack = file; - break; - } + TreeMap fileTreeMap = new TreeMap<>(); + for (File fileEntry : PACKS_DIR.listFiles()) { + try { + int packVersion = Integer.parseInt(fileEntry.getName().split("_")[0]); + fileTreeMap.put(packVersion, fileEntry); + } catch (NumberFormatException e) { + // Ignore } - - playerVersion--; } + int playerVersion = event.getPlayer().getProtocolVersion().getProtocol(); + Map.Entry packVersionEntry = protocolVersionToPackVersion.floorEntry(playerVersion); + if (packVersionEntry == null) return; + Map.Entry selectedPackEntry = fileTreeMap.floorEntry(packVersionEntry.getValue()); + if (selectedPackEntry == null) return; + File selectedPack = selectedPackEntry.getValue(); + String fileName = selectedPack.getName(); fileName = fileName.substring(fileName.indexOf('_') + 1, fileName.lastIndexOf('.')); byte[] hash = hexStringToByteArray(fileName);