mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 05:35:56 -04:00
Merge pull request #496 from plexigras/auto-version-fix
improved automatic version resolution
This commit is contained in:
commit
4e468b09dc
@ -22,19 +22,20 @@ module.exports = function(client, options) {
|
||||
// The version string is interpreted by https://github.com/PrismarineJS/node-minecraft-data
|
||||
const brandedMinecraftVersion = response.version.name; // 1.8.9, 1.7.10
|
||||
const protocolVersion = response.version.protocol;// 47, 5
|
||||
|
||||
debug(`Server version: ${brandedMinecraftVersion}, protocol: ${protocolVersion}`);
|
||||
|
||||
let minecraftVersion;
|
||||
if (brandedMinecraftVersion.indexOf(' ') !== -1) {
|
||||
// Spigot and Glowstone++ prepend their name; strip it off
|
||||
minecraftVersion = brandedMinecraftVersion.split(' ')[1];
|
||||
} else {
|
||||
minecraftVersion = brandedMinecraftVersion;
|
||||
let versions = [brandedMinecraftVersion]
|
||||
.concat(brandedMinecraftVersion.match(/((\d+\.)+\d+)/g)||[])
|
||||
.map(function (version) {
|
||||
return minecraft_data.versionsByMinecraftVersion["pc"][version]
|
||||
})
|
||||
.filter(function (info) { return info })
|
||||
.sort(function (a, b) { return b.version - a.version })
|
||||
.concat(minecraft_data.postNettyVersionsByProtocolVersion["pc"][protocolVersion]||[])
|
||||
if (versions.length === 0) {
|
||||
throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`);
|
||||
}
|
||||
const minecraftVersion = versions[0].minecraftVersion;
|
||||
|
||||
const versionInfo = minecraft_data.versionsByMinecraftVersion["pc"][minecraftVersion];
|
||||
if (!versionInfo) throw new Error(`unsupported/unknown protocol version: ${protocolVersion}, update minecraft-data`);
|
||||
debug(`Server version: ${minecraftVersion}, protocol: ${protocolVersion}`);
|
||||
|
||||
options.version = minecraftVersion;
|
||||
options.protocolVersion = protocolVersion;
|
||||
|
Loading…
x
Reference in New Issue
Block a user