@@ -45,8 +45,8 @@ const plugins = {
45
45
particle : require ( './plugins/particle' )
46
46
}
47
47
48
- const supportedVersions = require ( './version' ) . supportedVersions
49
- const testedVersions = require ( './version' ) . testedVersions
48
+ const minecraftData = require ( 'minecraft-data' )
49
+ const { testedVersions, latestSupportedVersion , oldestSupportedVersion } = require ( './version' )
50
50
51
51
module . exports = {
52
52
createBot,
@@ -55,9 +55,10 @@ module.exports = {
55
55
ScoreBoard : require ( './scoreboard' ) ,
56
56
BossBar : require ( './bossbar' ) ,
57
57
Particle : require ( './particle' ) ,
58
- supportedVersions,
58
+ latestSupportedVersion,
59
+ oldestSupportedVersion,
59
60
testedVersions,
60
- supportFeature : ( feature , version ) => require ( 'prismarine-registry' ) ( version ) . supportFeature ( feature )
61
+ supportFeature : ( feature , version ) => minecraftData ( version ) . supportFeature ( feature )
61
62
}
62
63
63
64
function createBot ( options = { } ) {
@@ -107,22 +108,21 @@ function createBot (options = {}) {
107
108
if ( ! bot . _client . wait_connect ) next ( )
108
109
else bot . _client . once ( 'connect_allowed' , next )
109
110
function next ( ) {
110
- bot . registry = require ( 'prismarine-registry' ) ( bot . _client . version )
111
- const version = bot . registry . version
112
- if ( supportedVersions . indexOf ( version . majorVersion ) === - 1 ) {
113
- throw new Error ( `Version ${ version . minecraftVersion } is not supported.` )
114
- }
111
+ const serverPingVersion = bot . _client . version
112
+ bot . registry = require ( 'prismarine-registry' ) ( serverPingVersion )
113
+ if ( ! bot . registry ?. version ) throw new Error ( `Server version '${ serverPingVersion } ' is not supported, no data for version` )
115
114
116
- const latestTestedVersion = testedVersions [ testedVersions . length - 1 ]
117
- const latestProtocolVersion = require ( 'prismarine-registry' ) ( latestTestedVersion ) . protocolVersion
118
- if ( version . protocolVersion > latestProtocolVersion ) {
119
- throw new Error ( `Version ${ version . minecraftVersion } is not supported. Latest supported version is ${ latestTestedVersion } .` )
115
+ const versionData = bot . registry . version
116
+ if ( versionData [ '>' ] ( latestSupportedVersion ) ) {
117
+ throw new Error ( `Server version '${ serverPingVersion } ' is not supported. Latest supported version is '${ latestSupportedVersion } '.` )
118
+ } else if ( versionData [ '<' ] ( oldestSupportedVersion ) ) {
119
+ throw new Error ( `Server version '${ serverPingVersion } ' is not supported. Oldest supported version is '${ oldestSupportedVersion } '.` )
120
120
}
121
121
122
- bot . protocolVersion = version . version
123
- bot . majorVersion = version . majorVersion
124
- bot . version = version . minecraftVersion
125
- options . version = version . minecraftVersion
122
+ bot . protocolVersion = versionData . version
123
+ bot . majorVersion = versionData . majorVersion
124
+ bot . version = versionData . minecraftVersion
125
+ options . version = versionData . minecraftVersion
126
126
bot . supportFeature = bot . registry . supportFeature
127
127
setTimeout ( ( ) => bot . emit ( 'inject_allowed' ) , 0 )
128
128
}
0 commit comments