File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
nms/src/main/kotlin/io/github/rothes/protocolstringreplacer/nms
src/main/java/io/github/rothes/protocolstringreplacer Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,14 @@ import io.github.rothes.protocolstringreplacer.nms.packetreader.IBlockEntityType
44import io.github.rothes.protocolstringreplacer.nms.packetreader.IDisguisedPacketHandler
55import io.github.rothes.protocolstringreplacer.nms.packetreader.IMenuTypeGetter
66import io.github.rothes.protocolstringreplacer.nms.packetreader.IPacketReader
7+ import java.util.function.Consumer
78
89object NmsManager {
910
1011 private const val PACKAGE_PREFIX = " io.github.rothes.protocolstringreplacer.nms"
1112
1213 private lateinit var minecraftVersion: String
14+ lateinit var warningFunction: Consumer <String >
1315
1416 fun setVersion (major : Int , minor : Int ) {
1517 var m = minor
@@ -22,6 +24,20 @@ object NmsManager {
2224 m++
2325 }
2426 }
27+ // On older versions we are not using NMS.
28+ if (major >= 19 ) {
29+ warningFunction.accept(" Minecraft version 1.$major .$minor is not supported by the plugin version you are running on." )
30+ m = minor
31+ while (-- m >= 0 ) {
32+ setVersionProp(major, m)
33+ try {
34+ create<IPacketReader >()
35+ warningFunction.accept(" Fallback to 1.$major .$m support and luckily it could be compatible." )
36+ return
37+ } catch (ignored: ClassNotFoundException ) {
38+ }
39+ }
40+ }
2541 setVersionProp(major, minor)
2642 }
2743
Original file line number Diff line number Diff line change 1818import io .github .rothes .protocolstringreplacer .upgrade .AbstractUpgradeHandler ;
1919import io .github .rothes .protocolstringreplacer .upgrade .UpgradeEnum ;
2020import io .github .rothes .protocolstringreplacer .util .FileUtils ;
21+ import kotlin .Unit ;
22+ import kotlin .jvm .functions .Function1 ;
2123import org .apache .commons .lang .Validate ;
2224import org .bukkit .Bukkit ;
2325import org .bukkit .configuration .ConfigurationSection ;
@@ -102,6 +104,7 @@ public ProtocolStringReplacer() {
102104 String [] split = Bukkit .getServer ().getBukkitVersion ().split ("-" )[0 ].split ("\\ ." );
103105 serverMajorVersion = Byte .parseByte (split [1 ]);
104106 serverMinorVersion = split .length > 2 ? Byte .parseByte (split [2 ]) : 0 ;
107+ NmsManager .INSTANCE .setWarningFunction (ProtocolStringReplacer ::warn );
105108 NmsManager .INSTANCE .setVersion (serverMajorVersion , serverMinorVersion );
106109
107110 // Start Console Replacer first to remove the Ansi in log files.
You can’t perform that action at this time.
0 commit comments