mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-14 19:04:59 -05:00
Throw error on minecraft-data protocol version mismatch (#1044)
require('minecraft-data')('1.19.1') can redirect to require('minecraft-data')('1.19') (the major version) per node-minecraft-data constructor's version handling. This can cause issues if the protocol version changed between patch updates even on the same major, so throw error to prevent.
This commit is contained in:
parent
061176d377
commit
7fb293fba2
1 changed files with 6 additions and 1 deletions
|
@ -10,15 +10,20 @@ const states = require('../states')
|
||||||
const merge = require('lodash.merge')
|
const merge = require('lodash.merge')
|
||||||
const get = require('lodash.get')
|
const get = require('lodash.get')
|
||||||
|
|
||||||
|
const minecraftData = require('minecraft-data')
|
||||||
const protocols = {}
|
const protocols = {}
|
||||||
|
|
||||||
function createProtocol (state, direction, version, customPackets, compiled = true) {
|
function createProtocol (state, direction, version, customPackets, compiled = true) {
|
||||||
const key = state + ';' + direction + ';' + version + (compiled ? ';c' : '')
|
const key = state + ';' + direction + ';' + version + (compiled ? ';c' : '')
|
||||||
if (protocols[key]) { return protocols[key] }
|
if (protocols[key]) { return protocols[key] }
|
||||||
|
|
||||||
const mcData = require('minecraft-data')(version)
|
const mcData = minecraftData(version)
|
||||||
|
const versionInfo = minecraftData.versionsByMinecraftVersion.pc[version]
|
||||||
if (mcData === null) {
|
if (mcData === null) {
|
||||||
throw new Error(`No data available for version ${version}`)
|
throw new Error(`No data available for version ${version}`)
|
||||||
|
} else if (versionInfo && versionInfo.version !== mcData.version.version) {
|
||||||
|
// The protocol version returned by node-minecraft-data constructor does not match the data in minecraft-data's protocolVersions.json
|
||||||
|
throw new Error(`Do not have protocol data for protocol version ${versionInfo.version} (attempted to use ${mcData.version.version} data)`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compiled) {
|
if (compiled) {
|
||||||
|
|
Loading…
Reference in a new issue